Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
HangMan
Author:
FutureCodesToday
E-mail:
Click to e-mail author
Submitted:
10/11/2014
Version:
VB 2010
Compatibility:
VB 2010, VB 2012, VB 2013
Category:
Game Programming
Views:
10673
Hangman game can be improved but mostly finished. 598 lines of code.
Declarations:
'none
Code:
Public Class frmHangman Dim Word As Integer Dim Fails As Integer Private Sub btnNewWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewWord.Click Fails = 0 Me.lblLeter1.Text = "#" Me.lblLeter2.Text = "#" Me.lblLeter3.Text = "#" Me.lblLeter4.Text = "#" Me.lblLeter5.Text = "#" Randomize() Word = Int(6 * Rnd() + 1) ' Picks number 1-6. Each number represents a word End Sub Private Sub btnA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnA.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Me.lblLeter2.Text = "A" ' Jacob - 1 End If If Word = 2 Then Me.lblLeter3.Text = "A" ' Grade - 2 End If If Word = 3 Then Fails = Fails + 1 ' Month - 3 End If If Word = 4 Then Fails = Fails + 1 ' Seven - 4 End If If Word = 5 Then Me.lblLeter5.Text = "A" ' Pizza - 5 End If If Word = 6 Then Me.lblLeter2.Text = "A" ' Water - 6 End If End Sub Private Sub btnB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnB.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Me.lblLeter5.Text = "B" End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnC.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Me.lblLeter3.Text = "C" End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnD.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Me.lblLeter4.Text = "D" End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnE.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Me.lblLeter5.Text = "E" End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Me.lblLeter4.Text = "E" Me.lblLeter2.Text = "E" End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Me.lblLeter4.Text = "E" End If End Sub Private Sub btnF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnF.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnG_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnG.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Me.lblLeter1.Text = "G" End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnH_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnH.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Me.lblLeter5.Text = "H" End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If End Sub Private Sub btnI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnI.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Me.lblLeter2.Text = "I" End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnJ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnJ.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Me.lblLeter1.Text = "J" End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnK.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnL.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnM.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Me.lblLeter1.Text = "M" End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub N_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles N.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Me.lblLeter3.Text = "N" End If If Word = 4 Then Me.lblLeter5.Text = "N" End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnO.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Me.lblLeter4.Text = "O" End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Me.lblLeter2.Text = "O" End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnP.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Me.lblLeter1.Text = "P" End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnQ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQ.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnR.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Me.lblLeter2.Text = "R" End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Me.lblLeter5.Text = "R" End If End Sub Private Sub btnS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnS.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Me.lblLeter1.Text = "S" End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnT.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Me.lblLeter4.Text = "T" End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Me.lblLeter3.Text = "T" End If End Sub Private Sub btnU_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnU.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnV.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Me.lblLeter3.Text = "V" End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnW.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Me.lblLeter1.Text = "W" End If End Sub Private Sub btnX_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnX.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnY_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnY.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Fails = Fails + 1 End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub btnZ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZ.Click Me.lblFails.Text = "Fails: " & Fails If Word = 1 Then Fails = Fails + 1 End If If Word = 2 Then Fails = Fails + 1 End If If Word = 3 Then Fails = Fails + 1 End If If Word = 4 Then Fails = Fails + 1 End If If Word = 5 Then Me.lblLeter3.Text = "Z" Me.lblLeter4.Text = "Z" End If If Word = 6 Then Fails = Fails + 1 End If End Sub Private Sub FailCountToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FailCountToolStripMenuItem.Click Me.lblFails.Text = "Fails: " & Fails End Sub Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click Application.Exit() End Sub End Class
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement