Jurnal Puzzle

Jumat, 07 Desember 2012


Tutorial Membuat Game Puzzle Sederhana

Visual Basic merupakan bahasa pemrograman yang dapat digunakan untuk membuat suatu program sederhana. Berikut adalah contoh langkah-langkah penggunaan visual basic 2010 dalam membuat Game Puzzle Sederhana
Langkah-Langkah:
1.      Membuka Aplikasi Visual Basic 2010












2.      Klik  Windows Form Application

            Untuk memunculkan form seperti berikut 
                

           
3.      Klik  menu bar-view-other windows-tollbox untuk memunculkan toolbox yang akan digunakan

           4.      Membuat  Form seperti di bawah ini dengan menggunakan komponen toolbox di atas

Berikut adalah komponen ToolBox yang digunakan dalam Form kasino ini
NO
KOMPONEN
PROPERTIES
KETERANGAN
1
Form 1
Name

Text
Form 1
2
Label1
Name
Text
Label1
Urutkan Dari terkecil atau terbesar
3
Button1
Name
Text
Button1
4
Button2
Name
Text
Button2
5
Button3
Name
Text
Button3
6
Button4
Name
Text
Button4
7
Button5
Name
Text
Button5
8
Button6
Name
Text
Button6
9
Button7
Name
Text
Button7
10
Button8
Name
Text
Button
11
Button9
Name
Text
Button9
12
Form2
Name
Text
Form2
13
Label1
Name
Text
Label1
SELAMAT ANDA MENANG
14
Button1
Name
Text
Button1
Keluar
15
Button2
Name
Text
Button2
Main lagi




















Agar program berjalan, buatlah listing sebagai berikut:
1.    Double click pada design Form1










2. Memunculkan angka acak pada slot
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim control As Windows.Forms.Control
        For Each control In Me.Controls
            If control.GetType.Name = "Button" Then
                Dim rndnumber As Random
                Dim number As Integer
                rndnumber = New Random
                number = rndnumber.Next(1, 9)
                control.Text = number
If Button2.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button2.Text = number
                    Loop Until Button2.Text <> Button1.Text
                End If

                If Button3.Text = Button2.Text Or Button3.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button3.Text = number
                    Loop Until Button3.Text <> Button2.Text And Button3.Text <> Button1.Text
                End If

                If Button4.Text = Button3.Text Or Button4.Text = Button2.Text Or Button4.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button4.Text = number
                    Loop Until Button4.Text <> Button3.Text And Button4.Text <> Button2.Text And Button4.Text <> Button1.Text
                End If

                If Button4.Text = Button3.Text Or Button4.Text = Button2.Text Or Button4.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button4.Text = number
                    Loop Until Button4.Text <> Button3.Text And Button4.Text <> Button2.Text And Button4.Text <> Button1.Text
                End If

                If Button5.Text = Button4.Text Or Button5.Text = Button3.Text Or Button5.Text = Button2.Text Or Button5.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button5.Text = number
                    Loop Until Button5.Text <> Button4.Text And Button5.Text <> Button3.Text And Button5.Text <> Button2.Text And Button5.Text <> Button1.Text
                End If

                If Button6.Text = Button5.Text Or Button6.Text = Button4.Text Or Button6.Text = Button3.Text Or Button6.Text = Button2.Text Or Button6.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button6.Text = number
                    Loop Until Button6.Text <> Button5.Text And Button6.Text <> Button3.Text And Button6.Text <> Button2.Text And Button6.Text <> Button1.Text
                End If

                If Button7.Text = Button6.Text Or Button7.Text = Button5.Text Or Button7.Text = Button4.Text Or Button7.Text = Button3.Text Or Button7.Text = Button2.Text Or Button7.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button7.Text = number
                    Loop Until Button7.Text <> Button6.Text And Button7.Text <> Button5.Text And Button7.Text <> Button4.Text And Button7.Text <> Button3.Text And Button7.Text <> Button2.Text And Button7.Text <> Button1.Text
                End If

                If Button8.Text = Button7.Text Or Button8.Text = Button6.Text Or Button8.Text = Button5.Text Or Button8.Text = Button4.Text Or Button8.Text = Button3.Text Or Button8.Text = Button2.Text Or Button8.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button8.Text = number
                    Loop Until Button8.Text <> Button7.Text And Button8.Text <> Button6.Text And Button8.Text <> Button5.Text And Button8.Text <> Button4.Text And Button8.Text <> Button3.Text And Button8.Text <> Button2.Text And Button8.Text <> Button1.Text
                End If
            End If
            Button9.Text = ""
        Next

    End Sub


