TI 2012

TI 2012

Friday, 7 December 2012

Program Puzzle Gambar

Program Puzzle Gambar dapat di download di link berikut:
http://www.4shared.com/rar/0ruQTl5m/Program_Puzzle_Angka.html

Flowchart Program Puzzle Gambar

atau bisa di download di link ini : http://www.4shared.com/office/BXRKEYh5/Flowchart_Program_Puzzle_Gamba.html

Tutorial dan Analisis Program Puzzle Gambar




TUTORIAL DAN ANALISIS PROGRAM PUZZLE GAMBAR

Untuk membuat program puzzle gambar, maka langkah-langkah yang harus dilakukan adalah sebagai berikut :



1. Buka Program Microsoft Visual Basic 2010, klik New Project untuk memulai membuat program.







2.  Klik Windows Forms Application untuk membuat Form Baru.



3.  Buatlah Form dengan interface seperti dibawah ini untuk membuat home page.







4. Masukkan Listing Berikut.

Public Class Form3

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

Keterangan:
Baris 1 berfungsi untuk menutup Form 3
Me adalah nama yang diberikan untuk Form 3

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form1.Show()
        Me.Hide()
    End Sub

Keterangan:
Baris 1 untuk membuka Form 1
Baris 2 untuk menyembunyikan Form 3
Me adalah nama yang diberikan untuk Form 3

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox1.Text = ""
    End Sub

Keterangan:
Baris 1 berfungsi untuk me-refresh TextBox1

End Class

5. Buatlah Form baru dengan mengklik tombol Add New Item pada toolbar, lalu pilih Windows Form.








6. Buatlah interface seperti gambar dibawah ini:






7. Masukkan listing code sebagai berikut:

Public Class Form1

    Dim Pindah As Object
    Dim Tukar As String
    Dim Acak As Integer

Keterangan:
Pindah, Tukar, Acak berfungsi sebagai variabel sementara
Baris 1 mendeklarasikan variabel “Pindah” sebagai Object
Baris 2 mendeklarasikan variabel “Tukar” sebagai String
Baris 3 mendeklarasikan variabel “Acak” sebagai Integer


    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        Timer1.Enabled = True
        Acak = Rnd() * 10

Keterangan :
Listing code diatas berfungsi untuk mengacak angka dan gambar pada button menggunakan random and timer. Random dan timer disini saling berhubungan, berfungsi untuk mengacak dengan cepat.

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Pindah = Button9.BackgroundImage
        Button9.BackgroundImage = Button4.BackgroundImage
        Button4.BackgroundImage = Pindah
        Tukar = Button9.Text
        Button9.Text = Button4.Text
        Button4.Text = Tukar

        Pindah = Button9.BackgroundImage
        Button9.BackgroundImage = Button3.BackgroundImage
        Button3.BackgroundImage = Pindah
        Tukar = Button9.Text
        Button9.Text = Button3.Text
        Button3.Text = Tukar

        Pindah = Button2.BackgroundImage
        Button2.BackgroundImage = Button7.BackgroundImage
        Button7.BackgroundImage = Pindah
        Tukar = Button2.Text
        Button2.Text = Button7.Text
        Button7.Text = Tukar

        Pindah = Button2.BackgroundImage
        Button2.BackgroundImage = Button6.BackgroundImage
        Button6.BackgroundImage = Pindah
        Tukar = Button2.Text
        Button2.Text = Button6.Text
        Button6.Text = Tukar

        Pindah = Button3.BackgroundImage
        Button3.BackgroundImage = Button8.BackgroundImage
        Button8.BackgroundImage = Pindah
        Tukar = Button3.Text
        Button3.Text = Button8.Text
        Button8.Text = Tukar

        Pindah = Button3.BackgroundImage
        Button3.BackgroundImage = Button1.BackgroundImage
        Button1.BackgroundImage = Pindah
        Tukar = Button3.Text
        Button3.Text = Button1.Text
        Button1.Text = Tukar

        Pindah = Button5.BackgroundImage
        Button5.BackgroundImage = Button8.BackgroundImage
        Button8.BackgroundImage = Pindah
        Tukar = Button5.Text
        Button5.Text = Button8.Text
        Button8.Text = Tukar

        Pindah = Button5.BackgroundImage
        Button5.BackgroundImage = Button7.BackgroundImage
        Button7.BackgroundImage = Pindah
        Tukar = Button5.Text
        Button5.Text = Button7.Text
        Button7.Text = Tukar

        Pindah = Button6.BackgroundImage
        Button6.BackgroundImage = Button1.BackgroundImage
        Button1.BackgroundImage = Pindah
        Tukar = Button6.Text
        Button6.Text = Button1.Text
        Button1.Text = Tukar
        benar()

Keterangan :
Listing code diatas berfungsi agar ketika timer berjalan, angka-angka dan gambar pada button juga dapat teracak.

    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        Timer1.Enabled = False

