Friday: Creating Hangman
As the weeks go on, the projects will generally get longer. Today we’re going to be building Hangman with the use of all the concepts learned from the past four weeks. As usual, new concepts will be introduced as we code along. Today’s goal is to have a fully functioning Hangman game, where we can guess, lose a life, and win or lose the game. We won’t be adding graphics, although after we complete the project together, feel free to add them yourself.
To follow along with this lesson, let’s continue from our previous notebook file
“Week_04” and add a markdown cell at the bottom that says, “Friday Project: Creating Hangman.”
Final Design
As always, we want to lay out our final design before we begin coding. This week will not be based around graphics, like last week, so we’ll focus on the logic and the steps necessary to run the program. Luckily for us, the logic is essentially the steps needed to play the game:
Select a word to play with.
Ask user for input.
Check if guess is correct.
If it is, show the letter in the proper place.
If it isn’t, lose a life.
Continue steps 2 and 3 until one of the following occurs:
The user guesses the word correctly.
The user loses all their lives.
This is the main game play functionality. There are several other steps we need to perform before actually running the game, like declaring game variables; however, this is the primary functionality that we needed to lay out before we begin coding. Knowing this structure will allow us to stay on track with our program.
Previous Line Symbols Introduced
Like how we added line numbers back in Week 1, we’re going to introduce the concept of line symbols for this project and all others going forward. With the need to edit previously written lines, or even add code in the middle of the project, we’ll be introducing the concept of line symbols. These symbols will be shown by the use of three empty squares and will represent previously written code. You can see an example here:
1| if num > 1: ◻◻◻
3| # new code will go here
5| print( ◻◻◻
When we add lines in between previously written code, I will use these three squares to signify which line should be above and below the code we’re writing. It also means that you should leave the line unaltered. When we need to overwrite a previous line, I will let you know. Be sure to pay attention to line numbers when you see those three squares, as that will help to let you know if you missed a line or not.
Note turn lines on by pressing “L” after clicking the cell’s side
Do'stlaringiz bilan baham: |