Advanced Search

Author Topic: SERTek: Correcting a Hangman program in Visual Logic  (Read 5283 times)

April 20, 2009, 12:17:15 PM
Read 5283 times

James

  • Should go on a ring diet

  • *

  • 3069
    Posts

  • blah

    • View Profile
    • My dA site
SERTek: Correcting a Hangman program in Visual Logic
« on: April 20, 2009, 12:17:15 PM »
Trying to fix some errors I'm getting in a Hangman program I'm working on. For some reason, it won't allow me to make arrays in the main logic, and when I try displaying an array full of "-", it displays zeroes instead. Can anyone help? I'll post pseudocode if needed.

April 21, 2009, 07:18:19 PM
Reply #1

James

  • Should go on a ring diet

  • *

  • 3069
    Posts

  • blah

    • View Profile
    • My dA site
Re: SERTek: Correcting a Hangman program in Visual Logic
« Reply #1 on: April 21, 2009, 07:18:19 PM »
Okay, I corrected the array and zeroes problems, but now I have another problem: it won't replace each "-" with a correct letter once I guess it.

Here's the pseudocode:

Quote
Begin
Make Array(hangmanAnswerx, 10)
Make Array(hangmanGuessx, 10)
Call Initializing
Call Processing
Call Finalizing
End

Initializing
Output (Console): “Welcome to Hangman!”
Output (Console): “Rules:”
Output (Console): “Guess a letter. If it’s in the word, it will be revealed on the board.”
Output (Console): “If not, a part is drawn.”
Output (Console): “Miss 7 guesses, and it’s a Hangman!”
Output (Console): "|---|"
Output (Console): "|   |"
Output (Console): "|"
Output (Console): "|"
Output (Console): "|"
Output (Console): "|"
Output (Console): "|"
Output (Console): "------------"
Return

Processing
playAgain = “ “
guessLetterx = “ “
Call InitializeArrays
Call RandomWordPick
Call DisplayWord
While playAgain <> “N”
   Call GetLetterInput
   Call CheckLetterMatch
   Call DisplayWord
   Call CheckMatchWin
EndWhile

InitializeArrays
For sub = 1 to sub = 10
   hangmanAnswerx(sub) = “ “
   hangmanGuessx(sub) = “ “
EndFor
Return

RandomWordPick
wordPicker = random(5)
If (wordPicker = 0)
   hangmanAnswerx(1) = “C“
   hangmanAnswerx(2) = “O“
   hangmanAnswerx(3) = “M“
   hangmanAnswerx(4) = “P“
   hangmanAnswerx(5) = “U“
   hangmanAnswerx(6) = “T“
   hangmanAnswerx(7) = “E“
   hangmanAnswerx(8 ) = “R“
   For sub = 1 to sub = 8
      HangmanGuessx(sub) = “-“
   EndFor
EndIf
If(wordPicker = 1)
   hangmanAnswerx(1) = “F“
   hangmanAnswerx(2) = “O“
   hangmanAnswerx(3) = “X“
   For sub = 1 to sub = 3
      hangmanGuessx(sub) = “-“
   EndFor

EndIf
If(wordPicker = 2)
   hangmanAnswerx(1) = “P“
   hangmanAnswerx(2) = “R“
   hangmanAnswerx(3) = “O“
   hangmanAnswerx(4) = “G“
   hangmanAnswerx(5) = “R“
   hangmanAnswerx(6) = “A“
   hangmanAnswerx(7) = “M“
   For sub = 1 to sub = 7
      hangmanGuessx(sub) = “-“
   EndFor
EndIf
If(wordPicker = 3)
   hangmanAnswerx(1) = “D“
   hangmanAnswerx(2) = “E“
   hangmanAnswerx(3) = “V“
   hangmanAnswerx(4) = “E“
   hangmanAnswerx(5) = “L“
   hangmanAnswerx(6) = “O“
   hangmanAnswerx(7) = “P“
   hangmanAnswerx(8 ) = “E“
   hangmanAnswerx(9) = “R“
   For sub = 1 to sub = 9
      hangmanGuessx(sub) = “-“
   EndFor
EndIf
If(wordPicker = 4)
   hangmanAnswerx(1) = “L“
   hangmanAnswerx(2) = “O“
   hangmanAnswerx(3) = “G“
   hangmanAnswerx(4) = “I“
   hangmanAnswerx(5) = “C“
   For sub = 1 to sub = 5
      hangmanGuessx(sub) = “-“
   EndFor
EndIf
Return

DisplayWord
For sub = 1 to sub = 10
   If hangmanGuessx(sub) <> “ “
      Output (Console): hangmanGuessx(sub)
   EndIf
