Witam.
Mam 6 kwadratów które zmieniają losowo kolor czerwony/zielony
Potrzebuję funkcji która wykona się tylko wtedy gdy zielony będzie 1 z nich. oraz
Jeśli jest taka możliwość uproszczenie losowości timerów.
(Np tak żeby zmieścić to w 1 timerze nie 6)
Kod:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
LosPic_1.Start()
LosPic_2.Start()
LosPic_3.Start()
LosPic_4.Start()
LosPic_5.Start()
LosPic_6.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles LosPic_1.Tick
Dim ccc As Integer
Dim xxx As Color
ccc = CInt(Int((2 * Rnd()) + 1))
If ccc = 1 Then
xxx = Color.Lime
End If
If ccc = 2 Then
xxx = Color.Red
End If
PictureBox1.BackColor = xxx
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If PictureBox1.BackColor = Color.Lime And PictureBox2.BackColor = Color.Red And PictureBox3.BackColor = Color.Red Then
LosPic_1.Stop()
MsgBox("Zielony jest tylko 1!")
End If
If PictureBox1.BackColor = Color.Red And PictureBox2.BackColor = Color.Lime And PictureBox3.BackColor = Color.Red Then
LosPic_1.Stop()
MsgBox("Zielony jest tylko 1")
End If
If PictureBox1.BackColor = Color.Lime And PictureBox2.BackColor = Color.Red And PictureBox3.BackColor = Color.Lime Then
LosPic_1.Stop()
MsgBox("Zielony jest tylko 1")
End If
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles LosPic_2.Tick
Dim ccc As Integer
Dim xxx As Color
ccc = CInt(Int((2 * Rnd()) + 1))
If ccc = 1 Then
xxx = Color.Lime
End If
If ccc = 2 Then
xxx = Color.Red
End If
PictureBox2.BackColor = xxx
End Sub
Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles LosPic_3.Tick
Dim ccc As Integer
Dim xxx As Color
ccc = CInt(Int((2 * Rnd()) + 1))
If ccc = 1 Then
xxx = Color.Lime
End If
If ccc = 2 Then
xxx = Color.Red
End If
PictureBox3.BackColor = xxx
End Sub
Private Sub Timer4_Tick(sender As Object, e As EventArgs) Handles LosPic_4.Tick
Dim ccc As Integer
Dim xxx As Color
ccc = CInt(Int((2 * Rnd()) + 1))
If ccc = 1 Then
xxx = Color.Lime
End If
If ccc = 2 Then
xxx = Color.Red
End If
PictureBox4.BackColor = xxx
End Sub
Private Sub Timer5_Tick(sender As Object, e As EventArgs) Handles LosPic_5.Tick
Dim ccc As Integer
Dim xxx As Color
ccc = CInt(Int((2 * Rnd()) + 1))
If ccc = 1 Then
xxx = Color.Lime
End If
If ccc = 2 Then
xxx = Color.Red
End If
PictureBox5.BackColor = xxx
End Sub
Private Sub Timer6_Tick(sender As Object, e As EventArgs) Handles LosPic_6.Tick
Dim ccc As Integer
Dim xxx As Color
ccc = CInt(Int((2 * Rnd()) + 1))
If ccc = 1 Then
xxx = Color.Lime
End If
If ccc = 2 Then
xxx = Color.Red
End If
PictureBox6.BackColor = xxx
End Sub
End Class