|  |
11-12-2005, 04:13 PM
|
#1 (permalink)
|
Newb Techie Join Date: May 2004 Posts: 4
| pseudocode help needed for hangman game 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
|
| |
11-12-2005, 11:11 PM
|
#2 (permalink)
|
Ultra Techie Join Date: Jul 2005 Posts: 530
| 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
__________________ Desktop machine: 2 x Opteron 246, Asus K8N-DL, 2GB PC3200 ECC Reg., XFX GeForce 6600GT, 74gb WD Raptor, 2 x 19\" LCDs, Windows XP x64
Server machine: Intel P4 3.0GHz 2MB EM64T, ECS i865pe, 1GB PC3200, 36gb WD Raptor, Windows Server 2003
Laptop: Dell Inspiron 9100 (Intel P4 3.2GHz 1MB Prescott, i865pe, 512MB PC3200, Mobility Radeon 9700, DVD+R/DL Burner), Windows XP
Linux: P3 450Mhz, 386MB ram, Slackware 10.1 (Running mySQL/Apache) |
| |
11-13-2005, 04:49 AM
|
#3 (permalink)
|
Newb Techie Join Date: May 2004 Posts: 4
| Thats excellent - thank you very much |
| |
11-17-2005, 06:58 PM
|
#4 (permalink)
|
Monster Techie Join Date: Sep 2005 Location: Boston, MA Posts: 1,791
| sheesh, getting someone else to do your homework. I didnt know thats what this forum was all about.
__________________ Lenovo Thinkpad T60
Intel Core 2 Duo T7200 @ 2.00 Ghz
2 GB DDR-2 memory
ATI Mobility Radeon x1400
60 GB 7200 rpm Hard Drive
Windows Vista Business SP1 32 Bit |
| |
11-17-2005, 09:56 PM
|
#5 (permalink)
|
Ultra Techie Join Date: Jul 2005 Posts: 530
| Helping a guy with some pseudocode hardly qualifies.
__________________ Desktop machine: 2 x Opteron 246, Asus K8N-DL, 2GB PC3200 ECC Reg., XFX GeForce 6600GT, 74gb WD Raptor, 2 x 19\" LCDs, Windows XP x64
Server machine: Intel P4 3.0GHz 2MB EM64T, ECS i865pe, 1GB PC3200, 36gb WD Raptor, Windows Server 2003
Laptop: Dell Inspiron 9100 (Intel P4 3.2GHz 1MB Prescott, i865pe, 512MB PC3200, Mobility Radeon 9700, DVD+R/DL Burner), Windows XP
Linux: P3 450Mhz, 386MB ram, Slackware 10.1 (Running mySQL/Apache) |
| |
11-18-2005, 05:04 AM
|
#6 (permalink)
|
Newb Techie Join Date: May 2004 Posts: 4
| 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 |
| |  | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | |