Alur programmnya seperti ini :
Kita akan membuat sebuah permainan angka yang bernama Lucky Seven. Dimana kita memilih angka antara 0-9 yang berada di Option, lalu kita menekan tombol spin dan 3 label start itu akan berputar beberapa detik dan menampilkan 3 bilangan acak. Jika 3 bilangan acak itu sama dengan Option yang kita pilih maka Wins akan bertambah 1. Begitu seterusnya. Jika kita ingin berhenti klik tombol End. Di program ini saya memakai prosedur dan function, jadi jangan bingung ya.....
Properties/toolbox yang digunakan :
1.Button
2.Label
3.ComboBox
4.PictureBox
5.Timer
Saya asumsikan :
1.Spin = Button1
2.End = Button3
3.Wins = Label6
4.Option =Combobox1
5.Start Merah =Label3
6.Start Hijau = Label4
7.Start Biru = Label5
8.Lucky... = Label2
Tampilan Awal
Codingnya :
Public Class Form1
Dim waso As New Random
Dim win As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
optionbox()
End Sub
Sub optionbox()
For i As Integer = 0 To 9
ComboBox1.Items.Add(i)
Next
End Sub
Sub Lucky()
If ComboBox1.SelectedItem = 1 Then
Label2.Text = "Lucky One"
ElseIf ComboBox1.SelectedItem = 2 Then
Label2.Text = "Lucky Two"
ElseIf ComboBox1.SelectedItem = 3 Then
Label2.Text = "Lucky Three"
ElseIf ComboBox1.SelectedItem = 4 Then
Label2.Text = "Lucky Four"
ElseIf ComboBox1.SelectedItem = 5 Then
Label2.Text = "Lucky Five"
ElseIf ComboBox1.SelectedItem = 6 Then
Label2.Text = "Lucky Six"
ElseIf ComboBox1.SelectedItem = 7 Then
Label2.Text = "Lucky Seven"
ElseIf ComboBox1.SelectedItem = 8 Then
Label2.Text = "Lucky Eight"
ElseIf ComboBox1.SelectedItem = 9 Then
Label2.Text = "Lucky Nine"
ElseIf ComboBox1.SelectedItem = 0 Then
Label2.Text = "Lucky Zero"
End If
End Sub
Function Spind() As Integer
Timer1.Enabled = True
Label3.Text = 1
Label4.Text = 2
Label5.Text = 3
If ComboBox1.SelectedItem = CInt(Label3.Text) And ComboBox1.SelectedItem = CInt(Label4.Text) And ComboBox1.SelectedItem = CInt(Label5.Text) Then
MessageBox.Show("Selamat Anda Menang", "GAME")
win += 1
Label6.Text = "wins : " & win
End If
End Function
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Lucky()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
iyos = 0
Timer1.Enabled = True
Spind()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox("TERIMA KASIH")
Me.Close()
End Sub
Dim iyos As Integer = 0
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label3.Text = waso.Next(0, 10)
Label4.Text = waso.Next(0, 10)
Label5.Text = waso.Next(0, 10)
Dim batas As Boolean = True
iyos += 1
If iyos = 50 Then
batas = False
If batas = False Then
Timer1.Enabled = False
End If
End If
End Sub
End Class
Public Class Form1
Dim waso As New Random
Dim win As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
optionbox()
End Sub
Sub optionbox()
For i As Integer = 0 To 9
ComboBox1.Items.Add(i)
Next
End Sub
Sub Lucky()
If ComboBox1.SelectedItem = 1 Then
Label2.Text = "Lucky One"
ElseIf ComboBox1.SelectedItem = 2 Then
Label2.Text = "Lucky Two"
ElseIf ComboBox1.SelectedItem = 3 Then
Label2.Text = "Lucky Three"
ElseIf ComboBox1.SelectedItem = 4 Then
Label2.Text = "Lucky Four"
ElseIf ComboBox1.SelectedItem = 5 Then
Label2.Text = "Lucky Five"
ElseIf ComboBox1.SelectedItem = 6 Then
Label2.Text = "Lucky Six"
ElseIf ComboBox1.SelectedItem = 7 Then
Label2.Text = "Lucky Seven"
ElseIf ComboBox1.SelectedItem = 8 Then
Label2.Text = "Lucky Eight"
ElseIf ComboBox1.SelectedItem = 9 Then
Label2.Text = "Lucky Nine"
ElseIf ComboBox1.SelectedItem = 0 Then
Label2.Text = "Lucky Zero"
End If
End Sub
Function Spind() As Integer
Timer1.Enabled = True
Label3.Text = 1
Label4.Text = 2
Label5.Text = 3
If ComboBox1.SelectedItem = CInt(Label3.Text) And ComboBox1.SelectedItem = CInt(Label4.Text) And ComboBox1.SelectedItem = CInt(Label5.Text) Then
MessageBox.Show("Selamat Anda Menang", "GAME")
win += 1
Label6.Text = "wins : " & win
End If
End Function
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Lucky()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
iyos = 0
Timer1.Enabled = True
Spind()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox("TERIMA KASIH")
Me.Close()
End Sub
Dim iyos As Integer = 0
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label3.Text = waso.Next(0, 10)
Label4.Text = waso.Next(0, 10)
Label5.Text = waso.Next(0, 10)
Dim batas As Boolean = True
iyos += 1
If iyos = 50 Then
batas = False
If batas = False Then
Timer1.Enabled = False
End If
End If
End Sub
End Class
Setelah Dijalankan
Saya akan mencoba menambahkan satu Button Stop untuk menghentikan putaran angka, jadi putaran angka tidak berhenti otomatis, seperti di bawah ini :
Kita hanya perlu menghapus beberapa bagian coding di even timer1_Tick yang ada tanda petik satu(tetapi bila di vb berwarna hijau).
Dim iyos As Integer = 0
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label3.Text = waso.Next(0, 10)
Label4.Text = waso.Next(0, 10)
Label5.Text = waso.Next(0, 10)
'Dim batas As Boolean = True
'iyos += 1
'If iyos = 50 Then
'batas = False
'If batas = False Then
'Timer1.Enabled = False
'End If
'End If
End sub
Lalu buatlah sebuah even Button Click, disini saya memakai Button3_Click, dan tuliskan codingnya seperti ini :
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Timer1.Enabled = False
End Sub
Cukup mudah bukan????? Memang masih banyak kekurangan dalam codingan ini, jadi kalian bisa mencoba merubah-rubah dan menambah ataupun mengurangi codingannya. Selamat mencoba....
Tunggu Edisi Berikutnya.....