PUZZLE
Puzzle merupakan game yang sering bahkan setiap orang bisa memainkannya. Dengan menggunakan logika untuk menyusun suatu gambar, angka bahkan kata-kata. Kali ini saya akan membuat puzzle dengan Logika yang mungkin biasa digunakan dalam permainan yakni, Menyusun Angka yang teracak dan acakan angka yang tidak selalu sama.
Adapun ketentuan dalam pembuatan Game PUZZLE ini, ketentuannya sebagai berikut :
1. Saat form dijalankan posisi angka acak.
2. Saat tombol ditekan yang terletak di dekat tombol kosong maka tombol tersebut akan menempati tombol kosong, begitu seterusnya sampai dengan angkanya tersusun dari 1 sampai 8.
3. Saat angka sudah tersusun tampilkan pesan selamat anda berhasil.
# Langkah – Langkah dalam Pembuatan Puzzle
Berikutnya adalah pembuatan game dengan menyusun “Common Controls” yang dibutuhkan untuk mendukung game ini. Tampilan awal untuk Game Puzzle dapat dilihat dibawah ini.
Adapun ketentuan dalam pembuatan Game PUZZLE ini, ketentuannya sebagai berikut :
1. Saat form dijalankan posisi angka acak.
2. Saat tombol ditekan yang terletak di dekat tombol kosong maka tombol tersebut akan menempati tombol kosong, begitu seterusnya sampai dengan angkanya tersusun dari 1 sampai 8.
3. Saat angka sudah tersusun tampilkan pesan selamat anda berhasil.
# Langkah – Langkah dalam Pembuatan Puzzle
Berikutnya adalah pembuatan game dengan menyusun “Common Controls” yang dibutuhkan untuk mendukung game ini. Tampilan awal untuk Game Puzzle dapat dilihat dibawah ini.
# Ketikan Listing Ini Pada Form1
Public Class Form1
Dim acak As String
Dim warna As Color
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
bt1.Enabled = False
bt2.Enabled = False
bt3.Enabled = False
bt4.Enabled = False
bt5.Enabled = False
bt6.Enabled = False
bt7.Enabled = False
bt8.Enabled = False
bt9.Enabled = False
btstopacak.Enabled = False
End Sub
1. Saat Form Dijalankan Posisi Angka Acak
Dalam pengacakan angka dapat menggunakan Random maupun dengan Perulangan. Untuk Pengacakan itu sendiri saya Menggunakan Timer atau waktu untuk mengulang acakan angka tersebut sehingga angka yang dihasilkan tidak sama.
Private Sub btacakangka_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btacakangka.Click
Timer1.Enabled = True
bt1.Enabled = True
bt2.Enabled = True
bt3.Enabled = True
bt4.Enabled = True
bt5.Enabled = True
bt6.Enabled = True
bt7.Enabled = True
bt8.Enabled = True
bt9.Enabled = True
btstop.Enabled = True
btacakangka.Enabled = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim pindah As String
'1
pindah = bt9.Text
bt9.Text = bt6.Text
bt6.Text = bt3.Text
bt3.Text = pindah
warna = bt9.BackColor
bt9.BackColor = bt6.BackColor
bt6.BackColor = bt3.BackColor
bt3.BackColor = warna
'2
pindah = bt8.Text
bt8.Text = bt5.Text
bt5.Text = bt2.Text
bt2.Text = pindah
warna = bt8.BackColor
bt8.BackColor = bt5.BackColor
bt5.BackColor = bt2.BackColor
bt2.BackColor = warna
'3
pindah = bt7.Text
bt7.Text = bt8.Text
bt8.Text = bt9.Text
bt9.Text = pindah
warna = bt7.BackColor
bt7.BackColor = bt8.BackColor
bt8.BackColor = bt9.BackColor
bt9.BackColor = warna
'4
pindah = bt4.Text
bt4.Text = bt5.Text
bt5.Text = bt6.Text
bt6.Text = pindah
warna = bt4.BackColor
bt4.BackColor = bt5.BackColor
bt5.BackColor = bt6.BackColor
bt6.BackColor = warna
'5
pindah = bt7.Text
bt7.Text = bt4.Text
bt4.Text = bt1.Text
bt1.Text = pindah
warna = bt7.BackColor
bt7.BackColor = bt4.BackColor
bt4.BackColor = bt1.BackColor
bt1.BackColor = warna
End Sub
2. Mengaktifkan Button STOP ACAK
Private Sub btstopacak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btstopacak.Click
btacakangka.Enabled = False
Timer1.Enabled = False
btstopacak.Enabled = True
End Sub
Sehingga angka menjadi acak, seperti yang terlihat dibawah ini :
Saat tombol ditekan yang terletak di dekat tombol kosong maka tombol tersebut akan menempati tombol kosong, begitu seterusnya sampai dengan angkanya tersusun dari 1 sampai 8.
# Ketikan listing pada masing-masing button dari 1 sampai 9.
Private Sub bt1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt1.Click
If bt4.Text = "" Then
acak = bt1.Text
bt1.Text = bt4.Text
bt4.Text = acak
warna = bt1.BackColor
bt1.BackColor = bt4.BackColor
bt4.BackColor = warna
ElseIf bt2.Text = "" Then
acak = bt1.Text
bt1.Text = bt2.Text
bt2.Text = acak
warna = bt1.BackColor
bt1.BackColor = bt2.BackColor
bt2.BackColor = warna
End If
End Sub
Private Sub bt2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt2.Click
If bt1.Text = "" Then
acak = bt2.Text
bt2.Text = bt1.Text
bt1.Text = acak
warna = bt2.BackColor
bt2.BackColor = bt1.BackColor
bt1.BackColor = warna
ElseIf bt5.Text = "" Then
acak = bt2.Text
bt2.Text = bt5.Text
bt5.Text = acak
warna = bt2.BackColor
bt2.BackColor = bt5.BackColor
bt5.BackColor = warna
ElseIf bt3.Text = "" Then
acak = bt2.Text
bt2.Text = bt3.Text
bt3.Text = acak
warna = bt2.BackColor
bt2.BackColor = bt3.BackColor
bt3.BackColor = warna
End If
End Sub
Private Sub bt3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt3.Click
If bt2.Text = "" Then
acak = bt3.Text
bt3.Text = bt2.Text
bt2.Text = acak
warna = bt3.BackColor
bt3.BackColor = bt2.BackColor
bt2.BackColor = warna
ElseIf bt6.Text = "" Then
acak = bt3.Text
bt3.Text = bt6.Text
bt6.Text = acak
warna = bt3.BackColor
bt3.BackColor = bt6.BackColor
bt6.BackColor = warna
End If
End Sub
Private Sub bt4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt4.Click
If bt7.Text = "" Then
acak = bt4.Text
bt4.Text = bt7.Text
bt7.Text = acak
warna = bt4.BackColor
bt4.BackColor = bt7.BackColor
bt7.BackColor = warna
ElseIf bt5.Text = "" Then
acak = bt4.Text
bt4.Text = bt5.Text
bt5.Text = acak
warna = bt4.BackColor
bt4.BackColor = bt5.BackColor
bt5.BackColor = warna
ElseIf bt1.Text = "" Then
acak = bt4.Text
bt4.Text = bt1.Text
bt1.Text = acak
warna = bt4.BackColor
bt4.BackColor = bt1.BackColor
bt1.BackColor = warna
End If
End Sub
Private Sub bt5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt5.Click
If bt8.Text = "" Then
acak = bt5.Text
bt5.Text = bt8.Text
bt8.Text = acak
warna = bt5.BackColor
bt5.BackColor = bt8.BackColor
bt8.BackColor = warna
ElseIf bt6.Text = "" Then
acak = bt5.Text
bt5.Text = bt6.Text
bt6.Text = acak
warna = bt5.BackColor
bt5.BackColor = bt6.BackColor
bt6.BackColor = warna
ElseIf bt4.Text = "" Then
acak = bt5.Text
bt5.Text = bt4.Text
bt4.Text = acak
warna = bt5.BackColor
bt5.BackColor = bt4.BackColor
bt4.BackColor = warna
ElseIf bt2.Text = "" Then
acak = bt5.Text
bt5.Text = bt2.Text
bt2.Text = acak
warna = bt5.BackColor
bt5.BackColor = bt2.BackColor
bt2.BackColor = warna
End If
End Sub
Private Sub bt6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt6.Click
If bt9.Text = "" Then
acak = bt6.Text
bt6.Text = bt9.Text
bt9.Text = acak
warna = bt6.BackColor
bt6.BackColor = bt9.BackColor
bt9.BackColor = warna
ElseIf bt5.Text = "" Then
acak = bt6.Text
bt6.Text = bt5.Text
bt5.Text = acak
warna = bt6.BackColor
bt6.BackColor = bt5.BackColor
bt5.BackColor = warna
ElseIf bt3.Text = "" Then
acak = bt6.Text
bt6.Text = bt3.Text
bt3.Text = acak
warna = bt6.BackColor
bt6.BackColor = bt3.BackColor
bt3.BackColor = warna
End If
End Sub
Private Sub bt7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt7.Click
If bt8.Text = "" Then
acak = bt7.Text
bt7.Text = bt8.Text
bt8.Text = acak
warna = bt7.BackColor
bt7.BackColor = bt8.BackColor
bt8.BackColor = warna
ElseIf bt4.Text = "" Then
acak = bt7.Text
bt7.Text = bt4.Text
bt4.Text = acak
warna = bt7.BackColor
bt7.BackColor = bt4.BackColor
bt4.BackColor = warna
End If
End Sub
Private Sub bt8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt8.Click
If bt9.Text = "" Then
acak = bt8.Text
bt8.Text = bt9.Text
bt9.Text = acak
warna = bt8.BackColor
bt8.BackColor = bt9.BackColor
bt9.BackColor = warna
ElseIf bt7.Text = "" Then
acak = bt8.Text
bt8.Text = bt7.Text
bt7.Text = acak
warna = bt8.BackColor
bt8.BackColor = bt7.BackColor
bt7.BackColor = warna
ElseIf bt5.Text = "" Then
acak = bt8.Text
bt8.Text = bt5.Text
bt5.Text = acak
warna = bt8.BackColor
bt8.BackColor = bt5.BackColor
bt5.BackColor = warna
End If
End Sub
Private Sub bt9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt9.Click
If bt8.Text = "" Then
acak = bt9.Text
bt9.Text = bt8.Text
bt8.Text = acak
warna = bt9.BackColor
bt9.BackColor = bt8.BackColor
bt8.BackColor = warna
ElseIf bt6.Text = "" Then
acak = bt9.Text
bt9.Text = bt6.Text
bt6.Text = acak
warna = bt9.BackColor
bt9.BackColor = bt6.BackColor
bt6.BackColor = warna
End If
If (bt1.Text = "1" And bt2.Text = "2" And bt3.Text = "3" And bt4.Text = "4" And bt5.Text = "5" And bt6.Text = "6" And bt7.Text = "7" And bt8.Text = "8" And bt9.Text = "") Then
MsgBox("Selamat Anda BERHASIL", vbInformation + vbOKOnly, "Puzzle")
Timer1.Enabled = False
End If
End Sub
3. Saat angka sudah tersusun tampilkan pesan selamat anda berhasil.
Pesan akan muncul ketika Anda telah menyelesaikan misi dari game puzzle ini. Misinya adalah mengurutkan angka yang acak menjadi seperti semula. Dengan catatan angkan berurut menurut letak awal.
Pesan yang muncul akan tampak pada keluaran dibawah ini :
Sebagai tambahan saat keluar dari game Anda akan dimintai Konfirmasi atau persetujuan untuk keluar atau menghentikan game ini.
Dengan pesan “ Anda Yakin Unttuk menghentikan Game ini?” jika Yes, game akan keluar atau tertutup dari aplikasi. Sedangkan untuk No, game tetap tampil seperti semula.
Dengan pesan “ Anda Yakin Unttuk menghentikan Game ini?” jika Yes, game akan keluar atau tertutup dari aplikasi. Sedangkan untuk No, game tetap tampil seperti semula.
Dengan Listing dibawah ini Anda dapat melihat pesan Konfirmasi.
Private Sub btexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btexit.Click
If MsgBox("Anda Yakin Untuk Menghentikan GAME ini ?", vbYesNo +
vbQuestion) = vbYes Then
vbQuestion) = vbYes Then
End
End If
End Sub
demikian hasil saya,, semoga bermanfaat...
terimakasih... ^_^
0 comments:
Post a Comment