EndFor
Return

GetInputLetter
Input (Console): guessLetterx
Return

CheckLetterMatch
correctCount = 0
badGuessCount = 0
For sub = 1 to sub = 10
   If hangmanAnswerx(sub) = guessLetterx
      hangmanGuessx(sub) = guessLetterx
      correctCount = correctCount + 1
   EndIf
EndFor
If correctCount = 0
   badGuessCount = badGuessCount + 1
   Call DrawHangman
EndIf
Return

DrawHangman
If badGuessCount = 1
   Output (Console): "|---|"
   Output (Console): "|   |"
   Output (Console): "|"
   Output (Console): "|"
   Output (Console): "|"
   Output (Console): "|  /"
   Output (Console): "| /"
   Output (Console): "------------"
EndIf
If badGuessCount = 2
   Output (Console): "|---|"
   Output (Console): "|   |"
   Output (Console): "|"
   Output (Console): "|"
   Output (Console): "|"
   Output (Console): "|  /\"
   Output (Console): "| /  \"
   Output (Console): "------------"
EndIf
If badGuessCount = 3
   Output (Console): "|---|"
   Output (Console): "|   |"
   Output (Console): "|"
   Output (Console): "|"
   Output (Console): "|   |"
   Output (Console): "|  /\"
   Output (Console): "| /  \"
   Output (Console): "------------"
EndIf
If badGuessCount = 4
   Output (Console): "|---|"
   Output (Console): "|   |"
   Output (Console): "|"
   Output (Console): "|"
   Output (Console): "|  /|"
   Output (Console): "|  /\"
   Output (Console): "| /  \"
   Output (Console): "------------"
EndIf
If badGuessCount = 5
   Output (Console): "|---|"
   Output (Console): "|   |"
   Output (Console): "|"
   Output (Console): "|"
   Output (Console): "|  /|\"
   Output (Console): "|  /\"
   Output (Console): "| /  \"
   Output (Console): "------------"
EndIf
If badGuessCount = 6
   Output (Console): "|---|"
   Output (Console): "|   |"
   Output (Console): "|"
   Output (Console): "|   |"
   Output (Console): "|   /|\"
   Output (Console): "|  /\"
   Output (Console): "| /  \"
   Output (Console): "------------"
EndIf
If badGuessCount = 7
   Output (Console): "|---|"
   Output (Console): "|   |"
   Output (Console): "|  ()"
   Output (Console): "|   |"
   Output (Console): "|  /|\"
   Output (Console): "|  /\"
   Output (Console): "| /  \"
   Output (Console): "------------"
   Call PlayAgainChoice(playAgain)
EndIf
Return

PlayAgainChoice(playAgain)
Input (Console): playSelect
While (playSelect <> “Y”) or (playSelect <> “N”)
   Output (Console): “Error. Please enter again.”
   Input (Console): playSelect
EndWhile
playAgain = playSelect
Return

CheckMatchWin
sub = 1
correctLetter = 0
While hangmanAnswerx <> “ “
   If hangmanAnswerx(sub) = hangmanGuessx(sub)
      correctLetter = correctLetter + 1
   EndIf
   sub = sub + 1
EndWhile
If correctLetter = sub
   Call PlayAgainChoice(playAgain)
EndIf
Return

Finalizing
Output (Console): "Thank you for playing!"
Return
End

April 21, 2009, 09:18:49 PM
Reply #2

James

  • Should go on a ring diet

  • *

  • 3069
    Posts

  • blah

    • View Profile
    • My dA site
Re: SERTek: Correcting a Hangman program in Visual Logic
« Reply #2 on: April 21, 2009, 09:18:49 PM »
... Could someone please help me with this? It's due tomorrow.

April 21, 2009, 09:59:19 PM
Reply #3

Southbird

  • Ring connoisseur

  • *

  • AKA "RobS" and something Epoch

  • 1139
    Posts

  • Starbounder

    • View Profile
    • YouTube
Re: SERTek: Correcting a Hangman program in Visual Logic
« Reply #3 on: April 21, 2009, 09:59:19 PM »
I don't know if any of us know this "Visual Logic" language here.  I've certainly never seen it before.  But I recommend you look up something about assigning character constants and formatted printing as a hint to what your problem may be.

April 22, 2009, 10:33:22 AM
Reply #4

James

  • Should go on a ring diet

  • *

  • 3069
    Posts

  • blah

    • View Profile
    • My dA site
Re: SERTek: Correcting a Hangman program in Visual Logic
« Reply #4 on: April 22, 2009, 10:33:22 AM »
Nevermind. Fixed and submitted. Go ahead and move this to the archive.