3.  Membuat setiap slot dapat berpindah ke slot yang kosong
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Button2.Text = "" Then
            Button2.Text = Button1.Text
            Button1.Text = ""
        ElseIf Button4.Text = "" Then
            Button4.Text = Button1.Text
            Button1.Text = ""
        End If
        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
            Form2.Show()
        End If
        If Button1.Text = "8" And Button2.Text = "7" And Button3.Text = "6" And Button4.Text = "5" And Button5.Text = "4" And Button6.Text = "3" And Button7.Text = "2" And Button8.Text = "1" And Button9.Text = "" Then
            Form2.Show()
        End If

    End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Button1.Text = "" Then
            Button1.Text = Button2.Text
            Button2.Text = ""
        ElseIf Button3.Text = "" Then
            Button3.Text = Button2.Text
            Button2.Text = ""
        ElseIf Button5.Text = "" Then
            Button5.Text = Button2.Text
            Button2.Text = ""
        End If
        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
            Form2.Show()
        End If
        If Button1.Text = "8" And Button2.Text = "7" And Button3.Text = "6" And Button4.Text = "5" And Button5.Text = "4" And Button6.Text = "3" And Button7.Text = "2" And Button8.Text = "1" And Button9.Text = "" Then
            Form2.Show()
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Button2.Text = "" Then
            Button2.Text = Button3.Text
            Button3.Text = ""
        ElseIf Button6.Text = "" Then
            Button6.Text = Button3.Text
            Button3.Text = ""
        End If
        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
            Form2.Show()
        End If
        If Button1.Text = "8" And Button2.Text = "7" And Button3.Text = "6" And Button4.Text = "5" And Button5.Text = "4" And Button6.Text = "3" And Button7.Text = "2" And Button8.Text = "1" And Button9.Text = "" Then
            Form2.Show()
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button1.Text = "" Then
            Button1.Text = Button4.Text
            Button4.Text = ""
        ElseIf Button5.Text = "" Then
            Button5.Text = Button4.Text
            Button4.Text = ""
        ElseIf Button7.Text = "" Then
            Button7.Text = Button4.Text
            Button4.Text = ""
        End If
        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
            Form2.Show()
        End If
        If Button1.Text = "8" And Button2.Text = "7" And Button3.Text = "6" And Button4.Text = "5" And Button5.Text = "4" And Button6.Text = "3" And Button7.Text = "2" And Button8.Text = "1" And Button9.Text = "" Then
            Form2.Show()
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If Button2.Text = "" Then
            Button2.Text = Button5.Text
            Button5.Text = ""
        ElseIf Button4.Text = "" Then
            Button4.Text = Button5.Text
            Button5.Text = ""
        ElseIf Button6.Text = "" Then
            Button6.Text = Button5.Text
            Button5.Text = ""
        ElseIf Button8.Text = "" Then
            Button8.Text = Button5.Text
            Button5.Text = ""
        End If
        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
            Form2.Show()
        End If
        If Button1.Text = "8" And Button2.Text = "7" And Button3.Text = "6" And Button4.Text = "5" And Button5.Text = "4" And Button6.Text = "3" And Button7.Text = "2" And Button8.Text = "1" And Button9.Text = "" Then
            Form2.Show()
        End If
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If Button9.Text = "" Then
            Button9.Text = Button6.Text
            Button6.Text = ""
        ElseIf Button3.Text = "" Then
            Button3.Text = Button6.Text
            Button6.Text = ""
        ElseIf Button5.Text = "" Then
            Button5.Text = Button6.Text
            Button6.Text = ""
        End If
        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
            Form2.Show()
        End If
        If Button1.Text = "8" And Button2.Text = "7" And Button3.Text = "6" And Button4.Text = "5" And Button5.Text = "4" And Button6.Text = "3" And Button7.Text = "2" And Button8.Text = "1" And Button9.Text = "" Then
            Form2.Show()
        End If
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If Button4.Text = "" Then
            Button4.Text = Button7.Text
            Button7.Text = ""
        ElseIf Button8.Text = "" Then
            Button8.Text = Button7.Text
            Button7.Text = ""
        End If
        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
            Form2.Show()
        End If
        If Button1.Text = "8" And Button2.Text = "7" And Button3.Text = "6" And Button4.Text = "5" And Button5.Text = "4" And Button6.Text = "3" And Button7.Text = "2" And Button8.Text = "1" And Button9.Text = "" Then
            Form2.Show()
        End If
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If Button7.Text = "" Then
            Button7.Text = Button8.Text
            Button8.Text = ""
        ElseIf Button9.Text = "" Then
            Button9.Text = Button8.Text
            Button8.Text = ""
        ElseIf Button5.Text = "" Then
            Button5.Text = Button8.Text
            Button8.Text = ""
        End If
        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
            Form2.Show()
        End If
        If Button1.Text = "8" And Button2.Text = "7" And Button3.Text = "6" And Button4.Text = "5" And Button5.Text = "4" And Button6.Text = "3" And Button7.Text = "2" And Button8.Text = "1" And Button9.Text = "" Then
            Form2.Show()
        End If
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If Button6.Text = "" Then
            Button6.Text = Button9.Text
            Button9.Text = ""
        ElseIf Button8.Text = "" Then
            Button8.Text = Button9.Text
            Button9.Text = ""
        End If
        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
            Form2.Show()
        End If
        If Button1.Text = "8" And Button2.Text = "7" And Button3.Text = "6" And Button4.Text = "5" And Button5.Text = "4" And Button6.Text = "3" And Button7.Text = "2" And Button8.Text = "1" And Button9.Text = "" Then
            Form2.Show()
        End If
    End Sub

    Private Sub Button9_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click

    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

