Subscribe to sudokuking's Blog        RSS Feed
-----

Simon Says in Visual Basic

Icon Leave Comment
Hey every1. i'm making a game in visual basic, and i need ur help. th game is called SIMON SAYS.
This is the code i hav writted so far:

Public Class frmSSays
Public intscore As Integer = 0
Public intRounds As Integer = 0
Private intRandomSequence As Integer = 0
Private intPlayerSequence As Integer = 0
Public myNumberList1 As New ArrayList
Private myNumberList2 As New ArrayList
Private Sub frmSSays_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.BtnNext.Enabled = False
' ADD TO THE NUMBER LISTS
myNumberList1.Add(1)
myNumberList1.Add(2)
myNumberList1.Add(3)
myNumberList1.Add(4)
myNumberList2.Add(1)
myNumberList2.Add(2)
myNumberList2.Add(3)
myNumberList2.Add(4)
End Sub
Public Sub load_timer_event()
' DECLARE VARIABLES
Dim random As New Random(Now.Millisecond)
' START THE TIMER & DONT SHOW THE BUTTONS
Me.btnStart.Visible = False
Me.btnNext.Visible = False
Me.Timer1.Enabled = True
For i = 1 To 4
Select Case myNumberList1(random.Next(0, 4))
Case 1
Me.PanBlue.BackColor = Color.Navy
Me.Timer2.Enabled = True
Case 2
Me.PanGreen.BackColor = Color.ForestGreen
Me.Timer2.Enabled = True
Case 3
Me.PanRed.BackColor = Color.Red
Me.Timer2.Enabled = True
Case 4
Me.PanYellow.BackColor = Color.Yellow
Me.Timer2.Enabled = True
End Select
Select Case myNumberList2(random.Next(0, 4))
Case 1
If Me.PanBlue.BackColor = Color.Navy Then
Me.Timer2.Enabled = False
Me.PanBlue.BackColor = Color.CornflowerBlue
End If
Case 2
If Me.PanBlue.BackColor = Color.ForestGreen Then
Me.Timer2.Enabled = False
Me.PanGreen.BackColor = Color.PaleGreen
End If
Case 3
If Me.PanBlue.BackColor = Color.Red Then
Me.Timer2.Enabled = False
Me.PanRed.BackColor = Color.IndianRed
End If
Case 4
If Me.PanBlue.BackColor = Color.Yellow Then
Me.Timer2.Enabled = False
Me.PanYellow.BackColor = Color.LightYellow
End If
End Select
' STOP THE TIMER
Me.Timer1.Enabled = False
Next
End Sub
Private Sub panBlue_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PanBlue.MouseClick
If Me.Timer1.Enabled = False Then
' ADD TO THE SCORE IF CORRECT OR END THE GAME
intscore += 1
Me.LblScore.Text = "Score: " & intscore
Me.BtnNext.Visible = True
' SET UP FOR NEXT ROUND
If intscore > 0 Then
Me.BtnNext.Text = "Round " & intscore + 1
End If
End If
End Sub
Private Sub panRed_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PanRed.MouseClick
' ADD TO THE SCORE IF CORRECT OR END THE GAME
intScore += 1
Me.lblScore.Text = "Score: " & intScore
Me.btnNext.Visible = True
' SET UP FOR NEXT ROUND
If intScore > 0 Then
Me.btnNext.Text = "Round " & intScore + 1
End If
End Sub
Private Sub panGreen_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PanGreen.MouseClick
' ADD TO THE SCORE IF CORRECT OR END THE GAME
intScore += 1
Me.lblScore.Text = "Score: " & intScore
Me.btnNext.Visible = True
' SET UP FOR NEXT ROUND
If intScore > 0 Then
Me.btnNext.Text = "Round " & intScore + 1
End If
End Sub
Private Sub panYellow_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PanYellow.MouseClick
' ADD TO THE SCORE IF CORRECT OR END THE GAME
intScore += 1
Me.lblScore.Text = "Score: " & intScore
Me.btnNext.Visible = True
' SET UP FOR NEXT ROUND
If intScore > 0 Then
Me.btnNext.Text = "Round " & intScore + 1
End If
If intScore > 3 Then
Me.btnNext.Text = "Round " & (intScore - (Me.lblScore.Text / 2)) + 1
End If
End Sub
Private Sub btnNext_Click(sender As System.Object, e As System.EventArgs) Handles BtnNext.Click
load_timer_event()
End Sub
Private Sub change_background(ByRef control As Panel, ByVal color As Color)
control.BackColor = color
End Sub
Private Sub BtnStartSimonSays_Click(sender As System.Object, e As System.EventArgs) Handles BtnStart.Click
' DECLARE VARIABLES
Dim random As New Random(Now.Millisecond)
' START THE TIMER & DONT SHOW THE BUTTONS
Me.BtnStart.Visible = False
Me.BtnNext.Visible = False
Me.Timer1.Enabled = True
For i = 1 To 4
Select Case myNumberList1(random.Next(0, 4))
Case 1
Me.PanBlue.BackColor = Color.Navy
Me.Timer2.Enabled = True
Case 2
Me.PanGreen.BackColor = Color.ForestGreen
Me.Timer2.Enabled = True
Case 3
Me.PanRed.BackColor = Color.Red
Me.Timer2.Enabled = True
Case 4
Me.PanYellow.BackColor = Color.Yellow
Me.Timer2.Enabled = True
End Select
Select Case myNumberList2(random.Next(0, 4))
Case 1
If Me.PanBlue.BackColor = Color.Navy Then
Me.Timer2.Enabled = False
Me.PanBlue.BackColor = Color.CornflowerBlue
End If
Case 2
If Me.PanBlue.BackColor = Color.ForestGreen Then
Me.Timer2.Enabled = False
Me.PanGreen.BackColor = Color.PaleGreen
End If
Case 3
If Me.PanBlue.BackColor = Color.Red Then
Me.Timer2.Enabled = False
Me.PanRed.BackColor = Color.IndianRed
End If
Case 4
If Me.PanBlue.BackColor = Color.Yellow Then
Me.Timer2.Enabled = False
Me.PanYellow.BackColor = Color.LightYellow
End If
End Select
Next
' STOP THE TIMER
Me.Timer1.Enabled = False
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Dim intReturnedValue As Integer = -1
Dim random As New Random(Now.Millisecond)
' Return a random number from the array list/remove it
intReturnedValue = myNumberList1.Item(random.Next(0, myNumberList1.Count))
myNumberList1.Remove(intReturnedValue)
' Call a random number/change panel color
For i As Integer = 0 To 100
intRandomSequence += 1
Select Case intReturnedValue
Case 1
change_background(Me.PanGreen, Color.PaleGreen)
If Me.PanGreen.BackColor = Color.PaleGreen Then
Me.BtnNext.Enabled = True
End If
Case 2
change_background(Me.PanRed, Color.IndianRed)
If Me.PanRed.BackColor = Color.IndianRed Then
Me.Timer1.Enabled = False
Me.BtnNext.Enabled = True
End If
Case 3
change_background(Me.PanYellow, Color.LightYellow)
If Me.PanYellow.BackColor = Color.LightYellow Then
Me.Timer1.Enabled = False
Me.BtnNext.Enabled = True
End If
Case 4
change_background(Me.PanBlue, Color.CornflowerBlue)
If Me.PanBlue.BackColor = Color.CornflowerBlue Then
Me.Timer1.Enabled = False
Me.BtnNext.Enabled = True
End If
End Select
Me.Timer1.Enabled = False
Next
End Sub
End Class

0 Comments On This Entry

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

July 2014

S M T W T F S
  12345
6789101112
13141516171819
202122232425 26
2728293031  

Recent Entries

Search My Blog

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)