stupidstudent
asked on
Help! Creating a Hangman game
I am creating a hangman game but don't know how to get the letter into the textbox and don't know how to get part by part of figure to show up if guessed incorrectly. Also after the figure is formed or guesses are exhausted, to end the game provided w/ the correct word. Here's the background info:
1) I currently have 10 empty textboxes (a 10 letter word).
2) I also have A-Z buttons so if a player depresses any one of those buttons, the letter will appear on one of the empty 10 boxes.
3) I also have some more textboxes that forms a figure of a person being hanged if the word is not guessed correctly.
Please show me how to do this w/ sample codes provided. Desperately seeking help. Thank you in advance for the person who's going to help my pathetic soul.
A Desperate Stupid Student
1) I currently have 10 empty textboxes (a 10 letter word).
2) I also have A-Z buttons so if a player depresses any one of those buttons, the letter will appear on one of the empty 10 boxes.
3) I also have some more textboxes that forms a figure of a person being hanged if the word is not guessed correctly.
Please show me how to do this w/ sample codes provided. Desperately seeking help. Thank you in advance for the person who's going to help my pathetic soul.
A Desperate Stupid Student
ASKER
Thanx fguerreiro_inix but that wasn't the answer I was looking for. I already have the concept but what I need is the code.
Option Explicit
Public sWord As String
Private Sub CmdLettersButton_Click(ind
'---- This button is an array of buttons with
'---- letters caption
Dim ipos As Integer
Dim bFindit As Boolean
For ipos = 1 To 10
If Text1(ipos).Tag = CmdLettersButton(index).Ca
Text1(ipos).Text = Text1(ipos).Tag
bFindit = True
End If
Next ipos
If Not bFindit Then
'---- Make your next textbox visible
'---- If last is visible
MsgBox "Game over"
End If
End Sub
Private Sub Command1_Click()
Dim ipos As Integer
sWord = InputBox("What's the word?", "Hangman")
For ipos = 1 To Len(sWord)
Text1(ipos).Tag = Mid(sWord, ipos, 1)
Text1(ipos).Text = ""
Next ipos
For ipos = Len(sWord) To 10
Text1(ipos).Text = ""
Text1(ipos).Tag = ""
Next ipos
End Sub
Think it through. Generate a word. Put the A-Z buttons in a control array. Put word text boxes in another control array. Instead of using circles and squares for the object, I'd use an image array. Gives you better looking Hangman and makes changing the picture easier. As the user clicks on A-Z scan the word for a match in the Click event:
Public Sub ...Click( index )
Guess = CHR( ASC( "A" + index ) ) ' Generate letter based on control index
result = INSTR( TheWord, Guess ) ' Look for match
If result > 0 then
'
' User guessed right
'
Text1( result ).Text = Guess 'Fill in the letter the user got right
else
'
' User guessed wrong
'
WrongCount = WrongCount + 1
hangman.image = PictureClip( WrongCount ) 'This isn't right, but you get the idea..
endif
Public Sub ...Click( index )
Guess = CHR( ASC( "A" + index ) ) ' Generate letter based on control index
result = INSTR( TheWord, Guess ) ' Look for match
If result > 0 then
'
' User guessed right
'
Text1( result ).Text = Guess 'Fill in the letter the user got right
else
'
' User guessed wrong
'
WrongCount = WrongCount + 1
hangman.image = PictureClip( WrongCount ) 'This isn't right, but you get the idea..
endif
stupidstudent,
Look over the Proposed Answer for this question and deside if it's what you want and post if you will accept it or if you will not accept it. I've got a sample program I'm working on that will do what you are asking dynamically, which I think would be the best for you as it will be the easiest to change to suit your needs. Up to you.
I've stopped working on it until I see if you're going to accept the Proposed Answer. If you accept it and it works, good... and I'll not waste my time.
HATCHET
Look over the Proposed Answer for this question and deside if it's what you want and post if you will accept it or if you will not accept it. I've got a sample program I'm working on that will do what you are asking dynamically, which I think would be the best for you as it will be the easiest to change to suit your needs. Up to you.
I've stopped working on it until I see if you're going to accept the Proposed Answer. If you accept it and it works, good... and I'll not waste my time.
HATCHET
ASKER
fguerreiro_inix and mark2150:
Thank you kindly for your answers and I am not rejecting any of your answers, but I would like to hear what HATCHET has to say... an enticing offer I cannot refuse.
One more thing, I would like to show the number of wrong guesses in a textbox as well.
HATCHET, please approach the podium.
Thank you kindly for your answers and I am not rejecting any of your answers, but I would like to hear what HATCHET has to say... an enticing offer I cannot refuse.
One more thing, I would like to show the number of wrong guesses in a textbox as well.
HATCHET, please approach the podium.
stupidstudent,
Ok. I am continuing my work on my sample program for you. Please post your Email here so I can send it to you when I'm done. Once finished, I'll post the code here for others to benefit from as well.
HATCHET
Ok. I am continuing my work on my sample program for you. Please post your Email here so I can send it to you when I'm done. Once finished, I'll post the code here for others to benefit from as well.
HATCHET
Hello stupidstudent, I think you want all work done by others.
I think with the anwers you have had, it´s time you start thinking a little.
It feel's nice to achive something by our own means.
The hangman programam you want is all almost posted here.
Regards and good luck
I think with the anwers you have had, it´s time you start thinking a little.
It feel's nice to achive something by our own means.
The hangman programam you want is all almost posted here.
Regards and good luck
If this is for a class project, getting others to do the work is not the answer.
... dee, dee, dum, dum ...
(... sounds of knitting & quiet humming...)
Just wrote a HANGMAN proto type along the lines of my first answer. You can click the letters and have them show up in the word list. Haven't gotten to such niceities as generating words (have KETCHUP hardcoded) yet, but is coming right along... Now where is that image of a hangman...
M
(... sounds of knitting & quiet humming...)
Just wrote a HANGMAN proto type along the lines of my first answer. You can click the letters and have them show up in the word list. Haven't gotten to such niceities as generating words (have KETCHUP hardcoded) yet, but is coming right along... Now where is that image of a hangman...
M
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
tomook, fguerreiro_inix, mark2150 & HATCHET:
Yes, I agree w/ y'all... I understand that asking others to do the work for me is totally unrewarding and how else am I going to learn, right? But (uh oh... I hear the violin playing) I've been working on this for 3 weeks now and I cannot get it to work. I am frustrated and I had to turn to others. I am new to VB and the instructor tossed this program in the students' face w/o lecture! So armed w/ a VB book and no knowledge of VB, I panic'd. Hopefully by providing the codes, I can see how's it done... that's all. So, please forgive me for getting y'all involved. So sorry all. Thank you, y'all been kind.
-StupidStudent-
Yes, I agree w/ y'all... I understand that asking others to do the work for me is totally unrewarding and how else am I going to learn, right? But (uh oh... I hear the violin playing) I've been working on this for 3 weeks now and I cannot get it to work. I am frustrated and I had to turn to others. I am new to VB and the instructor tossed this program in the students' face w/o lecture! So armed w/ a VB book and no knowledge of VB, I panic'd. Hopefully by providing the codes, I can see how's it done... that's all. So, please forgive me for getting y'all involved. So sorry all. Thank you, y'all been kind.
-StupidStudent-
ASKER
Thanx mark2150... thank you for everything.
Thanx all...
Thanx all...
When the player fails you start putting piece by piece visible.
When last piece is visible, the game ends.
Good luck