Konsep
Program PUZZLE
1. Deskripsi
Program yang kami
buat ini adalah program yang dibuat dengan cara permainnannya mengacak urutan
puzzle dan menyusunnya hingga tersusun seperti semula dengan maksimal 50
langkah.
2. Tujuan dan
Manfaat
Tujuan dari program
ini adalah memberi permainan yang bermanfaat untuk melatih otak kita untuk berpikir sistematis
dan logis
3. Sasaran
Sasaran dari program adalah untuk anak 10 tahun keatas
untuk melatih cara berpikir dan program
ini didesain dengan menampilkan gambar lawang sewu sebagai icon kota Semarang.
Langkah awal adalah buka dahulu
Visual Basic 2010 :
Form1 :
Komponen
Toolbox yang digunakan sebagai berikut :
No.
|
Komponen
|
Properties
|
Keterangan
|
1
|
Form1
|
Name
|
Form1
|
Text
|
Program
Puzzle Lawang Sewu
|
||
Background
|
Chartreuse
|
||
Display
|
CentertoScreen
|
||
2
|
Label1
|
Name
|
Label1
|
Text
|
Puzzle
Lawang Sewu
|
||
3
|
Label2
|
Name
|
Label2
|
Text
|
Kesempatan
|
||
25
|
Label3
|
Name
|
Label3
|
Text
|
50
|
||
26
|
Button1
|
Name
|
Button1
|
Text
|
1
|
||
27
|
Button2
|
Name
|
Button2
|
Text
|
2
|
||
28
|
Button3
|
Name
|
Button3
|
Text
|
3
|
||
26
|
Button14
|
Name
|
Button4
|
Text
|
4
|
||
27
|
Button5
|
Name
|
Button5
|
Text
|
5
|
||
28
|
Button6
|
Name
|
Button6
|
Text
|
6
|
||
26
|
Button7
|
Name
|
Button7
|
Text
|
7
|
||
27
|
Button8
|
Name
|
Button8
|
Text
|
8
|
||
28
|
Button9
|
Name
|
Button9
|
Text
|
9
|
||
26
|
Button10
|
Name
|
Button10
|
Text
|
Acak
|
||
27
|
Button11
|
Name
|
Button11
|
Text
|
Berhenti
|
||
28
|
Button12
|
Name
|
Button12
|
Text
|
Keluar
|
Listingnya :
Public Class Form1
Dim tuker As String
Dim pindah As Object
Dim acak As Integer
Private Sub Button1_Click(ByVal
sender As System.Object,
ByVal e As
(Baris 1
mendeklarasikan tuker sebagai string)
(Baris 2 mendeklarasikan pindah
sebagai objek)
(Baris 3 mendeklarasikan acak
sebagai integer)
System.EventArgs) Handles
Button1.Click
If
Button2.Text = "" Then
pindah = Button1.BackgroundImage
Button1.BackgroundImage =
Button2.BackgroundImage
Button2.BackgroundImage = pindah
tuker = Button1.Text
Button1.Text = Button2.Text
Button2.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf Button4.Text = ""
Then
pindah = Button1.BackgroundImage
Button1.BackgroundImage =
Button4.BackgroundImage
Button4.BackgroundImage = pindah
tuker = Button1.Text
Button1.Text = Button4.Text
Button4.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
benar()
End If
End Sub
(Membuat logika pemindahan dari
posisi 1 agar bisa pindah ke posisi 2 dan posisi 4)
(Jika langkah habis kalah)
(Jika sudah tersusun maka menang)
Private Sub Button2_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button2.Click
If
Button1.Text = "" Then
pindah = Button2.BackgroundImage
Button2.BackgroundImage =
Button1.BackgroundImage
Button1.BackgroundImage = pindah
tuker = Button2.Text
Button2.Text = Button1.Text
Button1.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button3.Text = "" Then
pindah = Button2.BackgroundImage
Button2.BackgroundImage =
Button3.BackgroundImage
Button3.BackgroundImage = pindah
tuker = Button2.Text
Button2.Text = Button3.Text
Button3.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button5.Text = "" Then
pindah = Button5.BackgroundImage
Button5.BackgroundImage =
Button2.BackgroundImage
Button2.BackgroundImage = pindah
tuker = Button5.Text
Button5.Text = Button2.Text
Button2.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
benar()
End If
End Sub
(Membuat logika pemindahan dari
posisi 2 agar bisa pindah ke posisi 3,1 dan 5)
(Jika langkah habis kalah)
(Jika sudah tersusun maka menang)
Private Sub Button3_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button3.Click
If
Button2.Text = "" Then
pindah = Button3.BackgroundImage
Button3.BackgroundImage =
Button2.BackgroundImage
Button2.BackgroundImage = pindah
tuker = Button3.Text
Button3.Text = Button2.Text
Button2.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button6.Text = "" Then
pindah = Button3.BackgroundImage
Button3.BackgroundImage =
Button6.BackgroundImage
Button6.BackgroundImage = pindah
tuker = Button3.Text
Button3.Text = Button6.Text
Button6.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
benar()
End If
End Sub
(Membuat logika pemindahan dari
posisi 3 agar bisa pindah ke posisi 2 dan 6)
(Jika langkah habis kalah)
(Jika sudah tersusun maka menang)
Private Sub Button4_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button4.Click
If
Button1.Text = "" Then
pindah = Button4.BackgroundImage
Button4.BackgroundImage =
Button1.BackgroundImage
Button1.BackgroundImage = pindah
tuker = Button4.Text
Button4.Text = Button1.Text
Button1.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button5.Text = "" Then
pindah = Button4.BackgroundImage
Button4.BackgroundImage =
Button5.BackgroundImage
Button5.BackgroundImage = pindah
tuker = Button4.Text
Button4.Text = Button5.Text
Button5.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button7.Text = "" Then
pindah = Button4.BackgroundImage
Button4.BackgroundImage =
Button7.BackgroundImage
Button7.BackgroundImage = pindah
tuker = Button4.Text
Button4.Text = Button7.Text
Button7.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
benar()
End If
End Sub
(Membuat logika pemindahan dari
posisi 4 agar bisa pindah ke posisi 1,5 dan 7)
(Jika langkah habis kalah)
(Jika sudah tersusun maka menang)
Private Sub Button5_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button5.Click
If
Button2.Text = "" Then
pindah = Button5.BackgroundImage
Button5.BackgroundImage =
Button2.BackgroundImage
Button2.BackgroundImage = pindah
tuker = Button5.Text
Button5.Text = Button2.Text
Button2.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button4.Text = "" Then
pindah = Button5.BackgroundImage
Button5.BackgroundImage =
Button4.BackgroundImage
Button4.BackgroundImage = pindah
tuker = Button5.Text
Button5.Text = Button4.Text
Button4.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button6.Text = "" Then
pindah = Button5.BackgroundImage
Button5.BackgroundImage =
Button6.BackgroundImage
Button6.BackgroundImage = pindah
tuker = Button5.Text
Button5.Text = Button6.Text
Button6.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button8.Text = "" Then
pindah = Button5.BackgroundImage
Button5.BackgroundImage =
Button8.BackgroundImage
Button8.BackgroundImage = pindah
tuker = Button5.Text
Button5.Text = Button8.Text
Button8.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
End If
If
Button2.Text = "" Then
tuker = Button5.Text
Button5.Text = Button2.Text
Button2.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button4.Text = "" Then
tuker = Button5.Text
Button5.Text = Button4.Text
Button4.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button6.Text = "" Then
tuker = Button5.Text
Button5.Text = Button6.Text
Button6.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button8.Text = "" Then
tuker = Button5.Text
Button5.Text = Button8.Text
Button8.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
benar()
End If
End Sub
(Membuat logika pemindahan dari
posisi 4 agar bisa pindah ke posisi 2,4,6 dan 8)
(Jika langkah habis kalah)
(Jika sudah tersusun maka menang)
Private Sub Button6_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button6.Click
If
Button3.Text = "" Then
pindah = Button6.BackgroundImage
Button6.BackgroundImage =
Button3.BackgroundImage
Button3.BackgroundImage = pindah
tuker = Button6.Text
Button6.Text = Button3.Text
Button3.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button5.Text = "" Then
pindah = Button6.BackgroundImage
Button6.BackgroundImage =
Button5.BackgroundImage
Button5.BackgroundImage = pindah
tuker = Button6.Text
Button6.Text = Button5.Text
Button5.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button9.Text = "" Then
pindah = Button6.BackgroundImage
Button6.BackgroundImage =
Button9.BackgroundImage
Button9.BackgroundImage = pindah
tuker = Button6.Text
Button6.Text = Button9.Text
Button9.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
benar()
End If
End Sub
(Membuat logika pemindahan dari
posisi 6 agar bisa pindah ke posisi 3,5 dan 9)
(Jika langkah habis kalah)
(Jika sudah tersusun maka menang)
Private Sub Button7_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button7.Click
If
Button4.Text = "" Then
pindah = Button7.BackgroundImage
Button7.BackgroundImage =
Button4.BackgroundImage
Button4.BackgroundImage = pindah
tuker = Button7.Text
Button7.Text = Button4.Text
Button4.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button8.Text = "" Then
pindah = Button7.BackgroundImage
Button7.BackgroundImage =
Button8.BackgroundImage
Button8.BackgroundImage = pindah
tuker = Button7.Text
Button7.Text = Button8.Text
Button8.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
benar()
End If
End Sub
(Membuat logika pemindahan dari
posisi 4 agar bisa pindah ke posisi 4 dan 8)
(Jika langkah habis kalah)
(Jika sudah tersusun maka menang)
Private Sub Button8_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button8.Click
If
Button5.Text = "" Then
pindah = Button8.BackgroundImage
Button8.BackgroundImage =
Button5.BackgroundImage
Button5.BackgroundImage = pindah
tuker = Button8.Text
Button8.Text = Button5.Text
Button5.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button7.Text = "" Then
pindah = Button8.BackgroundImage
Button8.BackgroundImage =
Button7.BackgroundImage
Button7.BackgroundImage = pindah
tuker = Button8.Text
Button8.Text = Button7.Text
Button7.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button9.Text = "" Then
pindah = Button8.BackgroundImage
Button8.BackgroundImage =
Button9.BackgroundImage
Button9.BackgroundImage = pindah
tuker = Button8.Text
Button8.Text = Button9.Text
Button9.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
benar()
End If
End Sub
(Membuat logika pemindahan dari
posisi 8 agar bisa pindah ke posisi 5,7 dan 9)
(Jika langkah habis kalah)
(Jika sudah tersusun maka menang)
Private Sub Button9_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button9.Click
If
Button6.Text = "" Then
pindah = Button9.BackgroundImage
Button9.BackgroundImage =
Button6.BackgroundImage
Button6.BackgroundImage = pindah
tuker = Button9.Text
Button9.Text = Button6.Text
Button6.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
ElseIf
Button8.Text = "" Then
pindah = Button9.BackgroundImage
Button9.BackgroundImage =
Button8.BackgroundImage
Button8.BackgroundImage = pindah
tuker = Button9.Text
Button9.Text = Button8.Text
Button8.Text = tuker
Label2.Text = Int(Label2.Text) - 1
If
Label2.Text = "0" Then
MsgBox("Game
Over")
Application.Restart()
End
If
benar()
End If
End Sub
(Membuat logika pemindahan dari
posisi 9 agar bisa pindah ke posisi 6 dan 8)
(Jika langkah habis kalah)
(Jika sudah tersusun maka menang)
Private Sub Clock_Tick(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Clock.Tick
pindah = Button9.BackgroundImage
Button9.BackgroundImage =
Button4.BackgroundImage
Button4.BackgroundImage = pindah
tuker = Button9.Text
Button9.Text = Button4.Text
Button4.Text = tuker
pindah = Button9.BackgroundImage
Button9.BackgroundImage =
Button3.BackgroundImage
Button3.BackgroundImage = pindah
tuker = Button9.Text
Button9.Text = Button3.Text
Button3.Text = tuker
pindah = Button2.BackgroundImage
Button2.BackgroundImage =
Button7.BackgroundImage
Button7.BackgroundImage = pindah
tuker = Button2.Text
Button2.Text = Button7.Text
Button7.Text = tuker
pindah = Button2.BackgroundImage
Button2.BackgroundImage = Button6.BackgroundImage
Button6.BackgroundImage = pindah
tuker = Button2.Text
Button2.Text = Button6.Text
Button6.Text = tuker
pindah = Button3.BackgroundImage
Button3.BackgroundImage =
Button8.BackgroundImage
Button8.BackgroundImage = pindah
tuker = Button3.Text
Button3.Text = Button8.Text
Button8.Text = tuker
pindah = Button3.BackgroundImage
Button3.BackgroundImage =
Button1.BackgroundImage
Button1.BackgroundImage = pindah
tuker = Button3.Text
Button3.Text = Button1.Text
Button1.Text = tuker
pindah = Button5.BackgroundImage
Button5.BackgroundImage =
Button8.BackgroundImage
Button8.BackgroundImage = pindah
tuker = Button5.Text
Button5.Text = Button8.Text
Button8.Text = tuker
pindah = Button5.BackgroundImage
Button5.BackgroundImage = Button7.BackgroundImage
Button7.BackgroundImage = pindah
tuker = Button5.Text
Button5.Text = Button7.Text
Button7.Text = tuker
pindah = Button6.BackgroundImage
Button6.BackgroundImage =
Button1.BackgroundImage
Button1.BackgroundImage = pindah
tuker = Button6.Text
Button6.Text = Button1.Text
Button1.Text = tuker
End Sub
(Posisi mengacak puzzle dengan
memindahkan button dengan sistem timer)
Private Sub Button10_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button10.Click
Clock.Enabled = True
acak = Rnd() * 10
End Sub
(Membuat puzzle mengacak)
Private Sub Button11_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button11.Click
Clock.Enabled = False
End Sub
(Membuat puzzle berhenti mengacak)
Private Sub Button12_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button12.Click
Me.Close()
End Sub
(Menclose Program)
Private Sub Form1_Load(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
MyBase.Load
Me.Text
= "Program Puzzle Lawan Sewu"
Me.CenterToScreen()
End Sub
Private Sub benar()
If
(Button1.Text = "1" And Button2.Text = "2"
And Button3.Text = "3"
And Button4.Text = "4"
And Button5.Text = "5"
And Button6.Text = "6"
And Button7.Text = "7"
And Button8.Text = "8"
And Button9.Text = "")
Then
MsgBox("Anda
Telah Menyelesaikan Puzzle Dengan Baik!", 0, "SELAMAT!")
End If
End Sub
(Membuat
kondisi dimana kalau semua puzzle sudah tersusun sesuai urutan maka akan keluar messagebox “Anda Telah
Menyelesaikan Puzzle Dengan Baik!”)
End Class