Simple Hangman Game

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2007
Posts: 140
Reputation: jonifen is an unknown quantity at this point 
Solved Threads: 15
jonifen jonifen is offline Offline
Junior Poster

Re: Simple Hangman Game

 
0
  #11
Aug 16th, 2008
You could lock the top text field ("Locked" in the properties when looking at the form in VB) to stop the text field being edited.
Needless to say, if a correct character is entered after the top box is changed, it would reset it to what it should be anyway. Changing what is in that box would not give you the ability to cheat, put it that way.
If you preferred a label, it would be easy to change it to that. Just update the code so anything which has "txtWord.Text" in, it is changed to "Label1.Caption" ("Label1" can be changed to whatever you named your label).


Unsure how you would stop people entering more than one letter in the guess field. I suppose you could use
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Left(txtLetterGuess.Text, 1)
when getting the letter that the user entered. That would then only take the first letter entered, and would only put one in the wrong guesses label.
You could put in a check for if the entered character is a letter or if it is a number or other symbol and alert the user to a wrongly entered character.

Someone may know a better way of doing this though... fingers crossed someone sees this thread and can help with this part.


Finally, I get an email alert when a thread I have participated in has been updated, so you don't need to send me a PM to let me know if you have added something new
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 304
Reputation: aktharshaik is an unknown quantity at this point 
Solved Threads: 37
aktharshaik's Avatar
aktharshaik aktharshaik is offline Offline
Posting Whiz

Re: Simple Hangman Game

 
0
  #12
Aug 16th, 2008
Mr. jonifen u have a good knowledge of VB. its gr8. try to make the game more interesting. you have made the hangman to appear letter by letter. ok. if the word is only 4 letters long? what if the word would have to be 7 letters long? i am also trying out a little bit on this. u can plz find some better soln very soon from me.


regards,
Shaik Akthar
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 304
Reputation: aktharshaik is an unknown quantity at this point 
Solved Threads: 37
aktharshaik's Avatar
aktharshaik aktharshaik is offline Offline
Posting Whiz

Re: Simple Hangman Game

 
0
  #13
Aug 16th, 2008
U CAN FIND SOME INTERESTING CODE HERE.


http://www.vb6.us/source-code/full-hangman-game-vb6
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 304
Reputation: aktharshaik is an unknown quantity at this point 
Solved Threads: 37
aktharshaik's Avatar
aktharshaik aktharshaik is offline Offline
Posting Whiz

Re: Simple Hangman Game

 
0
  #14
Aug 16th, 2008
To limit the entry of more than one letter, just set the maxlength property of the textbox to 1.

to limit the entry of characters from "a through z" only use the
TextBox_KeyPress() event.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 140
Reputation: jonifen is an unknown quantity at this point 
Solved Threads: 15
jonifen jonifen is offline Offline
Junior Poster

Re: Simple Hangman Game

 
0
  #15
Aug 16th, 2008
aktharshaik,

I had made my version to work with any length of word. What I didn't take into account was multiple words (to form phrases etc.) - I only really noticed that when I looked at the URL you posted for a Hangman game in complete form (which I have to say is an excellent example Thanks for sharing that link).

Finally, thanks for the advice on the maximum length of text boxes. I'd never used that functionality before, but cannot believe it is so simple to put in place!


Thanks again,

Jon
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 16
Reputation: Lil' Tripsturr is an unknown quantity at this point 
Solved Threads: 0
Lil' Tripsturr Lil' Tripsturr is offline Offline
Newbie Poster

Re: Simple Hangman Game

 
0
  #16
Aug 18th, 2008
thank u guys for the help so far im currently attempting a hangman game for my son which is 1 player with preset words.Its all good so far,ill post it wen its completed.

But i need help with...

making a label that shows the amount of guesses,and one that shows the correct guesses
any tips??
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 140
Reputation: jonifen is an unknown quantity at this point 
Solved Threads: 15
jonifen jonifen is offline Offline
Junior Poster

Re: Simple Hangman Game

 
0
  #17
