Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Time to create the start_game method to finalize our memory game.
Accomplished in this Video
- Created the start game method
- posts the game name
- starts a while loop
- prints the grid
- asks the player for their guesses
- checks them to see if the locations are good
- checks if they are a match and prints out the appropriate response
- checks if the game has been run
- created a game over message for when the loop ends
OOP Practice Ideas
- Store Inventory
- A class for items in the store
- A class for the inventory
- How can you add items to the inventory?
- How can you update items in the inventory?
- What about deleting items?
- Dungeon Game
- Using the grid-like we did in our memory game but instead of cards, one space holds a monster, and another the exit. Start your play in a spot on the grid and have them move around the grid one space at a time until they either find the exit and win or find the monster and lose.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
All right,
let's make the start_game method.
0:00
The game will be held in a while loop.
0:22
So let's create a variable called
game_running and set it equal to True.
0:25
Let's also print out our game header.
0:32
Feel free to get creative with this.
0:37
I'm just going to put a memory game.
0:39
Then, create the cards by calling
the set_cards method
0:44
and create the while
loop using game_running.
0:53
The first thing we need to do is print
out the grid for the player to see so
1:00
they can guess.
1:04
We can ask for their guesses next.
1:09
guess1
1:13
check_location and pass in first,
1:17
guess2 = self.check_location,
1:23
pass in second.
1:31
Now that we have their matches,
we can check them.
1:35
if self.check_match,
1:40
guess1, guess2.
1:44
If they match, then we need to
see if the game has been won.
1:49
if self.check_win, if so,
let's let the player know they've won.
1:54
Print.
2:01
Congrats.
2:03
You have guessed them all.
2:06
And print out the grid one more time so
they can see their handiwork.
2:13
self.create_grid and then set
2:17
game_running to False
since the game is over.
2:22
This will stop the while loop.
If they weren't a match,
2:31
if they weren't a match,
let's let the player know.
2:44
I'm going to use input here, so the player
gets a chance to see what the cards were
2:48
before the grid is printed again.
2:53
Finally, outside the while loop,
3:08
one more, there we go.
3:12
We can print out game over.
3:15
Since this will only get run when
game_running has been set to False and
3:22
the while loop has ended.
3:28
Look at all that hard work. Now let's jump
3:31
down to the bottom and
call our start_game method.
3:37
And let's finally play our game.
3:48
Keep playing the game on your own and
have fun.
4:12
You did great work.
4:15
Awesome job you put in a ton
of hard work in this course.
4:17
So pat yourself on the back. If
you wanna take the game further,
4:21
how would you incorporate a high score?
4:27
What about letting the user pick
their game size, 4 by 4 could be
4:30
easy than 8 by 8 is medium difficulty and
12 by 12 is hard mode.
4:34
Have fun and make it your own.
4:40
Now that you have some object
oriented programming knowledge,
4:43
the best way to solidify it further is
to try and create something on your own.
4:46
Check the teacher's notes for a few ideas.
4:52
Keep up the hard work Pythonistas!
4:55
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up