Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27365

VS 2010 Need help with a glitch in my game

$
0
0
Hello,

I have a glitch in my game that I have no clue how to figure out. The original game has 15 cards and one will flip once the start button is clicked, they will turn back once clicked and change to another one of the cards. But if the user doesn't click the card fast enough then the card will flip back and change cards. My problem is that sometimes when the card is clicked, two cards will appear and I believe it is because I need to reset the timer. I have tried:
tmrActionTimer.Enabled = False
tmrActionTimer.Enabled = True
But it doesn't seem to do the trick.



Here is the code to a simpler version of the game, it has the same glitch but with less cards (if you test it out just replace the 'Edmonton_Oilers' and 'Edmonton_Oilers_2'):

Public Class frmTest
Dim Score As Integer
Dim ActionTimer As Integer
Dim TargetCard As Integer
Private Sub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click, picTest4.Click, picTest3.Click, picTest1.Click, picTest2.Click
Call RandomNum(TargetCard)
Me.btnStart.Enabled = False
If Score = 20 Then
MessageBox.Show("You Win")
Application.Restart()
End If
End Sub

Sub RandomNum(ByVal TargetCard As Integer)
Me.tmrActionTimer.Enabled = True
TargetCard = Int(4 - 1 + 1) * Rnd() + 1
Select Case TargetCard
Case 1
Me.picTest1.Image = My.Resources.Edmonton_Oilers
Me.picTest1.Enabled = True
Case 2
Me.picTest2.Image = My.Resources.Edmonton_Oilers
Me.picTest2.Enabled = True
Case 3
Me.picTest3.Image = My.Resources.Edmonton_Oilers
Me.picTest3.Enabled = True
Case 4
Me.picTest4.Image = My.Resources.Edmonton_Oilers
Me.picTest4.Enabled = True
End Select
End Sub

Private Sub picTest1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picTest1.Click
Me.tmrActionTimer.Enabled = False
Me.tmrActionTimer.Interval = 1000
Me.tmrActionTimer.Enabled = True
Me.picTest1.Image = My.Resources.Edmonton_Oilers_2
Score += 1
Me.lblScore.Text = Score
Me.picTest1.Enabled = False
Call RandomNum(TargetCard)
End Sub
Private Sub picTest2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picTest2.Click
Me.tmrActionTimer.Enabled = False
Me.tmrActionTimer.Interval = 1000
Me.tmrActionTimer.Enabled = True
Me.picTest2.Image = My.Resources.Edmonton_Oilers_2
Score += 1
Me.lblScore.Text = Score
Me.picTest2.Enabled = False
Call RandomNum(TargetCard)
End Sub
Private Sub picTest3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picTest3.Click
Me.tmrActionTimer.Enabled = False
Me.tmrActionTimer.Interval = 1000
Me.tmrActionTimer.Enabled = True
Me.picTest3.Image = My.Resources.Edmonton_Oilers_2
Score += 1
Me.lblScore.Text = Score
Me.picTest3.Enabled = False
Call RandomNum(TargetCard)
End Sub
Private Sub picTest4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picTest4.Click
Me.tmrActionTimer.Enabled = False
Me.tmrActionTimer.Interval = 1000
Me.tmrActionTimer.Enabled = True
Me.picTest4.Image = My.Resources.Edmonton_Oilers_2
Score += 1
Me.lblScore.Text = Score
Me.picTest4.Enabled = False
Call RandomNum(TargetCard)
End Sub

Private Sub tmrActionTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrActionTimer.Tick
ActionTimer += 1
If ActionTimer = 1 Then
Me.picTest1.Image = My.Resources.Edmonton_Oilers_2
Me.picTest2.Image = My.Resources.Edmonton_Oilers_2
Me.picTest3.Image = My.Resources.Edmonton_Oilers_2
Me.picTest4.Image = My.Resources.Edmonton_Oilers_2
ActionTimer = 0
Call RandomNum(TargetCard)
End If
End Sub
End Class

Viewing all articles
Browse latest Browse all 27365

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>