| | |
Simple Hangman Game
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2007
Posts: 140
Reputation:
Solved Threads: 15
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
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
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)
Left(txtLetterGuess.Text, 1)
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
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
regards,
Shaik Akthar
•
•
Join Date: Nov 2007
Posts: 140
Reputation:
Solved Threads: 15
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
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
•
•
Join Date: Nov 2007
Posts: 140
Reputation:
Solved Threads: 15
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.
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.
•
•
Join Date: Nov 2007
Posts: 140
Reputation:
Solved Threads: 15
•
•
•
•
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)
Private Sub cmdNewWord_Click() cmdStart.Enabled = True txtGuessWord.Enabled = True txtWord.Caption = "" lblGuesses = "" frmHangman.Enabled = False cmdGuess.Enabled = False txtLetterGuess.Enabled = False End Sub '---------------------------------------------------------------------- Private Sub cmdStart_Click() '---------------------------------------------------------------------------- Dim i As Integer 'start button and text box cannot be pressed and interfered with twice in a row cmdStart.Enabled = False txtGuessWord.Enabled = False ' Reset wrong guesses counter intWrongGuesses = 0 ' Enable letter guess field and button txtLetterGuess.Enabled = True cmdGuess.Enabled = True txtLetterGuess.Enabled = True cmdGuess.Enabled = True ' Get word from guess word field strWord = txtGuessWord.Text txtGuessWord.Text = vbNullString ' Get length of word intTotalLetters = Len(strWord) ' Re-Initialise the arrays for the word and letters guessed ReDim arrWord(intTotalLetters) As String ReDim arrLetters(intTotalLetters) As String 'Populate word field with hyphens to symbolise letters to be guessed For i = 1 To intTotalLetters arrWord(i) = Mid(strWord, i, 1) arrLetters(i) = "-" txtWord.Caption = txtWord.Caption & arrLetters(i) & " " Next End Sub
and for the Guess button
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
'Start button cannot be pressed if guess button has been pressed cmdStart.Enabled = False 'Text box cannot be interfered with if guess button has been pressed 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
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.
![]() |
Similar Threads
- Projects for the Beginner (Python)
- hangman game in C++ (C++)
- Help with hangman tutorial. (C++)
- C++ Programming issue (C++)
- Having Some Trouble with Methods (Java)
- reading(printing to screen) program (Python)
- Code Confusion (C#)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: inserting Serial No in Report
- Next Thread: Data grid addition problem?
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





