Hangman Pseudocode
%Start
%Prompt user to enter whether he wants to play and what level to play.
%Generate the word the player needs to guess.
%Initialize variable “guessTime”=8;
%While loop, runs while “guessTime<=7”
- %If condition 1: current “guessWord” equals “targetWord”
- %If true, print”congrats!”
- %Prompt to let the player enter a valid guess
- %For loop: number of iteration = length of the word
- %Compare the letter to the letter on the current iteration.
- %Sum the numbers of logic returns
- %End loop
- %If condition 2 sum>1
- %For loop: number of iteration = length of the word
- %Compare the letter to the letter on the current iteration.
- %End loop
- %Elseif sum<1
- %Variable “guessTime”+1, “guessLeft”-1.
- %If condition 3: guessLeft = 0
- %If true, print” Game over!”.
%End while loop.
Hangman Final Algorithm
- Start
- Welcome the user
- Generate two arrays, which are on different levels of difficulties
- Ask if the user wants to play the game or not.
- If the user enters invalid input, go to step 4. If the user doesn’t want to play, go to step 16 if not continue step 6.
- generate the word needs to be guessed if the user enters “end” go to step 16.
- modify the guess into “*”.
- initiate the while loop
- if the current word equals to the word needs to be guessed go to step 14, if not go to step 10
- ask the user to guess a letter, if the user enters “end”. Go to step 16.
- if the user enters invalid input, go to step 10. Else go to step 12
- if the user enters a letter that is included in the word, then change the “*” in the corresponding position into the original letter. Else, variable “guessTime”+1
- show a picture of the stage of the game according to the value of “guessTime” and continue to step 14, if “guessTime” = 8 go to step 16.
- Go to step 9
- The user successfully guesses the word. Print ” congrats!”
- End program.