Keterangan :
Baris 1 adalah listing code yang digunakan untuk menghentikan acakan angka-angka dan gambar-gambar. Diberikan pada tombol “Stop”.

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Button2.Text = "" Then
            Pindah = Button1.BackgroundImage
            Button1.BackgroundImage = Button2.BackgroundImage
            Button2.BackgroundImage = Pindah
            Tukar = Button1.Text
            Button1.Text = Button2.Text
            Button2.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button4.Text = "" Then
            Pindah = Button1.BackgroundImage
            Button1.BackgroundImage = Button4.BackgroundImage
            Button4.BackgroundImage = Pindah
            Tukar = Button1.Text
            Button1.Text = Button4.Text
            Button4.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        End If
        benar()
    End Sub

    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
            Tukar = Button2.Text
            Button2.Text = Button1.Text
            Button1.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button3.Text = "" Then
            pindah = Button2.BackgroundImage
            Button2.BackgroundImage = Button3.BackgroundImage
            Button3.BackgroundImage = pindah
            Tukar = Button2.Text
            Button2.Text = Button3.Text
            Button3.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button5.Text = "" Then
            pindah = Button5.BackgroundImage
            Button5.BackgroundImage = Button2.BackgroundImage
            Button2.BackgroundImage = pindah
            Tukar = Button5.Text
            Button5.Text = Button2.Text
            Button2.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        End If
        benar()
    End Sub


    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
            Tukar = Button3.Text
            Button3.Text = Button2.Text
            Button2.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button6.Text = "" Then
            pindah = Button3.BackgroundImage
            Button3.BackgroundImage = Button6.BackgroundImage
            Button6.BackgroundImage = pindah
            Tukar = Button3.Text
            Button3.Text = Button6.Text
            Button6.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        End If
        benar()
    End Sub

    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
            Tukar = Button4.Text
            Button4.Text = Button1.Text
            Button1.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button5.Text = "" Then
            pindah = Button4.BackgroundImage
            Button4.BackgroundImage = Button5.BackgroundImage
            Button5.BackgroundImage = pindah
            Tukar = Button4.Text
            Button4.Text = Button5.Text
            Button5.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button7.Text = "" Then
            pindah = Button4.BackgroundImage
            Button4.BackgroundImage = Button7.BackgroundImage
            Button7.BackgroundImage = pindah
            Tukar = Button4.Text
            Button4.Text = Button7.Text
            Button7.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        End If
        benar()
    End Sub

    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
            Tukar = Button5.Text
            Button5.Text = Button2.Text
            Button2.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button4.Text = "" Then
            pindah = Button5.BackgroundImage
            Button5.BackgroundImage = Button4.BackgroundImage
            Button4.BackgroundImage = pindah
            Tukar = Button5.Text
            Button5.Text = Button4.Text
            Button4.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button6.Text = "" Then
            pindah = Button5.BackgroundImage
            Button5.BackgroundImage = Button6.BackgroundImage
            Button6.BackgroundImage = pindah
            Tukar = Button5.Text
            Button5.Text = Button6.Text
            Button6.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button8.Text = "" Then
            pindah = Button5.BackgroundImage
            Button5.BackgroundImage = Button8.BackgroundImage
            Button8.BackgroundImage = pindah
            Tukar = Button5.Text
            Button5.Text = Button8.Text
            Button8.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        End If
        If Button2.Text = "" Then
            Tukar = Button5.Text
            Button5.Text = Button2.Text
            Button2.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button4.Text = "" Then
            Tukar = Button5.Text
            Button5.Text = Button4.Text
            Button4.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button6.Text = "" Then
            Tukar = Button5.Text
            Button5.Text = Button6.Text
            Button6.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button8.Text = "" Then
            Tukar = Button5.Text
            Button5.Text = Button8.Text
            Button8.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        End If
        benar()
    End Sub


    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
            Tukar = Button6.Text
            Button6.Text = Button3.Text
            Button3.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button5.Text = "" Then
            pindah = Button6.BackgroundImage
            Button6.BackgroundImage = Button5.BackgroundImage
            Button5.BackgroundImage = pindah
            Tukar = Button6.Text
            Button6.Text = Button5.Text
            Button5.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button9.Text = "" Then
            pindah = Button6.BackgroundImage
            Button6.BackgroundImage = Button9.BackgroundImage
            Button9.BackgroundImage = pindah
            Tukar = Button6.Text
            Button6.Text = Button9.Text
            Button9.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        End If
        benar()
    End Sub

    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
            Tukar = Button7.Text
            Button7.Text = Button4.Text
            Button4.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
          
        ElseIf Button8.Text = "" Then
            pindah = Button7.BackgroundImage
            Button7.BackgroundImage = Button8.BackgroundImage
            Button8.BackgroundImage = pindah
            Tukar = Button7.Text
            Button7.Text = Button8.Text
            Button8.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        End If
        benar()
    End Sub

    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
            Tukar = Button8.Text
            Button8.Text = Button5.Text
            Button5.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button7.Text = "" Then
            pindah = Button8.BackgroundImage
            Button8.BackgroundImage = Button7.BackgroundImage
            Button7.BackgroundImage = pindah
            Tukar = Button8.Text
            Button8.Text = Button7.Text
            Button7.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button9.Text = "" Then
            pindah = Button8.BackgroundImage
            Button8.BackgroundImage = Button9.BackgroundImage
            Button9.BackgroundImage = pindah
            Tukar = Button8.Text
            Button8.Text = Button9.Text
            Button9.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        End If
        benar()
    End Sub

    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
            Tukar = Button9.Text
            Button9.Text = Button6.Text
            Button6.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        ElseIf Button8.Text = "" Then
            pindah = Button9.BackgroundImage
            Button9.BackgroundImage = Button8.BackgroundImage
            Button8.BackgroundImage = pindah
            Tukar = Button9.Text
            Button9.Text = Button8.Text
            Button8.Text = Tukar
            Label3.Text = Int(Label3.Text) + 1
        End If
        benar()

