You are here: DEVPPL Forum Programming Visual Basic Forum
NOTIFICATIONS
54.084
MEMBERS
15.684
TOPICS
62.255
POSTS
  562
FLASH GAMES
7.740
TUTORIALS
 

Login

E-mail:
Password:

Help PLEASE

0

Loading

Help PLEASE

Postby Routy » Tue Nov 01, 2011 3:58 pm

' Name: Hangman Game Project
' Purpose: Simulates the Hangman game
' Programmer:

Option Explicit On
Option Strict On
Option Infer Off

Public Class frmMain

Private Sub NewGameToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewGameToolStripMenuItem.Click
' simulates the Hangman game
Dim strWord As String
Dim strLetter As String
Dim blnValidWord As Boolean
Dim blnDashReplaced As Boolean
Dim blnGameOver As Boolean
Dim intIncorrect As Integer
Dim blnValidLetter As Boolean

'hide the picture boxes
picBottom.Visible = False
picPost.Visible = False
picTop.Visible = False
picRope.Visible = False
picHead.Visible = False
picBody.Visible = False
picRightArm.Visible = False
picLeftArm.Visible = False
picRightLeg.Visible = False
picLeftLeg.Visible = False

'get a 10-letter word from player 1 and convert to uppercase
strWord = InputBox("Enter a 10-letter word;", "Hangman Game").ToUpper

'determine whether the word contains 10 letters
blnValidWord = True 'assume the word is valid
If strWord.Length <> 10 Then
blnValidWord = False
Else
Dim intIndex As Integer
Do While intIndex < 10 AndAlso blnValidWord = True
If strWord.Substring(intIndex, 1) Like "[!A-Z]" Then
blnValidWord = False
End If
intIndex = intIndex + 1
Loop
End If

'if the world is not valid, display a message

If blnValidWord = False Then
MessageBox.Show("10 letters are required. ", "Hangman Game",
MessageBoxButtons.OK,
MessageBoxIcon.Information)

Else
'display ten dashes in lblWord and clear lblIncorrect
lblWord.Text = "----------"
lblIncorrect.Text = String.Empty

'get a letter from player 2 and convert to uppercase
strLetter = InputBox("Enter a letter:", "Letter", "", 600, 400).ToUpper
Dim intLetter As Integer
Do While intLetter < 26 AndAlso blnValidWord = True
If strLetter.Substring(intLetter, 1) Like "[!A-Z]" Then
blnValidLetter = False
End If
intLetter = intLetter + 1
Loop
End If
'if the world is not valid, display a message

If blnValidLetter = False Then
MessageBox.Show("Only letters of alphabet can be entered! ", "Hangman Game",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
'verify that player 2 entered a letter
' and that the games is not over
Else
Do While strLetter <> String.Empty AndAlso
blnGameOver = False

Loop
End If
'search the word for the letter
For intIndex As Integer = 0 To 9

'if the letter appears in the word, then
'replace the dash in lblWord and
'indicate that a replacement was made
If strWord.Substring(intIndex, 1) = strLetter Then
lblWord.Text = lblWord.Text.Remove(intIndex, 1)
lblWord.Text = lblWord.Text.Insert(intIndex, strLetter)
blnDashReplaced = True
End If
Next intIndex
' determine whether a dash was replaced
If blnDashReplaced = True Then

'if the word does not contain any dashes,
'the game is over because player 2
'guessed the word; otherwise, reset the
'blnDashReplaced variable for the next search
If lblWord.Text.Contains("-") = False Then
blnGameOver = True
MessageBox.Show("Great guessing!", "Game Over",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
blnDashReplaced = False
End If

Else
' processed when no dash was replaced
'display the incorrect letter, then update
'the intIncorrect variable,then show
'the appropriate picture box
lblIncorrect.Text =
lblIncorrect.Text & "" & strLetter
intIncorrect = intIncorrect + 1
Select Case intIncorrect
Case 1
picBottom.Visible = True
Case 2
picPost.Visible = True
Case 3
picTop.Visible = True
Case 4
picRope.Visible = True
Case 5
picHead.Visible = True
Case 6
picBody.Visible = True
Case 7
picRightArm.Visible = True
Case 8
picLeftArm.Visible = True
Case 9
picRightLeg.Visible = True
Case 10
picLeftLeg.Visible = True
blnGameOver = True
MessageBox.Show("Sorry, the word is " & strWord & ".", "Game Over",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Select
End If
'determine whetherr to get another letter
If blnGameOver = False Then
strLetter = InputBox("Enter a letter",
"Letter", "", 600, 400).ToUpper
End If

Loop

End If



End Sub


Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
End Class
Last edited by Routy on Thu Dec 29, 2011 6:47 pm, edited 1 time in total.
Routy
 
Reputation: 0
Posts: 2
Joined: Mon Oct 24, 2011 3:24 am
Highscores: 0
Arcade winning challenges: 0

Help PLEASE - Sponsored results

Sponsored results

Login to get rid of ads

 

0

Loading

Re: Help PLEASE

Postby Sanjon » Thu Nov 10, 2011 10:46 pm

The reason why it cannot work it because it is not looped. When the player presses on new game, they are asked one letter and then the program finishes. Instead, you should put the code that is executed when newgame is pressed inside a loop that stops once gameover = true.

I have a suggestion for the pictureboxes. Make one big picturebox that can fit the whole stick man. Then make a few pictures, every time adding something to his body (an arm, a leg). Name the pictures from 01 - 09 or whatever and cycle through them every time a wrong word is guessed.


If you have any questions let me know.
Sanjon
 
Reputation: 0
Posts: 40
Joined: Sun Dec 05, 2010 7:20 pm
Highscores: 0
Arcade winning challenges: 0
^ Back to Top