#100DaysOfCode in Python Transcripts
Chapter: Days 13-15: Text-based games (and classes)
Lecture: Your turn: Day 2
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Second day, is we're going to write
0:01
standard Rock, Paper, Scissors.
0:03
And you're going to model this with classes.
0:05
There's going to be a roll and the roll has a name.
0:09
It knows what rolls defeat it.
0:12
And, alright, so you store the name
0:17
that other rolls, that the names of the rolls that you
0:20
can defeat as a roll and the rolls that defeat you.
0:24
Also, we have player concept.
0:26
And the player is really just going to have a name.
0:27
So it says, player Sarah rolls this.
0:32
Player Computer rolls that, and so on.
0:34
Alright, so nothing major there.
0:35
You could also keep a history of the rolls.
0:38
You could show like, sort of replay the game if you wanted,
0:41
and each player could remember what they played
0:43
at each stage, that'd be fun.
0:45
And then the basic program flow looks like this.
0:47
This is not perfectly exactly what you necessarily need.
0:50
It's not totally implemented but, we're going to
0:52
print out the header, we're going to initialize the game here
0:55
by getting the various rolls, in this case
0:58
there's only the three: Rock, Paper, Scissors.
1:00
And then we're going to get the name of the player,
1:03
Add the computer and then we'll have an automatic player
1:06
here, and then we're going to run this little game loop,
1:08
by passing them off.
1:09
And the game loopers need to go round-and-round,
1:11
until somebody has won.
1:13
We'll go around three times, and basically
1:15
just have the computer randomly roll.
1:18
And then have the real player ask them what they
1:20
want to roll, Rock, Paper, Scissors,
1:21
and then have them do that roll correctly.
1:24
And then finally, you can just sort of do this comparison.
1:26
Does the one roll defeat the other?
1:28
I don't know, right?
1:29
And then just do a little output here,
1:31
and increment the count so that you'll know,
1:33
like you just played best of three.
1:35
So you'll know who won, figure out who won and then
1:37
print out so-and-so won 2 to 1 or
1:41
3 to 0 or something like that.
1:45
If you get a tie somewhere in the middle,
1:46
this doesn't work so, you know,
1:48
maybe once you get it working, not considering ties,
1:51
then come back and address the possibility
1:53
there might be ties.