943,769 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Aug 16th, 2008
0

Re: Simple Hangman Game

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
Reputation Points: 13
Solved Threads: 17
Junior Poster
jonifen is offline Offline
152 posts
since Nov 2007
Aug 16th, 2008
0

Re: Simple Hangman Game

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
Reputation Points: 26
Solved Threads: 40
Posting Whiz
aktharshaik is offline Offline
316 posts
since Aug 2008
Aug 16th, 2008
0

Re: Simple Hangman Game

U CAN FIND SOME INTERESTING CODE HERE.


http://www.vb6.us/source-code/full-hangman-game-vb6
Reputation Points: 26
Solved Threads: 40
Posting Whiz
aktharshaik is offline Offline
316 posts
since Aug 2008
Aug 16th, 2008
0

Re: Simple Hangman Game

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.
Reputation Points: 26
Solved Threads: 40
Posting Whiz
aktharshaik is offline Offline
316 posts
since Aug 2008
Aug 16th, 2008
0

Re: Simple Hangman Game

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
Reputation Points: 13
Solved Threads: 17
Junior Poster
jonifen is offline Offline
152 posts
since Nov 2007
Aug 18th, 2008
0

Re: Simple Hangman Game

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??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lil' Tripsturr is offline Offline
16 posts
since Aug 2008
Aug 18th, 2008
0

Re: Simple Hangman Game

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.
Reputation Points: 13
Solved Threads: 17
Junior Poster
jonifen is offline Offline
152 posts
since Nov 2007
Aug 22nd, 2008
0

Re: Simple Hangman Game

cool thanx so far,im keen for new ways for me to improve the game ,any suggestions??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lil' Tripsturr is offline Offline
16 posts
since Aug 2008
Aug 23rd, 2008
0

Re: Simple Hangman Game

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lil' Tripsturr is offline Offline
16 posts
since Aug 2008
Aug 23rd, 2008
1

Re: Simple Hangman Game

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.
Reputation Points: 13
Solved Threads: 17
Junior Poster
jonifen is offline Offline
152 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: inserting Serial No in Report
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Report Problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC