Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 10th, 2006, 03:39 PM
Samantha07 Samantha07 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 3 Samantha07 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 5 sec
Reputation Power: 0
Hangman Game

I created a Form for a Hangman Game, it's very basic, there's no actual hangman image. I wrote the code and it worked but there was no "3 strikes you're out" type of thing, you could just keep clicking letters until you solved the puzzle. I tried to make it so when you click a wrong letter, an X appears on the screen. I want a box to pop up and say Game Over when there are 6 Xs visible at the top of the screen, but I can't figure it out. The file is on my website: http://home.mchsi.com/~sissipoo246/Hangman.exe )

Reply With Quote
  #2  
Old June 12th, 2006, 01:13 AM
thayalan44 thayalan44 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 29 thayalan44 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 10 m 55 sec
Reputation Power: 0
Use a counter which is incremented by 1 whenever X increases. Whenever X increases, an If clause should be used which checks if the value of X = 6 which has the following codes (which can be modified to suit your program) as shown below within the tags [Code][\Code].

[Code]
If Xcounter = 6 Then
MsgBox "GAME OVER", vbOKOnly, "HANGMAN"
Exit Sub
End If
[\Code]
Comments on this post
Samantha07 agrees!

Reply With Quote
  #3  
Old June 14th, 2006, 03:51 AM
Samantha07 Samantha07 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 3 Samantha07 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 5 sec
Reputation Power: 0
Erm, I'm extremely new to Visual Basic, I have no clue how to create a counter (Let alone make one that goes up every time another X shows up.) What you said makes sense, but I just haven't learned all that much about programming.

Reply With Quote
  #4  
Old June 14th, 2006, 08:55 AM
Darius Darius is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 108 Darius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
Quote:
Originally Posted by Samantha07
Erm, I'm extremely new to Visual Basic, I have no clue how to create a counter (Let alone make one that goes up every time another X shows up.) What you said makes sense, but I just haven't learned all that much about programming.

You will need to make a global variable ie. Xcounter , at the beginning of the form ... not inside a subroutine
(Dim Xcounter)
and add 1 to the variable each time that the user fail
(Xcounter =Xcounter +1)

Reply With Quote
  #5  
Old June 14th, 2006, 09:59 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is online now
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 36 m 35 sec
Reputation Power: 1243
If you are still confused just post your code and I will illustrate how to implement the suggestions you have been given.

Reply With Quote
  #6  
Old June 15th, 2006, 02:44 AM
Samantha07 Samantha07 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 3 Samantha07 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 5 sec
Reputation Power: 0
Dim Xcounter

Private Sub A1_Click()
Text1.Text = "Correct!"
LabelA.Caption = "A"
A1.Enabled = False
End Sub

Private Sub B1_Click()
Text1.Text = "Correct!"
LabelB.Caption = "B"
B1.Enabled = False
End Sub

Private Sub C1_Click()
Text1.Text = "Incorrect."
CLabel.Visible = True
C1.Enabled = False
Xcounter = Xcounter + 1
If Xcounter = 6 Then
MsgBox "GAME OVER", vbOKOnly, "HANGMAN"
Exit Sub
End If
End Sub

That's the first bit. The rest looks the same, but different letters and whatnot.
The whole counter thing works, really well. (Thank you!) Now my problem is that I want to make it so, when it comes up GAME OVER the rest of the letters become visible, so you can see the answer.
If seeing how it works now would help you help me... http://home.mchsi.com/~sissipoo246/Hangman.exe

Reply With Quote
  #7  
Old June 15th, 2006, 03:31 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is online now
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 36 m 35 sec
Reputation Power: 1243
Hi,

All you have to do is to make the labels visible, I dont know the names of your labels so you will have
to change the names accordingly. I believe most of them are correct but because there are several E's
they may be LabelE1, LabelE2 etc.:
Code:
Private Sub C1_Click()
Text1.Text = "Incorrect."
CLabel.Visible = True
C1.Enabled = False
Xcounter = Xcounter + 1
If Xcounter = 6 Then
	MsgBox "GAME OVER", vbOKOnly, "HANGMAN"
	LabelB.Caption = "B"
	LabelE.Caption = "E"
	LabelS.Caption = "S"
	LabelT.Caption = "T"
	LabelD.Caption = "D"
	LabelA.Caption = "A"
	LabelD.Caption = "D"
	LabelE.Caption = "E"
	LabelV.Caption = "V"
	LabelE.Caption = "E"
	LabelR.Caption = "R"
Exit Sub
End If
End Sub

Reply With Quote
  #8  
Old June 15th, 2006, 04:36 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is online now
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 36 m 35 sec
Reputation Power: 1243
Hi,

Just thought I'd throw something together to demonstrate how to use arrays to allow multiple questions instead of just one possibility.

The basis of the project is two control arrays, one for the labels on the form which will display the blanks/letters and one for the command buttons which allow the user to guess. To add a control array you just put a control (eg. a button) on the form and right click on it and select "Copy", then "paste" it anywhere on the form. You will see a message saying "do you want to create a control array?", click OK. You can now paste as many command buttons as you want (in this case 26, 1 for each letter of the alphabet!!), each one will have the same name but with a subscript which identifies it. Now, instead of a seperate subroutine for each of your 26 command buttons you just need one and you can identify the letter selected by the index of the button.

The simplified code now looks like this:
Code:
Option Explicit

Dim arrayofanswers(10) As String
Dim givenanswer() As String
Dim wronganswers As Integer
Dim ok As Boolean
Dim ano As Double
Dim ano2 As Integer
Dim a As Integer

Public Sub dosearch(x As String)
Dim b As Integer
ok = False
Dim g As Integer
g = 0
For b = 0 To UBound(givenanswer) - 1
If UCase(givenanswer(b)) = x Then
    g = g + 1
    Label3(b) = x
    ok = True
End If
Next
If g >= 1 Then
    If g = 1 Then
        Label2.Caption = "Well Done, there is 1 " & x
    Else
        Label2.Caption = "Well Done, there are " & g & " " & x & "s"
    End If
Else
    Label2.Caption = "Sorry, there are no " & x & "s"
End If
If ok = False Then
    Label1.Caption = Label1.Caption & " X "
    wronganswers = wronganswers + 1
    Dim tempstring As String
    Dim k As Integer
    For k = 0 To UBound(givenanswer) - 1
        tempstring = tempstring & givenanswer(k)
    Next
    Dim vbQuote As String
    vbQuote = Chr(34)
    Dim prompt$
    prompt$ = "Game Over - The Correct Answer Was " & vbQuote & tempstring & vbQuote
    If wronganswers = 6 Then MsgBox (prompt$)
End If
End Sub

Private Sub Command1_Click(Index As Integer)
Command1(Index).Enabled = False
Select Case Index
Case Is = 0
Call dosearch("A")
Case Is = 1
Call dosearch("B")
Case Is = 2
Call dosearch("C")
Case Is = 3
Call dosearch("D")
Case Is = 4
Call dosearch("E")
Case Is = 5
Call dosearch("F")
Case Is = 6
Call dosearch("G")
Case Is = 7
Call dosearch("H")
Case Is = 8
Call dosearch("I")
Case Is = 9
Call dosearch("J")
Case Is = 10
Call dosearch("K")
Case Is = 11
Call dosearch("L")
Case Is = 12
Call dosearch("M")
Case Is = 13
Call dosearch("N")
Case Is = 14
Call dosearch("O")
Case Is = 15
Call dosearch("P")
Case Is = 16
Call dosearch("Q")
Case Is = 17
Call dosearch("R")
Case Is = 18
Call dosearch("S")
Case Is = 19
Call dosearch("T")
Case Is = 20
Call dosearch("U")
Case Is = 21
Call dosearch("V")
Case Is = 22
Call dosearch("W")
Case Is = 23
Call dosearch("X")
Case Is = 24
Call dosearch("Y")
Case Is = 25
Call dosearch("Z")
End Select
End Sub

Private Sub Command2_Click()
Call getrandomquestion
wronganswers = 0
For a = 0 To 25
Command1(a).Enabled = True
If a < 13 Then Label3(a).Caption = "     "
Label1.Caption = ""
Label2.Caption = ""
Next
End Sub

Private Sub Form_Load()
wronganswers = 0
arrayofanswers(0) = "aaaaaaaaaaaa"
arrayofanswers(1) = "bbbbbbbbbbbb"
arrayofanswers(2) = "cccccccccccc"
arrayofanswers(3) = "ddd d d d dd"
arrayofanswers(4) = "eeeeeeeeeeee"
arrayofanswers(5) = "etc"
arrayofanswers(6) = "best dad ever"
arrayofanswers(7) = ""
arrayofanswers(8) = ""
arrayofanswers(9) = ""
Randomize
Call getrandomquestion
End Sub

Private Sub getrandomquestion()
ano = Rnd
ano2 = ano * 9
For a = 1 To 12
Label3(a).Visible = False
Next
ReDim givenanswer(Len(arrayofanswers(ano2)))
For a = 1 To Len(arrayofanswers(ano2))
givenanswer(a - 1) = Left(arrayofanswers(ano2), a)
givenanswer(a - 1) = Right$(givenanswer(a - 1), 1)
If givenanswer(a - 1) = " " Then
    Label3(a - 1).Visible = False
Else
    Label3(a - 1).Visible = True
End If
Next
End Sub

Last edited by sync_or_swim : June 20th, 2006 at 10:38 AM. Reason: Removed Attachment due to Problems - Samantha, if you haven't downloaded the sample project let me know and I will attach it again for you

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Hangman Game


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT