Senin, 05 November 2012

PUZZLE CUTE

PUZZLE CUTE
Nama         : EKA YUNITA H S
Kelas          : TI 11 C
Nim            : 11.11.2498
            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.

            Berikutnya adalah pembuatan game dengan menyusun “Common Controls” yang dibtuhkan 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
        btstop.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 btacak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btacak.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
        btacak.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
  • Mengaktifkan Button STOP ACAK

Private Sub btstop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btstop.Click
        btacak.Enabled = False
        Timer1.Enabled = False
        btstop.Enabled = True

    End Sub



Sehingga angka menjadi acak, seperti yang terlihat dibawah ini :

Sebagai contoh Saya tampilkan Beberapa Pengacakan .







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 Cute")
            Timer1.Enabled = False
        End If
    End Sub


2.      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 Listing dibawah ini Anda dapat melihat pesan Konfirmasi.
    Private Sub btkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btkeluar.Click
        If MsgBox("Anda Yakin Untuk Menghentikan GAME ini ?", vbYesNo + vbQuestion) = vbYes Then
            End
        End If
    End Sub

*warna telah dideklarasikan pada form 1.
*terakhir listing dituliskan “ End class”

     Terima Kasih Atas Waktu Anda Telah Mengunjungi Blog Saya, Mohon Maaf jika Banyak Kekurangan pada Listing Aplikasi yang Saya buat untuk memenuhi penilaian.  J

Tidak ada komentar:

Posting Komentar