Senin, 10 Desember 2012

Modul 3 Aplikasi Game Puzzle

Aplikasi Game Puzzle


1. TUJUAN
   Membuat salah satu game puzzle
2. MANFAAT
    Menghilangkan penat
3. SASARAN
    Masyarakat umum 
4. Flowchart

Public Class Form1
    Dim smt As Object
    Dim stp As String
    Dim acak As Integer
    Dim stpWatch As New System.Diagnostics.Stopwatch

Keterangan:
Deklarasi baris pertama Smt(sementara)sebagai objek.
Deklarasi baris kedua Stp(stop)sebagai string.
Deklarasi baris ketiga Acak sebagai integer.
Deklarasi baris keempat Stopwatch sebagai System.Diagnostics.Stopwatch.
    

Private Sub Susun()
        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 Menang Tekan OK")
            MsgBox("Waktu Anda: " & stpWatch.Elapsed.TotalSeconds & " detik")
            Button1.Enabled = False
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Enabled = False
            Button6.Enabled = False
            Button7.Enabled = False
            Button8.Enabled = False
            Button9.Enabled = False
        End If
    End Sub
Keterangan:
Prosedur tersebut jika gambar telah tersusun dengan benar maka akan keluar message box yang menandakan user telah menang dan mengeluarkan waktu yang diperlukan untuk menyelesaikan puzzle tersebut.
.enabled digunakan untuk mengubah apakah button tersebut aktif atau tidak,false menandakan button tersebut tidak aktif.


    Private Sub stopwatch()
        stpWatch.Start()
    End Sub
Keterangan:
Prosedur tersebut digunakan untuk memulai stopwatch.


    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        smt = Button9.BackgroundImage
        Button9.BackgroundImage = Button4.BackgroundImage
        Button4.BackgroundImage = smt

        smt = Button9.BackgroundImage
        Button9.BackgroundImage = Button3.BackgroundImage
        Button3.BackgroundImage = smt

        smt = Button2.BackgroundImage
        Button2.BackgroundImage = Button7.BackgroundImage
        Button7.BackgroundImage = smt

        smt = Button2.BackgroundImage
        Button2.BackgroundImage = Button6.BackgroundImage
        Button6.BackgroundImage = smt

        smt = Button3.BackgroundImage
        Button3.BackgroundImage = Button8.BackgroundImage
        Button8.BackgroundImage = smt

        smt = Button3.BackgroundImage
        Button3.BackgroundImage = Button1.BackgroundImage
        Button1.BackgroundImage = smt

        smt = Button5.BackgroundImage
        Button5.BackgroundImage = Button8.BackgroundImage
        Button8.BackgroundImage = smt

        smt = Button5.BackgroundImage
        Button5.BackgroundImage = Button7.BackgroundImage
        Button7.BackgroundImage = smt

        smt = Button6.BackgroundImage
        Button6.BackgroundImage = Button1.BackgroundImage
        Button1.BackgroundImage = smt

        stp = Button9.Text
        Button9.Text = Button4.Text
        Button4.Text = stp

        stp = Button9.Text
        Button9.Text = Button3.Text
        Button3.Text = stp

        stp = Button2.Text
        Button2.Text = Button7.Text
        Button7.Text = stp

        stp = Button2.Text
        Button2.Text = Button6.Text
        Button6.Text = stp

        stp = Button3.Text
        Button3.Text = Button8.Text
        Button8.Text = stp

        stp = Button3.Text
        Button3.Text = Button1.Text
        Button1.Text = stp

        stp = Button5.Text
        Button5.Text = Button8.Text
        Button8.Text = stp

        stp = Button5.Text
        Button5.Text = Button7.Text
Button7.Text = stp

        stp = Button6.Text
        Button6.Text = Button1.Text
        Button1.Text = stp
    End Sub
Keterangan:
Listing tersebut digunakan untuk mengacak gambar jika ditekan tombol acak dan menghentikan acakan gambar jika ditekan tombol stop.


    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        Timer1.Enabled = False
        Button1.Enabled = True
        Button2.Enabled = True
        Button3.Enabled = True
        Button4.Enabled = True
        Button5.Enabled = True
        Button6.Enabled = True
        Button7.Enabled = True
        Button8.Enabled = True
        Button9.Enabled = True

        Call stopwatch()
    End Sub
Keterangan:
Listing tersebut digunakan untuk mengaktifkan button.
Call stopwatch digunakan untuk memanggil prosedur stopwatch.


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Button2.BackgroundImage Is Nothing Then
            smt = Button1.BackgroundImage
            Button1.BackgroundImage = Button2.BackgroundImage
            Button2.BackgroundImage = smt
            Button2.Text = ""
            stp = Button1.Text
            Button1.Text = Button2.Text
            Button2.Text = stp
        End If

        If Button4.BackgroundImage Is Nothing Then
            smt = Button1.BackgroundImage
            Button1.BackgroundImage = Button4.BackgroundImage
            Button4.BackgroundImage = smt
            Button4.Text = ""
            stp = Button1.Text
            Button1.Text = Button4.Text
            Button4.Text = stp
        End If
        Call Susun()
    End Sub
