rock paper scissors game help

Hello, I have a game I am designing and I am having problems getting my code.

I have declared Wins and Losses in my global variables and am attempting to call those in a select case as show in my code. However it is not working properly, If you run the game you will see that the different message boxes do not show the correct information in them. I have a ttached the game for anyone who would like to help. How do I, at the end of my splash screen on my quit button, do I reset the game if they don't want to quit?

I can email the game to you if you would like to help... any help would be greatly appreciated...

[634 byte] By [Thanes] at [2008-2-15]
# 1
Thanes,

I'm sorry but you will need to provide more information. No one is going to be able to help you without actually providing some code. You will need to show some of the code that you are having trouble with on the actual post. Don't post the whole lot, just the section that is causing you trouble.

DavidM.Kean at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
How do I change my exit command so that if they don't want to exit then it will reset the following... rather reset the whole code.

lblwinner.caption
lblPlayerScore = Val(lblPlayerScore.Caption) + 1
lblRound.Caption = Val(lblRound.Caption) + 1
Private Sub cmdExit_Click()
Dim ExitGame As String
ExitGame = MsgBox("Are You Sure You want to Exit?", vbYesNo, "EXIT")
If ExitGame = vbYes Then
End
End If

Thanes at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
Hi,
I haven't used VB in quite a long time... But in C++/CLI and C# you could use the FormClosing event. then set the FromClosingEventArgs cancel property to true if you want to cancel the unloading of your form...
cheers,
Paul June A. Domag
PaulDomag at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
Hi,

Paul has a good suggestion.

Here is a bit of sample code to get you started. Note that we handle the FormClosing event, which is called anytime a user tries to close a form. This in turn calls a Function called ShouldGameClose which will return True or False based on the MsgBox. We also can call ShouldGameClose if the user clicks on a specific Exit button or command.



Public Class Form1

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

'note: don't call ShouldGameEnd again if application is already exiting

If (e.CloseReason <> CloseReason.ApplicationExitCall) AndAlso (Me.ShouldGameEnd) Then

'no need to do anything since form is closing

Else

'cancel form from closing and reset game

e.Cancel = True

Me.ResetGame()

End If

End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

'initialize game

Me.ResetGame()

End Sub

Private Sub btnStartGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartGame.Click

'simulate game play

Me.lblCaption.Text = "Rock"

Me.lblPlayerScore.Text = "50"

Me.lblWinner.Text = "Player 2"

End Sub

Private Sub btnResetGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResetGame.Click

Me.ResetGame()

End Sub

Private Sub btnEndGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEndGame.Click

'check with user if game should end

If Me.ShouldGameEnd Then

Application.Exit()

Else

Me.ResetGame()

End If

End Sub


'''
<summary>

''' resets game state

''' </summary>

''' <remarks></remarks>

Sub ResetGame()

Me.lblCaption.Text = ""

Me.lblPlayerScore.Text = "0"

Me.lblWinner.Text = ""

End Sub

''' <summary>

''' Prompts user if they want to exit app.

''' </summary>

''' <returns>True if they want to exit. </returns>

''' <remarks>Called by exit commands and form closing events</remarks>

Public Function ShouldGameEnd() As Boolean

Dim ExitGame As String = MsgBox("Are You Sure You want to Exit?", vbYesNo, "EXIT")

If ExitGame = vbYes Then

Return True

Else

Return False

End If

End Function

End Class



Hope this helps. Enjoy.

Paul Yuknewicz
Visual Basic

PaulYuk_MS at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...