Keterangan :
Listing code diatas adalah inti dari permainan puzzlenya, dimana tombol gambar yang ada di dekat tombol kosong berpindah ke tombol kosong dengan cara di klik. Ketika seluruh gambar telah tersusun dengan benar, maka akan muncul pesan bahwa anda telah berhasil menyelesaikan puzzle tersebut. Untuk memindahkan tombol gambar tersebut kita menggunakan logika if karena pilihannya lebih dari satu. Misalnya jika tombol gambar 1 yang kosong maka akan ada dua pilihan tombol gambar yang bisa ditukar yaitu tombol gambar 2 dan tombol gambar 4.

    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 = "" And Label3.Text > 0) Then
            If MsgBox("Congratulations! Do You Want To Try Again?", MsgBoxStyle.YesNoCancel, "43's Puzzle") = Windows.Forms.DialogResult.Yes Then
                Form3.Show()
                Label3.Text = "0"
            ElseIf Windows.Forms.DialogResult.Cancel Then
                Me.Show()

            Else
                Form3.Show()
                Me.Hide()
            End If
        End If

Keterangan :
Listing code diatas akan memunculkan messagebox ketika puzzle sudah terselesaikan dengan benar. Messagebox akan menampilkan pesan “Congratulations! Do You Want To Try Again?” lalu akan ada 3 tombol opsi, Yes untuk mengulang kembali permainan, No untuk keluar dari permainan, dan Cancel untuk kembali ke Form permainan terakhir.

    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        Me.Close()

Keterangan :
Baris 1 berfungsi untuk menutup program.

    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        Form2.Show()
        Me.Hide()
    End Sub

Keterangan :
Baris 1 berfungsi untuk membuka form “Hint!” atau gambar Puzzle secara utuh
Baris 2 berfungsi untuk menutup Form 1
Me adalah nama yang diberikan untuk Form 1

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        Form4.Show()
        Dim Name As String = Form3.TextBox1.Text
        Dim Movement As Integer = Label3.Text

        Form4.DataGridView1.Rows.Add(Name, Movement)

Keterangan:
Baris 1 untuk membuka Form “High Score”
Baris 2 mendeklarasikan nilai variabel Name yang ada ada Textbox1 Form 3 sebagai String
Baris 3 mendeklarasikan nilai variabel Movement pada Label3 Form 2 sebagai Integer
Baris 4 adalah listing code untuk menambahkan data pada tabel yang telah disediakan

    End Sub

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        Form3.Show()
        Me.Close()

Keterangan:
Baris 1 untuk membuka kembali Form 3
Baris 2 untuk menutup Form 1
Me adalah nama yang diberikan untuk Form 1

    End Sub
End Class


8. Buat kembali Form baru, dan buatlah dengan interface seperti dibawah ini:






9. Masukkan listing code sebagai berikut:

Public Class Form2

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form1.Show()
        Me.Hide()
    End Sub

Keterangan :
Baris 1 berfungsi untuk membuka Form 1
Baris 2 berfungsi untuk menyembunyikan Form 2
Me adalah nama yang diberikan untuk Form 2

End Class

2.      Buat kembali form baru, dengan interface sebagai berikut



10. Masukkan listing code sebagai berikut:
Public Class Form4

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        Form1.Show()
        Me.Close()
    End Sub

Keterangan :
Baris 1 berfungsi untuk membuka Form 1
Baris 2 berfungsi untuk menutup Form 4
Me adalah nama yang diberikan untuk Form 4
   
End Class

Untuk Lebih Jelasnya, silahkan download tutorial secara lengkap di link berikut ini : http://www.4shared.com/office/ShZI9B3q/Tutorial_dan_Analisis_Program_.html