Keterangan:
Listing tersebut digunakan untuk mengubah gambar di button yang berada disampingnya dan memanggil prosedur susun.


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Button1.BackgroundImage Is Nothing Then
            smt = Button2.BackgroundImage
            Button2.BackgroundImage = Button1.BackgroundImage
            Button1.BackgroundImage = smt

            Button1.Text = ""
            stp = Button2.Text
            Button2.Text = Button1.Text
            Button1.Text = stp
        End If

        If Button3.BackgroundImage Is Nothing Then
            smt = Button2.BackgroundImage
            Button2.BackgroundImage = Button3.BackgroundImage
            Button3.BackgroundImage = smt

            Button3.Text = ""
            stp = Button2.Text
            Button2.Text = Button3.Text
            Button3.Text = stp


        ElseIf Button5.BackgroundImage Is Nothing Then
            smt = Button5.BackgroundImage
            Button5.BackgroundImage = Button2.BackgroundImage
            Button2.BackgroundImage = smt
            Button5.Text = ""
            stp = Button5.Text
            Button5.Text = Button2.Text
            Button2.Text = stp
        End If
        Call Susun()
    End Sub
Keterangan:
Listing tersebut digunakan untuk mengubah gambar di button yang berada disampingnya dan memanggil prosedur susun.


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Button2.BackgroundImage Is Nothing Then
            smt = Button3.BackgroundImage
            Button3.BackgroundImage = Button2.BackgroundImage
            Button2.BackgroundImage = smt

            Button2.Text = ""
            stp = Button3.Text
            Button3.Text = Button2.Text
            Button2.Text = stp
        End If

        If Button6.BackgroundImage Is Nothing Then
            smt = Button3.BackgroundImage
            Button3.BackgroundImage = Button6.BackgroundImage
            Button6.BackgroundImage = smt
            Button6.Text = ""
            stp = Button3.Text
            Button3.Text = Button6.Text
            Button6.Text = stp

        End If
        Call Susun()
    End Sub
Keterangan:
Listing tersebut digunakan untuk mengubah gambar di button yang berada disampingnya dan memanggil prosedur susun.


    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button1.BackgroundImage Is Nothing Then
            smt = Button4.BackgroundImage
            Button4.BackgroundImage = Button1.BackgroundImage
            Button1.BackgroundImage = smt

            If Button1.Text = "" Then
                stp = Button4.Text
                Button4.Text = Button1.Text
                Button1.Text = stp
            End If
        ElseIf Button5.BackgroundImage Is Nothing Then
            smt = Button4.BackgroundImage
            Button4.BackgroundImage = Button5.BackgroundImage
            Button5.BackgroundImage = smt
            Button5.Text = ""
            stp = Button4.Text
            Button4.Text = Button5.Text
            Button5.Text = stp

        ElseIf Button7.BackgroundImage Is Nothing Then
            smt = Button4.BackgroundImage
            Button4.BackgroundImage = Button7.BackgroundImage
            Button7.BackgroundImage = smt
            Button7.Text = ""
            stp = Button4.Text
            Button4.Text = Button7.Text
            Button7.Text = stp

        End If
        Call Susun()
    End Sub
Keterangan:
Listing tersebut digunakan untuk mengubah gambar di button yang berada disampingnya dan memanggil prosedur susun.


    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If Button2.BackgroundImage Is Nothing Then
            smt = Button5.BackgroundImage
            Button5.BackgroundImage = Button2.BackgroundImage
            Button2.BackgroundImage = smt
            Button2.Text = ""
            stp = Button5.Text
            Button5.Text = Button2.Text
            Button2.Text = stp
        End If

        If Button4.BackgroundImage Is Nothing Then
            smt = Button5.BackgroundImage
            Button5.BackgroundImage = Button4.BackgroundImage
            Button4.BackgroundImage = smt
            Button4.Text = ""
            stp = Button5.Text
            Button5.Text = Button4.Text
            Button4.Text = stp

        ElseIf Button6.BackgroundImage Is Nothing Then
            smt = Button5.BackgroundImage
            Button5.BackgroundImage = Button6.BackgroundImage
            Button6.BackgroundImage = smt
            Button6.Text = ""
            stp = Button5.Text
            Button5.Text = Button6.Text
            Button6.Text = stp

        ElseIf Button8.BackgroundImage Is Nothing Then
            smt = Button5.BackgroundImage
            Button5.BackgroundImage = Button8.BackgroundImage
            Button8.BackgroundImage = smt
            Button8.Text = ""
            stp = Button5.Text
            Button5.Text = Button8.Text
            Button8.Text = stp

        End If
        Call Susun()
    End Sub