5.    Double klik pada design form2


6.    Membuat Button1 sebagai tombol keluar dari game ini

Public Class Form2
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
        Form1.Close()
    End Sub

7.    Membuat Button2 sebagai  tombol untuk kembali memulai permainan

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Form1.Show()
        Dim control As Windows.Forms.Control
        For Each control In Form1.Controls
            If control.GetType.Name = "Button" Then
                Dim rndnumber As Random
                Dim number As Integer
                rndnumber = New Random
                number = rndnumber.Next(1, 9)
                control.Text = number

                If Form1.Button2.Text = Form1.Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Form1.Button2.Text = number
                    Loop Until Form1.Button2.Text <> Form1.Button1.Text
                End If

                If Form1.Button3.Text = Form1.Button2.Text Or Form1.Button3.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Form1.Button3.Text = number
                    Loop Until Form1.Button3.Text <> Form1.Button2.Text And Form1.Button3.Text <> Form1.Button1.Text
                End If

                If Form1.Button4.Text = Form1.Button3.Text Or Form1.Button4.Text = Form1.Button2.Text Or Form1.Button4.Text = Form1.Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Form1.Button4.Text = number
                    Loop Until Form1.Button4.Text <> Form1.Button3.Text And Form1.Button4.Text <> Form1.Button2.Text And Form1.Button4.Text <> Form1.Button1.Text
                End If

                If Form1.Button5.Text = Form1.Button4.Text Or Form1.Button5.Text = Form1.Button3.Text Or Form1.Button5.Text = Form1.Button2.Text Or Form1.Button5.Text = Form1.Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Form1.Button5.Text = number
                    Loop Until Form1.Button5.Text <> Form1.Button4.Text And Form1.Button5.Text <> Form1.Button3.Text And Form1.Button5.Text <> Form1.Button2.Text And Form1.Button5.Text <> Form1.Button1.Text
                End If

                If Form1.Button6.Text = Form1.Button5.Text Or Form1.Button6.Text = Form1.Button4.Text Or Form1.Button6.Text = Form1.Button3.Text Or Form1.Button6.Text = Form1.Button2.Text Or Form1.Button6.Text = Form1.Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Form1.Button6.Text = number
                    Loop Until Form1.Button6.Text <> Form1.Button5.Text And Form1.Button6.Text <> Form1.Button4.Text And Form1.Button6.Text <> Form1.Button3.Text And Form1.Button6.Text <> Form1.Button2.Text And Form1.Button6.Text <> Form1.Button1.Text
                End If

                If Form1.Button7.Text = Form1.Button6.Text Or Form1.Button7.Text = Form1.Button5.Text Or Form1.Button7.Text = Form1.Button4.Text Or Form1.Button7.Text = Form1.Button3.Text Or Form1.Button7.Text = Form1.Button2.Text Or Form1.Button7.Text = Form1.Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Form1.Button7.Text = number
                    Loop Until Form1.Button7.Text <> Form1.Button6.Text And Form1.Button7.Text <> Form1.Button5.Text And Form1.Button7.Text <> Form1.Button4.Text And Form1.Button7.Text <> Form1.Button3.Text And Form1.Button7.Text <> Form1.Button2.Text And Form1.Button7.Text <> Form1.Button1.Text
                End If

                If Form1.Button8.Text = Form1.Button7.Text Or Form1.Button8.Text = Form1.Button6.Text Or Form1.Button8.Text = Form1.Button5.Text Or Form1.Button8.Text = Form1.Button4.Text Or Form1.Button8.Text = Form1.Button3.Text Or Form1.Button8.Text = Form1.Button2.Text Or Form1.Button8.Text = Form1.Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Form1.Button8.Text = number
                    Loop Until Form1.Button8.Text <> Form1.Button7.Text And Form1.Button8.Text <> Form1.Button6.Text And Form1.Button8.Text <> Form1.Button5.Text And Form1.Button8.Text <> Form1.Button4.Text And Form1.Button8.Text <> Form1.Button3.Text And Form1.Button8.Text <> Form1.Button2.Text And Form1.Button8.Text <> Form1.Button1.Text
                End If
            End If
            Form1.Button9.Text = ""
        Next
        Me.Close()

    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub
End Class





Konsep Program Game Puzzle Sederhana

Deskripsi
Program ini dibuat dengan total 2 form. Form1 sebagai game puzzle itu sendiri. Dan Form2 sebagai penutup yang berisi pilihan untuk melanjutkan game kembali atau keluar dari game. Permainannya cukup mudah. Anda disilakan untuk menyusun angka secara berurutan dengan susunan zigzag dari angka 1 sampai angka 8 baik dengan posisi angka 1 di atas maupun di bawah. Cara menyusunnya pun cukup dengan meng-klik slot suatu angka ke slot yang kosong. Begitu seterusnya hingga dihasilkan susunan angka 1-8 yang berurutan.
Tujuan
Tujuan dibuatnya program game puzzle ini adalah sebagai latihan dan pengajaran untuk membuat game sederhana yaitu puzzle.
Manfaat
Manfaat dari pembuatan game puzzle sederhana ini tentu sebagaimana dengan game pada umumnya adalah sebagai hiburan dan dapat melatih Anda untuk membuat strategi.
Sasaran user
Game puzzle sederhana ini dapat digunakan oleh semua kalangan. Terutama anak-anak dan remaja



0 komentar: