infinite loop?

skaboywrx

New member
Joined
May 8, 2009
Messages
1
Programming Experience
Beginner
:confused:Hello all,

I am a student working on the venerable "Hangman" project. We were tasked to create a hangman game that would get a random word from one of three sources either by file, by array, or by database file. I have managed to get a random word to import from all three but I run into a problem once I start to play the game. The program seems to run into an infitinite loop as soon as you enter a letter or it automatically dispays character entered and gives a game over. Please take a look any help is massivly apreciated. P.S. If there is a better way to paste the code please let me know. I will also attach .txt document
 

Attachments

  • HangManCodeComplete.txt
    11.8 KB · Views: 20
The logic that you have in Button4 is a little off. If you make it into pseudo code you have:

VB.NET:
Start Loop until gameover
Check letter against correct word
  if correct then make replace  

if replacement done
   if no more letters then        --- If you have a correct guess it will replace the same letter infinitely because the  
        gameover true                 loop has no exit point except for gameover = true. That will never be set because it
   else 	 		       it is only set when: 1) last incorrect guess, 2) last correct guess. if it is a 
        reset dashreplacement	       correct guess and not the last correct guess then loop forever.

else no replacement done
   process incorrect guess        <---- When the no replacement is done (which will happen infinitely for a wrong guess)
    increment # of IncorrectGuess       it will increment the guesses all the way up to #6, then of course it will be 
    show corresponding part             gameover (gameover = true) and that is when it will exit the loop.
    
Loop again

I would start by getting rid of the while loop, it is not needed.
 
Back
Top