| | |
Hangman Game
![]() |
•
•
Join Date: May 2009
Posts: 1
Reputation:
Solved Threads: 0
Hey guys first post here.
Down to business, i have to create a hangman game in VB5 for a Yr 12 assignment. So far i have created a help screen and a word list and a main menu list to navigate to these forms, however i am struggling with the main game section.
So far all i have mangaed to come up with is a flow chart of what i want the program to do:
1. Form loads the wordlist
2. Picks a random word from the wordlist and display it as dashes in a label called "lblWord"
3. Keyboard on Screen enabled (I have an on screen keyboard made of command buttons they also do not work)
4. Everytime a letter button is pressed the game needs to check through the word and if the letter is not in the word load the next image of the hangman picture and decrease the counter by one (counter counts down the amount of incorrect guesses remaining) If the letter is in the word the dash in the word needs to be replaced with the letter.
5. The letter on the on-screen keyboard is disabled
6. If the word is complete user as won
7. If te hangman counter reaches zero the user has lost
This is what i have so far regarding the actual game, i also need help with making the letters work on the on screen keyboard.
Thanks fo any/all help you can give me
Sniper87
Down to business, i have to create a hangman game in VB5 for a Yr 12 assignment. So far i have created a help screen and a word list and a main menu list to navigate to these forms, however i am struggling with the main game section.
So far all i have mangaed to come up with is a flow chart of what i want the program to do:
1. Form loads the wordlist
2. Picks a random word from the wordlist and display it as dashes in a label called "lblWord"
3. Keyboard on Screen enabled (I have an on screen keyboard made of command buttons they also do not work)
4. Everytime a letter button is pressed the game needs to check through the word and if the letter is not in the word load the next image of the hangman picture and decrease the counter by one (counter counts down the amount of incorrect guesses remaining) If the letter is in the word the dash in the word needs to be replaced with the letter.
5. The letter on the on-screen keyboard is disabled
6. If the word is complete user as won
7. If te hangman counter reaches zero the user has lost
This is what i have so far regarding the actual game, i also need help with making the letters work on the on screen keyboard.
Thanks fo any/all help you can give me
Sniper87
Last edited by Sniper87; May 14th, 2009 at 11:50 pm.
•
•
Join Date: Mar 2009
Posts: 807
Reputation:
Solved Threads: 147
Well since you have command buttons on the form you cannot use the form's keypreview property but you can use any of the following events of the command buttons as long as they have the focus...
KeyDown, KeyPress, KeyUp
Now, as for checking if the letter is within the word/phrase you can use the Instr function (see vb's help(*)). To replace the dash with the letter the user guessed you can use the mid function(*). Also, when the user has a word like "Remember" and they guess the "e" you will need to check for each "e" in a loop when using instr.
As for incorrect guesses you will need a form level variable and as each new game starts you will have to reset it there. Then as each incorrect guess is made you will have to decrement the value of the variable prior to displaying its value and prior to testing it for equaling zero (0).
Good Luck
KeyDown, KeyPress, KeyUp
Now, as for checking if the letter is within the word/phrase you can use the Instr function (see vb's help(*)). To replace the dash with the letter the user guessed you can use the mid function(*). Also, when the user has a word like "Remember" and they guess the "e" you will need to check for each "e" in a loop when using instr.
As for incorrect guesses you will need a form level variable and as each new game starts you will have to reset it there. Then as each incorrect guess is made you will have to decrement the value of the variable prior to displaying its value and prior to testing it for equaling zero (0).
Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.
Thanks
Thanks
•
•
Join Date: Sep 2006
Posts: 23
Reputation:
Solved Threads: 0
I presume the Command buttons on the screen are linked to letters of the alpabet. If you set up these buttons with the same name so they are indexed it is fairly simple to linke the index of the command button to the letter e.g. Command(0)=A Command(1) =B etc etc
When a button is pressed you can determine the letter as the index will relate to the Ascii number. Command(0) = Ascii 65 = A, Command(1) = 66 = B and so on.
once you know what the letter is you can then loop through your "word" to see if it is present. If it is you replace your dash with the letter.
If it isn't then increment the miss counter by one and load the correct picture. You can do this with a
Select MissCount
case 1: Picture1.load Image1
case 2: Picture1.load Image2
etc etc
end select
Hope this helps ... good luck
When a button is pressed you can determine the letter as the index will relate to the Ascii number. Command(0) = Ascii 65 = A, Command(1) = 66 = B and so on.
once you know what the letter is you can then loop through your "word" to see if it is present. If it is you replace your dash with the letter.
If it isn't then increment the miss counter by one and load the correct picture. You can do this with a
Select MissCount
case 1: Picture1.load Image1
case 2: Picture1.load Image2
etc etc
end select
Hope this helps ... good luck
•
•
Join Date: May 2009
Posts: 372
Reputation:
Solved Threads: 26
www.geocities.com\excelmarksway
Select Games > Hangman.xls
Save the file.
Open Excel then open Hangman.xls
Select Games > Hangman.xls
Save the file.
Open Excel then open Hangman.xls
![]() |
Similar Threads
- Simple Hangman Game (Visual Basic 4 / 5 / 6)
- Simple Hangman Game (VB.NET)
- hangman game (C++)
- hangman game in C++ (C++)
- newbie in need of help for hangman game (Python)
- Homework Help - Hangman Game (VB.NET)
- Need help with a certain part to a hangman game.. (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Create new row in table
- Next Thread: recieve sms
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college 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 save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





