pseudocode help needed for hangman game

Status
Not open for further replies.

racybabeuk

Beta member
Messages
4
Hi

I have to produce a hangman game for two players. Player one inputs a secret word between 6 and 10 characters long. The secret word is copied to a marker board displaying asterisks instead of the letters. Player two has to guess the secret word. For each correct guess the marker board is updated to show the correct letter replacing the asterisk. For each incorrect guess a piece of the hangman is displayed (9 pieces consisting of lines of stars for each body part).
The game ends when player two correctly guesses the secret word or incorrectly guesses 9 times.

I have started with the pseudocode and once I know it is correct i will then produce a flow chart before finally coding the program.

Could someone please look over my pseudocode and point out any obvious errors I may have made. For instance, I am not sure if it is legitimate to use an if.. then.. else construct nested in a repeat.. until construct? Or will the program never check for an incorrect guess but keep looping round checking for correct guesses until the game is over?


Code:
A pseudo code description of my solution algorithm
Play_hangman

Items of Interest: player one, player two, secret word, letter guess, word marker, hangman pieces, incorrect count, correct count.

Set		player one 
Set		player one 
Set  		secret word as an array greater than 6 and less than 10
Set 		letter guess 
Set 		word marker as an array of * characters to length of 				secret word
Set    	hangman pieces as 9 in a separate function to be called
Set		incorrect count to zero
Set		correct count to zero
Output 	message prompt for name of player one
Get		name of player one
Output	message prompt for named player one to input secret word between 6 and 10 characters length
Get		secret word 
Output	message prompt for name of player two
Get 		name of player two
Repeat
	Output message prompt for named player two to input                           
         letter guess
	Get letter guess
		IF   letter guess is a letter in the secret word   Then 
	      	     Output updated word marker with letter guess in 			      	     correct position replacing the *
	              increment correct guess counter  + 1
Until  correct guess is equal to secret word length
Output message You win
		Else 	
	       	    Output message prompt that the letter is not in the 			    secret word
	       	    Output hangman piece on screen 
	             increment incorrect guess counter + 1
Until  incorrect guess is equal to nine
Output message You lose
		Endif
END
 
This is what you want:

Code:
Repeat {
   Output message prompt for player                          
   Get letter guess
   IF   letter guess is correct   Then  {
      Output updated word marker with letter guess in 		correct position replacing the *
      increment correct guess counter  + 1
   }
   Else { 	
      Output message prompt that the letter is not in the 		secret word
      Output hangman piece on screen 
      increment incorrect guess counter + 1
  }
} Until  (correct guess is equal to secret word length OR incorrect guess is equal to nine)

if (correct guess equal to secret word length) then {
   Output message You win
}
else {
   Output message You lose
}

END

I added { and }, ( and ) for clarity
 
Thanks - I appreciate the help given on this forum and I hope one day I will be in a position to help others. We all need a bit of help now and then to grasp an idea and in this case I had written most of the pseudocode - it just needed rejigging about.

Suzanne
 
Status
Not open for further replies.
Back
Top Bottom