Keterangan:
Listing tersebut digunakan untuk mengubah gambar di button yang berada disampingnya dan memanggil prosedur susun.


    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If Button3.BackgroundImage Is Nothing Then
            smt = Button6.BackgroundImage
            Button6.BackgroundImage = Button3.BackgroundImage
            Button3.BackgroundImage = smt
            Button3.Text = ""
            stp = Button6.Text
            Button6.Text = Button3.Text
            Button3.Text = stp
        End If

        If Button5.BackgroundImage Is Nothing Then
            smt = Button6.BackgroundImage
            Button6.BackgroundImage = Button5.BackgroundImage
            Button5.BackgroundImage = smt
            Button5.Text = ""
            stp = Button6.Text
            Button6.Text = Button5.Text
            Button5.Text = stp


        ElseIf Button9.BackgroundImage Is Nothing Then
            smt = Button6.BackgroundImage
            Button6.BackgroundImage = Button9.BackgroundImage
            Button9.BackgroundImage = smt
            Button9.Text = ""
            stp = Button6.Text
            Button6.Text = Button9.Text
            Button9.Text = stp
        End If
        Call Susun()
    End Sub
Keterangan:
Listing tersebut digunakan untuk mengubah gambar di button yang berada disampingnya dan memanggil prosedur susun.


    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If Button4.BackgroundImage Is Nothing Then
            smt = Button7.BackgroundImage
            Button7.BackgroundImage = Button4.BackgroundImage
            Button4.BackgroundImage = smt
            Button4.Text = ""
            stp = Button7.Text
            Button7.Text = Button4.Text
            Button4.Text = stp
        End If

        If Button8.BackgroundImage Is Nothing Then
            smt = Button7.BackgroundImage
            Button7.BackgroundImage = Button8.BackgroundImage
            Button8.BackgroundImage = smt
            Button8.Text = ""
            stp = Button7.Text
            Button7.Text = Button8.Text
            Button8.Text = stp
        End If
        Call Susun()
    End Sub
Keterangan:
Listing tersebut digunakan untuk mengubah gambar di button yang berada disampingnya dan memanggil prosedur susun.


    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If Button7.BackgroundImage Is Nothing Then
            smt = Button8.BackgroundImage
            Button8.BackgroundImage = Button7.BackgroundImage
            Button7.BackgroundImage = smt
            Button7.Text = ""
            stp = Button8.Text
            Button8.Text = Button7.Text
            Button7.Text = stp
        End If

        If Button5.BackgroundImage Is Nothing Then
            smt = Button8.BackgroundImage
            Button8.BackgroundImage = Button5.BackgroundImage
            Button5.BackgroundImage = smt
            Button5.Text = ""
            stp = Button8.Text
            Button8.Text = Button5.Text
            Button5.Text = stp

        ElseIf Button9.BackgroundImage Is Nothing Then
            smt = Button8.BackgroundImage
            Button8.BackgroundImage = Button9.BackgroundImage
            Button9.BackgroundImage = smt
            Button9.Text = ""
            stp = Button8.Text
            Button8.Text = Button9.Text
            Button9.Text = stp
        End If
        Call Susun()
    End Sub
Keterangan:
Listing tersebut digunakan untuk mengubah gambar di button yang berada disampingnya dan memanggil prosedur susun.


    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If Button6.BackgroundImage Is Nothing Then
            smt = Button9.BackgroundImage
            Button9.BackgroundImage = Button6.BackgroundImage
            Button6.BackgroundImage = smt
            Button6.Text = ""
            stp = Button9.Text
            Button9.Text = Button6.Text
            Button6.Text = stp
        End If

        If Button8.BackgroundImage Is Nothing Then
            smt = Button9.BackgroundImage
            Button9.BackgroundImage = Button8.BackgroundImage
            Button8.BackgroundImage = smt
            Button8.Text = ""
            stp = Button9.Text
            Button9.Text = Button8.Text
            Button8.Text = stp
        End If
        Call Susun()
    End Sub
Keterangan:
Listing tersebut digunakan untuk mengubah gambar di button yang berada disampingnya dan memanggil prosedur susun.


    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        MsgBox("Thanks for playing this Game :)")
        Close()

    End Sub
Keterangan:
Listing tersebut digunakan untuk menutup aplikasi dan menampilkan message box yang berisi ("Thanks for playing this Game :)").


    Private Sub Button10_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        Timer1.Enabled = True
        acak = Rnd() * 10
    End Sub
Keterangan:
Listing tersebut digunakan untuk mengaktifkan timer dan menggacak gambar button 1 sampai 9.


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Button1.Enabled = False
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False
        Button5.Enabled = False
        Button6.Enabled = False
        Button7.Enabled = False
        Button8.Enabled = False
        Button9.Enabled = False
    End Sub
Keterangan:
.enabled digunakan untuk mengubah apakah button tersebut aktif atau tidak,false menandakan button tersebut tidak aktif.

Tidak ada komentar:

Posting Komentar