Tutorial
membuat slot machine
Kami akan menjelaskan bagaimana cara membuat slot
machine, berikut adalah cara cara membuat slot machine beserta listingnya.
1. buka terlebih dahulu
visual basic 2010
2. lalu buatlah form1,
dengan komponen seperti gambar dibawah ini
Dengan toolbox
no
|
Komponen
|
properties
|
1
|
label1
|
text = welcome to
|
2
|
label2
|
text = Slot Machine Games
|
3
|
picture box1
|
-
|
4
|
button1
|
text = angka
|
5
|
button2
|
text = gambar
|
6
|
button3
|
text = go home
|
7
|
timer1
|
-
|
Lalu untuk listing
form1 bisa dilihat dibawah ini
Public Class Form1
Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Form5.Show()
Me.Hide()
Form5.TextBox1.Text = ""
End Sub
Private Sub
Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
Form4.Show()
Me.Hide()
Form4.TextBox1.Text = ""
End Sub
Private Sub
Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
MsgBox("Bye Bye!")
Close()
End Sub
End Class
(penjelasan untuk
listing form1 = jika button1 di klik maka form5 akan muncul dan textbox1 pada
form 5 akan kosong. Jika button2 di klik maka form4 akan muncul dan textbox1
pda form 4 akan kosong. Jika button 3 di klik maka akan muncul msgbox(bye bye)
dan akan tertutup)
3. lalu untuk langkah
ketiga buat form 2 dengan toolbox dan properties seperti gambar dibawah ini.
Dan berikut adalah
keterangan dari komponen yang dipakai.
No
|
komponen
|
Properties
|
1
|
label1
|
text = "1"
|
2
|
label2
|
text = "2"
|
3
|
label3
|
text = "3"
|
4
|
label4
|
text = "bet"
|
5
|
label5
|
text = "money"
|
6
|
label7
|
text = "label"
|
7
|
label8
|
text = "mau main lagi?"
|
8
|
label9
|
text = "kamu menang!!!
|
9
|
button1
|
text = "back"
|
10
|
button2
|
text = "ya"
|
11
|
button3
|
text = "tidak"
|
12
|
textbox1
|
text = ""
|
13
|
textbox2
|
text = ""
|
14
|
picturebox1
|
text = ""
|
15
|
picturebox2
|
text = ""
|
16
|
timer1
|
-
|
Dan untuk listing bisa
anda ikuti seperti dibawah ini.
Public Class Form2
Dim itung, x1, x2, x3 As
Integer
Dim spin As
System.Media.SoundPlayer = New System.Media.SoundPlayer(WindowsApplication1.My.Resources.Spin)
Dim but As
System.Media.SoundPlayer = New System.Media.SoundPlayer(WindowsApplication1.My.Resources.CLICK)
Dim sp As
System.Media.SoundPlayer = New System.Media.SoundPlayer(WindowsApplication1.My.Resources.Tada)
Dim bonk As System.Media.SoundPlayer = New
System.Media.SoundPlayer(WindowsApplication1.My.Resources.BONK)
Friend Shared
picture6 As String
(penjelasan = dim itu artinya dipermisalkan,
dimisalkan itung,x1,x2,x3 integer. Dan spin as system.media.soundplayer = new
itu artinya sebagai efect suara pada visual basic.)
Private Sub
Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
but.Play()
Form1.Show()
Me.Hide()
End Sub
(penjelasan = jika button 3 di klik maka suara yang
sudah dimasukan akan keluar. Form1 muncul.)
Private Sub
PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
PictureBox2.Click
Timer1.Enabled = False
spin.Stop()
itung
= 0
If Label1.Text = Label2.Text Or
Label2.Text = Label3.Text Or Label1.Text =
Label3.Text Then
Label6.Hide()
Label7.Show()
Label7.Text = "Selamat Kamu Dapat
" & Val(TextBox2.Text)
TextBox1.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
sp.Play()
ElseIf Label1.Text = 7 And
Label2.Text = 7 And Label3.Text = 7 Then
Label7.Hide()
Label6.Show()
Label6.Text = "BINGO!!!"
TextBox1.Text = Val(TextBox1.Text) + 1000
sp.Play()
Else
Label7.Hide()
Label6.Show()
Label6.Text = "Coba Lagi!!!"
TextBox1.Text = Val(TextBox1.Text) - Val(TextBox2.Text)
bonk.Play()
End If
PictureBox1.Show()
PictureBox2.Hide()
End Sub
(penjelasan = timer itu digunakan untuk mengacak
akan terstop. Jika terdapat if lalu then maka itu tersebut persyaratan agar
program tersebut dapat jalan. Dan val digunakan untuk mengubah menjadi bilangan
numerik)
Private Sub
Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
TextBox1.Text = Form5.TextBox1.Text
TextBox2.Text = "100"
PictureBox3.Hide()
Me.BackColor = Color.White
Label1.Text = "0"
Label2.Text = "0"
Label3.Text = "0"
Label1.Show()
Label2.Show()
Label3.Show()
Label4.Show()
Label5.Show()
Label8.Hide()
Label9.Hide()
Button13.Hide()
Button14.Hide()
PictureBox1.Show()
PictureBox2.Hide()
TextBox1.Show()
TextBox2.Show()
Button3.Show()
End Sub
Private Sub
PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
PictureBox1.Click
If Val(TextBox1.Text) <= 10000 Then
Timer1.Enabled = True
Label7.Hide()
Label6.Hide()
PictureBox1.Hide()
PictureBox2.Show()
spin.Play()
ElseIf Val(TextBox2.Text) > Val(TextBox1.Text) Or Val(TextBox1.Text <= 0) Then
MsgBox("Your money is not enough")
MsgBox("Game Over!", 0, "Game Over")
bonk.Play()
Dim testMsg As String
testMsg = MsgBox("Try Again?",
vbYesNo + vbQuestion, "Try Again?")
If testMsg = vbNo Then
Form6.Show()
Me.Hide()
ElseIf testMsg = vbYes Then
Form5.Show()
Me.Hide()
Form4.TextBox1.Text = ""
TextBox1.Text = Form4.TextBox1.Text
TextBox2.Text = "100"
End If
End If
End Sub
(penjelasan = jika terdapat val maka diubah menjadi
bentuk numerik. Jika textbox2 lebih besar dari texbox1 atau textbox1 lebih
kecil sama dengan 0 maka akan muncul msgbox seperti yang diatas. Terdapat
testmsg untuk pertanyaan try again yes no. Jika jawaban no maka form6 akan
muncul jika yes maka form5 akan muncul form4.textbox1.text = “” dan
textbox1.text akan sama. Sedangkan textbox2.text = “100”)
Private Sub
Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Timer1.Tick
If itung < 1000 Then
Label1.Text = Int(Rnd() * 10)
Label2.Text = Int(Rnd() * 10)
Label3.Text = Int(Rnd() * 10)
End If
End Sub
(penjelasan = jika itung lebih kecil dari 1000 maka
label1.text = int sebagai bil bulat rnd akan berputar antara 0 – 10)
Private Sub
TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged
If Val(TextBox1.Text) > 10000 Then
sp.Play()
PictureBox3.Show()
PictureBox3.Image = My.Resources.Fire
Me.BackColor = Color.Black
Label1.Hide()
Label2.Hide()
Label3.Hide()
Label4.Hide()
Label5.Hide()
Label6.Hide()
Label7.Hide()
Label8.Show()
Label9.Show()
Button13.Show()
Button14.Show()
PictureBox1.Hide()
PictureBox2.Hide()
TextBox1.Hide()
TextBox2.Hide()
Button3.Hide()
End If
End Sub
Private Sub
Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button14.Click
Form5.TextBox1.Text = ""
Form5.Show()
Me.Hide()
End Sub
Private Sub
Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button13.Click
Form1.Close()
End Sub
End Class
4. lalu setelah buat
form2 maka buatlah form3 seperti komponen yang ada digambar ini
Lalu buatlah toolbox
beserta komponen seperti dibawah ini.
no
|
komponen
|
Properties
|
1
|
label1
|
text = money
|
2
|
label2
|
text = jackpot
|
3
|
label3
|
text =bet
|
4
|
label4
|
text = selamat kamu menang!!!
|
5
|
label5
|
text = mau main lagi?
|
6
|
button1
|
text = back
|
7
|
button2
|
text = ya
|
8
|
button3
|
text = tidak
|
9
|
textbox1
|
text = ""
|
10
|
textbox2
|
text = ""
|
11
|
picturebox1
|
-
|
12
|
picturebox2
|
-
|
13
|
picturebox3
|
-
|
14
|
picturebox4
|
-
|
15
|
picturebox5
|
-
|
16
|
timer1
|
-
|
17
|
imagelist1
|
-
|
Dan berikut ini
merupakan listing dari form3
Public Class Form3
Dim m, n1, n2, n3 As Integer
Dim spin As
System.Media.SoundPlayer = New System.Media.SoundPlayer(WindowsApplication1.My.Resources.Spin)
Dim but As
System.Media.SoundPlayer = New System.Media.SoundPlayer(WindowsApplication1.My.Resources.CLICK)
Dim sp As
System.Media.SoundPlayer = New System.Media.SoundPlayer(WindowsApplication1.My.Resources.Tada)
Dim bonk As
System.Media.SoundPlayer = New System.Media.SoundPlayer(WindowsApplication1.My.Resources.BONK)
Private Sub
Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Timer1.Tick
m = m
+ 1 ( m lebih kecil dari 1000 dan m
sebelumnya sma dengan m ditambah 1)
If m < 1000 Then
n1 = Int(1 + Rnd() * 5) (n1 sma dgn int 1 ditambah rnd untuk
mengacak sampai dengan
5)
n2 = Int(1 + Rnd() * 5)
n3 = Int(1 + Rnd() * 5)
Select Case n1
Case 1
PictureBox1.Image = ImageList1.Images.Item(1)
Case 2
PictureBox1.Image = ImageList1.Images.Item(2)
Case 3
PictureBox1.Image = ImageList1.Images.Item(3)
Case 4
PictureBox1.Image = ImageList1.Images.Item(4)
Case 5
PictureBox1.Image = ImageList1.Images.Item(5)
Case 6
PictureBox1.Image = ImageList1.Images.Item(6)
End Select
Select Case n2
Case 1
PictureBox2.Image = ImageList1.Images.Item(1)
Case 2
PictureBox2.Image = ImageList1.Images.Item(2)
Case 3
PictureBox2.Image = ImageList1.Images.Item(3)
Case 4
PictureBox2.Image = ImageList1.Images.Item(4)
Case 5
PictureBox2.Image = ImageList1.Images.Item(5)
Case 6
PictureBox2.Image = ImageList1.Images.Item(6)
End Select
Select Case n3
Case 1
PictureBox3.Image = ImageList1.Images.Item(1)
Case 2
PictureBox3.Image = ImageList1.Images.Item(2)
Case 3
PictureBox3.Image =
ImageList1.Images.Item(3)
Case 4
PictureBox3.Image = ImageList1.Images.Item(4)
Case 5
PictureBox3.Image = ImageList1.Images.Item(5)
Case 6
PictureBox3.Image = ImageList1.Images.Item(6)
End Select
End If
End Sub
Private Sub
Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
but.Play()
Form1.Show()
Me.Hide()
End Sub
( penjelasan bahwa jika button 3 di klik maka akan
muncul suara.)
Private Sub
PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
PictureBox5.Click
Timer1.Enabled = False
spin.Stop() (jika picturebox5 di klik maka timer1 akan
berhenti)
m = 0
If n1 = n2 Or n2 = n3
Or n1 = n3 Then
Label1.Show()
Label1.Text = "CONGRATS!!!"
TextBox1.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
sp.Play()
Else
Label1.Show()
Label1.Text = "No Luck!"
TextBox1.Text = Val(TextBox1.Text) - Val(TextBox2.Text)
bonk.Play()
End If
PictureBox5.Hide()
PictureBox4.Show()
End Sub
Private Sub
PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
PictureBox4.Click
If Val(TextBox2.Text) > Val(TextBox1.Text) Or Val(TextBox1.Text <= 0) Then
MsgBox("Your money is not enough")
MsgBox("Game Over!", 0, "Game Over")
bonk.Play()
Dim testMsg As String
testMsg = MsgBox("Try Again?",
vbYesNo + vbQuestion, "Try Again?")
If testMsg = vbNo Then
Form6.Show()
Me.Hide()
ElseIf testMsg = vbYes Then
TextBox1.Text = Form4.TextBox1.Text
TextBox2.Text = "100"
End If
Else
Label1.Hide()
spin.Play()
PictureBox4.Hide()
PictureBox5.Show()
Timer1.Enabled = True
End If
End Sub
Private Sub
Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
TextBox1.Text = Form4.TextBox1.Text
TextBox2.Text = "100"
PictureBox6.Hide()
Me.BackColor = Color.White
Label1.Hide()
Label2.Show()
Label3.Show()
Label8.Hide()
Label9.Hide()
Button13.Hide()
Button14.Hide()
PictureBox1.Show()
PictureBox2.Show()
PictureBox3.Show()
PictureBox4.Show()
PictureBox5.Hide()
TextBox1.Show()
TextBox2.Show()
Button3.Show()
End Sub
Private Sub
TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged ( jika textbox1 lebih besar dari 10000 maka akan muncul
suara dan picturebox6 dan seperti yang ada dibawah ini)
If
Val(TextBox1.Text) > 10000 Then
sp.Play()
PictureBox6.Show()
PictureBox6.Image = My.Resources.Fire
Me.BackColor = Color.Black
Label1.Hide()
Label2.Hide()
Label3.Hide()
Label8.Show()
Label9.Show()
Button13.Show()
Button14.Show()
PictureBox1.Hide()
PictureBox2.Hide()
PictureBox3.Hide()
PictureBox4.Hide()
PictureBox5.Hide()
TextBox1.Hide()
TextBox2.Hide()
Button3.Hide()
End If
End Sub
Private Sub
Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button14.Click
Form4.TextBox1.Text = ""
Form4.Show()
Me.Hide()
End Sub
Private Sub
Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button13.Click
Form1.Close()
End Sub
End Class
5 lalu setelah buat
form3 lanjut ke form4 seperti gambar yang ada dibawah ini.
Lalu berikut adalah
komponen yang digunakan
no
|
komponen
|
Properties
|
1
|
label1
|
text = masukan uang
|
2
|
label2
|
text = kamu
|
3
|
textbox1
|
text = ""
|
4
|
button1
|
text =mulai
|
Dan berikut ini
merupakan listingnya
Public Class Form4
Private Sub
TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim key As Integer = Char.ConvertToUtf32(e.KeyChar.Tostring(),
0)
If Not (((key >=
48) And (key <= 57)) Or (key = 8) Or (key = 46) Or (key = 45)) Then
e.Handled = True
End If
End Sub
Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
If Val(TextBox1.Text) > 10000 Then
MsgBox("Uang maksimal 10000")
TextBox1.Text = "0"
Else
Form3.TextBox1.Text = TextBox1.Text
Form3.TextBox2.Text = "0"
Form3.Show()
Me.Hide()
End If
End Sub
End Class
6. lalu untuk langkah
selanjutnya buat form 5 ikuti langkah seperti gambar dibawah ini.
Dan berikut ini adalah
komponen komponen yang digunakan dalam form 5.
No
|
komponen
|
properties
|
1
|
label1
|
text = masukan uang
|
2
|
label2
|
text = kamu
|
3
|
textbox1
|
text = ""
|
4
|
button1
|
text = mulai
|
Setelah masukan
komponen masukan listing berikut ini.
Public Class Form5
Private Sub
TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim key As Integer = Char.ConvertToUtf32(e.KeyChar.Tostring(),
0)
If Not (((key >=
48) And (key <= 57)) Or (key = 8) Or (key = 46) Or (key = 45)) Then
e.Handled = True
End If
End Sub
Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
If Val(TextBox1.Text) > "10000"
Then
MsgBox("Uang maksimal 10000")
Else
Form2.TextBox1.Text = Val(TextBox1.Text)
Form2.TextBox2.Text = ""
Form2.Show()
Me.Hide()
End If
End Sub
Private Sub
Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
TextBox1.Text = ""
End Sub
End Class
7. lalu terakhir adalah buat form6 dan buat
komponen seperti gambar dibawah ini.
Dan berikut adalah
informasi dari komponen yang ada
no
|
komponen
|
properties
|
1
|
label1
|
text = you lose
|
2
|
button1
|
text = try again
|
3
|
button2
|
text = exit
|
Setelah itu masukan
listing dibawah berikut
Public Class Form6
Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Form1.Show()
Me.Hide()
End Sub
Private Sub
Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
Form1.Close()
End Sub
End Class
8. setelah itu klik
slot machine yang berada di solution explorer lalu pilih application. Pilih
start up form: Form1. Yaitu untuk memulai pada saat debug form1 yang
dimunculkan
Tidak ada komentar:
Posting Komentar