D. Final Algorithm, Flowchart, or Pseudocode

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

  1. Start
  2. Welcome the user
  3. Generate two arrays, which are on different levels of difficulties
  4. Ask if the user wants to play the game or not.
  5. 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.
  6. generate the word needs to be guessed if the user enters “end” go to step 16.
  7. modify the guess into “*”.
  8. initiate the while loop
  9. if the current word equals to the word needs to be guessed go to step  14, if not go to step 10
  10. ask the user to guess a letter, if the user enters “end”. Go to step 16.
  11. if the user enters invalid input, go to step 10. Else go to step 12
  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
  13. 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.
  14.  Go to step 9
  15. The user successfully guesses the word. Print ” congrats!”
  16. End program.