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.
All right,
let's make the start day 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.Then
0:39
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.
1:09
Next.
1:11
Guess one.
1:13
Check location and pass in first,
1:17
guess two self.check,
1:23
location pass in a second.
1:28
Now that we have their matches,
we can check them.
1:35
If self dot check, match,
1:40
I guess one, I guess two.
1:44
If they match, then we need to
see if the game has been one.
1:49
If self dot 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 dot create grid and then set game
2:17
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 grade 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 tonne
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 teachers notes for a few ideas.
4:52
Keep up the hard work by the knees does
4:55
You need to sign up for Treehouse in order to download course files.
Sign up