Aug 18th, 2008
For capturing good/wrong guesses, you could piggy back onto the code which either draws another limb onto the Hangman, or updates the text boxes for a valid guess.

There is something similar in the code which aktharshik linked us to which tracks the amount of games played, and the amount won. You could use similar functionality for the guesses.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 16
Reputation: Lil' Tripsturr is an unknown quantity at this point 
Solved Threads: 0
Lil' Tripsturr Lil' Tripsturr is offline Offline
Newbie Poster

Re: Simple Hangman Game

 
0
  #18
Aug 22nd, 2008
cool thanx so far,im keen for new ways for me to improve the game ,any suggestions??
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 16
Reputation: Lil' Tripsturr is an unknown quantity at this point 
Solved Threads: 0
Lil' Tripsturr Lil' Tripsturr is offline Offline
Newbie Poster

Re: Simple Hangman Game

 
0
  #19
Aug 23rd, 2008
i have fixed the problem already ,don't worry guys!

I am still updating the game so keep checking back !!
Last edited by Lil' Tripsturr; Aug 23rd, 2008 at 9:58 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 140
Reputation: jonifen is an unknown quantity at this point 
Solved Threads: 15
jonifen jonifen is offline Offline
Junior Poster

Re: Simple Hangman Game

 
1
  #20
Aug 23rd, 2008
Originally Posted by Lil' Tripsturr View Post
Ive just hit a wall in the game that a user submitted here ,ive made some changes to it such as not being able to interfere with the label at the top,not being able to type in the guess box until a word is entered,and ive made a "new word" button that clears the word text at the top .BUT when it is clicked,the whole game freezes and i have no idea why if anyone can help me as quicly as possible id be grateful

heres the code for the new word button and the start button

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub cmdNewWord_Click()
  2. cmdStart.Enabled = True
  3. txtGuessWord.Enabled = True
  4. txtWord.Caption = ""
  5. lblGuesses = ""
  6. frmHangman.Enabled = False
  7. cmdGuess.Enabled = False
  8. txtLetterGuess.Enabled = False
  9.  
  10. End Sub
  11.  
  12.  
  13. '----------------------------------------------------------------------
  14. Private Sub cmdStart_Click()
  15. '----------------------------------------------------------------------------
  16. Dim i As Integer
  17. 'start button and text box cannot be pressed and interfered with twice in a row
  18. cmdStart.Enabled = False
  19. txtGuessWord.Enabled = False
  20. ' Reset wrong guesses counter
  21. intWrongGuesses = 0
  22. ' Enable letter guess field and button
  23. txtLetterGuess.Enabled = True
  24. cmdGuess.Enabled = True
  25. txtLetterGuess.Enabled = True
  26. cmdGuess.Enabled = True
  27. ' Get word from guess word field
  28. strWord = txtGuessWord.Text
  29. txtGuessWord.Text = vbNullString
  30. ' Get length of word
  31. intTotalLetters = Len(strWord)
  32. ' Re-Initialise the arrays for the word and letters guessed
  33. ReDim arrWord(intTotalLetters) As String
  34. ReDim arrLetters(intTotalLetters) As String
  35. 'Populate word field with hyphens to symbolise letters to be guessed
  36. For i = 1 To intTotalLetters
  37. arrWord(i) = Mid(strWord, i, 1)
  38. arrLetters(i) = "-"
  39. txtWord.Caption = txtWord.Caption & arrLetters(i) & " "
  40. Next
  41. End Sub

and for the Guess button

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 'Start button cannot be pressed if guess button has been pressed
  2. cmdStart.Enabled = False
  3. 'Text box cannot be interfered with if guess button has been pressed
  4. txtGuessWord.Enabled = False

i cant work out what is the problem,can anyone apeculate as to why the game freezes when the 'new word' button is pressed??
thanx
I noticed for your new method you did not have an End Sub and the line of hyphens above the next method header did not have a preceding apostrophe to let VB know it is a comment. I've made those changes.

You've also got a line in there saying:

frmHangman.Enabled = False

I'm unsure that is required, and could be why your game appears to freeze.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC