Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Hangman


Hangman

Author
Message
AdRock
AdRock
Forum God
Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)

Group: Forum Members
Posts: 21, Visits: 1

Hello

I have to create a game for my college course and i have chosen to make hangman

I have designed the layout of the game and now i am don to the coding. 

What i want to know is how do i write a fuinction to check if a letter is in the word that has been chosen.  I think i know how to add the hangman to the board etc but so the word is HOUSE.  How would i code it so if the user selects O it knows where in the word it is.

If anyone can help me i would be really chuffed.

Many thanks


waynespangler
waynespangler
Forum God
Forum God (98K reputation)Forum God (98K reputation)Forum God (98K reputation)Forum God (98K reputation)Forum God (98K reputation)Forum God (98K reputation)Forum God (98K reputation)Forum God (98K reputation)Forum God (98K reputation)

Group: Forum Members
Posts: 910, Visits: 5.4K

x = InStr("HOUSE","O")

if x=0 then letter is not in text otherwise x gives the place in text i.e. 2.

might have problems with more than one letter i.e. Moose would return 2 showing in second position. You would probably need a recursive function to check untill you return a 0.

Also convert text to upper case or lower case because O <> o.

 



Wayne

I know enough to be dangerious.

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.

James
James
Forum God
Forum God (117K reputation)Forum God (117K reputation)Forum God (117K reputation)Forum God (117K reputation)Forum God (117K reputation)Forum God (117K reputation)Forum God (117K reputation)Forum God (117K reputation)Forum God (117K reputation)

Group: Forum Members
Posts: 653, Visits: 14
You could use mid(String) function for this.




dim StrTest as String
dim StrLet as String

SreLet = UCase(text2.text) 'The letter searching for
StrTest = UCase(text1.Text) 'holds your word
For n = 1 to Len(text1.text)
If Mid(strTest, n, 1) = SreLet Then ‘If the selected Char is the letter
‘ do found code Like showing the image of the letter
End if
Next n

Hope this helps James




  


AdRock
AdRock
Forum God
Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)

Group: Forum Members
Posts: 21, Visits: 1

Here is what i have done so far but i am really stuck.

Any help would be appreciated

 

Many thanks


AdRock
AdRock
Forum God
Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)

Group: Forum Members
Posts: 21, Visits: 1

I managed to sort out the letters but what I'm stuck on now is when the word if finished how to let the program now that the word is found and it is the end of the game.  Also how do I hide the wrong letters and take a guess off the amount

 

here is the code from what i have done for the main form

 

Private word As String
Option Explicit

Private Sub Form_Load()
    Dim guess As Integer
    Dim a As Integer
       
    guess = 12
    GuessesLeft.Caption = "You have " & guess & " Guesses left"
    word = frmWord.txtWord.Text
   
    For a = 1 To Len(word)
        letter1(a - 1).Visible = True
    Next a
          
          
End Sub

Private Sub Label1_Click(Index As Integer)
    Dim i As Integer
    Dim go As String
   
    go = UCase(Label1(Index).Caption)
    word = UCase(word)
   
    For i = 1 To Len(word)
        If go = Mid(word, i, 1) Then
            letter1(i - 1).Caption = go
            Label1(Index).Visible = False
        End If
    Next i
   
End Sub


James
James
Forum God
Forum God (117K reputation)Forum God (117K reputation)Forum God (117K reputation)Forum God (117K reputation)Forum God (117K reputation)Forum God (117K reputation)Forum God (117K reputation)Forum God (117K reputation)Forum God (117K reputation)

Group: Forum Members
Posts: 653, Visits: 14
OK You've sorted it but I made the program anyway so here you go

I have added the completed word code

Private Sub lblLet_Click(Index As Integer)
blAppeared = False
blComplete = True
For n = 0 To Len(strWord) - 1
If Mid(strWord, n + 1, 1) = lblLet(Index).Caption Then 'if the letter exist in the label array
lblFind(n).ForeColor = vbBlack
lblLet(Index).BackColor = vbWhite
blAppeared = True 'letter has been found and used so boolean is set to true
End If
If lblFind(n).ForeColor = vbWhite Then
blComplete = False
End If

Next n

If blAppeared <> True Then
lblLet(Index).BackColor = vbRed 'if the letter was not found set the labels backcolor to red
lblGoes.Caption = lblGoes.Caption - 1 'decrement the goes label by 1
End If

If blComplete = True Then
MsgBox "WELL DONE"
Unload Me
Me.Show
End If


End Sub

the bits in bold handle the completion




  


waynespangler
waynespangler
Forum God
Forum God (98K reputation)Forum God (98K reputation)Forum God (98K reputation)Forum God (98K reputation)Forum God (98K reputation)Forum God (98K reputation)Forum God (98K reputation)Forum God (98K reputation)Forum God (98K reputation)

Group: Forum Members
Posts: 910, Visits: 5.4K

I made some changes to your program. Hope this helps.

One thing to keep in mind when designing a game (or any program) is the screen resolution. I use a 1024 x 768 screen so part of your forms I could not see and couldn't drag them high enought. I read that most people use a 1024 x 768 resolution, so you should design for that (anything more us old people can't read real good).

It is a pretty impressive game. Keep up the good work and let us know if we can help you.

 

 



Wayne

I know enough to be dangerious.

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.

AdRock
AdRock
Forum God
Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)

Group: Forum Members
Posts: 21, Visits: 1

I did notice that today at college.  When i made this game I was doing it at home and my screen resolution is quite high because of my monitor.  At college some monitors are only 800 x 600 so i will resize forms etc.

Anyway thanks for all the help in getting me on my way with my game.  I did get a bit further today but from what I gave seen so far is even better.   I will hopefully be done soon so at leat i can pass htis subject.

I'm sure I may need some more help soon if I get stuck again.  Just watch this space.

Thanks again for all your help


AdRock
AdRock
Forum God
Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)

Group: Forum Members
Posts: 21, Visits: 1

Just thinking about screen sizes and how to resize forms etc for people who may have 800 x 600 and I was thinking about rezing all my forms for 1024 x 768 but I got some code that resizes forms depending on the screen resolution.  The only problem is that it doesn't resize all the objects in the form such as labels etc.  I then found some code that does that but is poosible to combine the two so that the form can be resized and the components are resized to scale

Here is the code

If it is possible then I shall do that but if not I hall just make it 1024 x 768 (as long as it fits for checking at college, I'm not fussed but it would be nice for other users to play it)

Thanks again


AdRock
AdRock
Forum God
Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)Forum God (4.1K reputation)

Group: Forum Members
Posts: 21, Visits: 1
it didn't add this file
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search