Minggu, 28 Oktober 2012

TUGAS 3 PART II

 2 ) MEMBUAT PROGRAM PUZZLE .

1 . Buat button dengan tampilan berikut .

Buat 9 button dengan 1 button kosong pada button 9.
Button 1 : Dengan nama text satu .

Button 2 : Dengan nama text dua .
Button 3 : Dengan nama text tiga .
Button 4 : Dengan nama text empat .
Button 5 : Dengan nama text lima .
Button 6 : Dengan nama text enam .
Button 7 : Dengan nama text tujuh .
Button 8 : Dengan nama text delapan .



Pada program ini saya tidak memakai GroupBox pada 9 button yang dijadikan puzzle namun saya memakainya pada button restart dan exit untuk membedakan dari 9 button tersebut  .

-  <> 0 :  Memanggil semua angka kecuali 0 .
-  number = Rnd() * 8 : Mengacak nomer 1-8.
- And & Or : Memberikan syarat tambahan .
- Else if : Untuk pengecekan pertukaran angka .
- Loop Until : Kondisi dihentikan sampai dengan benar .



 *Tampilan sebelum dijalankan




2 . Syntax Program .


Public Class Form1

    Private Sub tiga_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tiga.Click
        If dua.Text = "" Then
            dua.Text = tiga.Text
            tiga.Text = ""
        ElseIf enam.Text = "" Then
            enam.Text = tiga.Text
            tiga.Text = ""
        End If
        If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Succes")
        End If

    End Sub

    Private Sub empat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles empat.Click
        If satu.Text = "" Then
            satu.Text = empat.Text
            empat.Text = ""
        ElseIf tujuh.Text = "" Then
            tujuh.Text = empat.Text
            empat.Text = ""
        ElseIf lima.Text = "" Then
            lima.Text = empat.Text
            empat.Text = ""
        End If
        If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Succes")
        End If

    End Sub

    Private Sub lima_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lima.Click
        If dua.Text = "" Then
            dua.Text = lima.Text
            lima.Text = ""
        ElseIf empat.Text = "" Then
            empat.Text = lima.Text
            lima.Text = ""
        ElseIf enam.Text = "" Then
            enam.Text = lima.Text
            lima.Text = ""
        ElseIf delapan.Text = "" Then
            delapan.Text = lima.Text
            lima.Text = ""
        End If
        If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Succes")
        End If

    End Sub

    Private Sub enam_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enam.Click
        If Button9.Text = "" Then
            Button9.Text = enam.Text
            enam.Text = ""
        ElseIf tiga.Text = "" Then
            tiga.Text = enam.Text
            enam.Text = ""
        ElseIf lima.Text = "" Then
            lima.Text = enam.Text
            enam.Text = ""
        End If
        If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Succes")
        End If

    End Sub

    Private Sub tujuh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tujuh.Click
        If empat.Text = "" Then
            empat.Text = tujuh.Text
            tujuh.Text = ""
        ElseIf delapan.Text = "" Then
            delapan.Text = tujuh.Text
            tujuh.Text = ""
        End If
        If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Succes")
        End If

    End Sub

    Private Sub delapan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delapan.Click
        If tujuh.Text = "" Then
            tujuh.Text = delapan.Text
            delapan.Text = ""
        ElseIf Button9.Text = "" Then
            Button9.Text = delapan.Text
            delapan.Text = ""
        ElseIf lima.Text = "" Then
            lima.Text = delapan.Text
            delapan.Text = ""
        End If
        If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Succes")
        End If

    End Sub
    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If enam.Text = "" Then
            enam.Text = Button9.Text
            Button9.Text = ""
        ElseIf delapan.Text = "" Then
            delapan.Text = Button9.Text
            Button9.Text = ""
        End If
        If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Succes")
        End If


    End Sub



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim control As Windows.Forms.Control
        Dim number As Integer
        For Each control In Me.Controls
            If control.GetType.Name = "Button" Then
                control.Text = number
            End If


            If dua.Text = satu.Text Then
                Do
                    number = Rnd() * 8
                    dua.Text = number
                Loop Until dua.Text <> satu.Text And dua.Text <> "0"

            End If

            If tiga.Text = dua.Text Or tiga.Text = satu.Text Then
                Do
                    number = Rnd() * 8
                    tiga.Text = number
                Loop Until tiga.Text <> dua.Text And tiga.Text <> satu.Text And tiga.Text <> "0"

            End If

            If empat.Text = tiga.Text Or empat.Text = dua.Text Or empat.Text = satu.Text Then
                Do
                    number = Rnd() * 8
                    empat.Text = number
                Loop Until empat.Text <> tiga.Text And empat.Text <> dua.Text And empat.Text <> satu.Text And empat.Text <> "0"
            End If

            If empat.Text = tiga.Text Or empat.Text = dua.Text Or empat.Text = satu.Text Then
                Do
                    number = Rnd() * 8
                    empat.Text = number
                Loop Until empat.Text <> tiga.Text And empat.Text <> dua.Text And empat.Text <> satu.Text And lima.Text <> "0"
            End If

            If lima.Text = empat.Text Or lima.Text = tiga.Text Or lima.Text = dua.Text Or lima.Text = satu.Text Then
                Do
                    number = Rnd() * 8
                    lima.Text = number
                Loop Until lima.Text <> empat.Text And lima.Text <> tiga.Text And lima.Text <> dua.Text And lima.Text <> satu.Text And lima.Text <> "0"
            End If

            If enam.Text = lima.Text Or enam.Text = empat.Text Or enam.Text = tiga.Text Or enam.Text = dua.Text Or enam.Text = satu.Text Then
                Do
                    number = Rnd() * 8
                    enam.Text = number

                Loop Until enam.Text <> lima.Text And enam.Text <> tiga.Text And enam.Text <> dua.Text And enam.Text <> satu.Text And enam.Text <> "0"

            End If

            If tujuh.Text = enam.Text Or tujuh.Text = lima.Text Or tujuh.Text = empat.Text Or tujuh.Text = tiga.Text Or tujuh.Text = dua.Text Or tujuh.Text = satu.Text Then
                Do
                    number = Rnd() * 8
                    tujuh.Text = number

                Loop Until tujuh.Text <> enam.Text And tujuh.Text <> lima.Text And tujuh.Text <> empat.Text And tujuh.Text <> tiga.Text And tujuh.Text <> dua.Text And tujuh.Text <> satu.Text And tujuh.Text <> "0"

            End If

            If delapan.Text = tujuh.Text Or delapan.Text = enam.Text Or delapan.Text = lima.Text Or delapan.Text = empat.Text Or delapan.Text = tiga.Text Or delapan.Text = dua.Text Or delapan.Text = satu.Text Then
                Do
                    number = Rnd() * 8
                    delapan.Text = number

                Loop Until delapan.Text <> tujuh.Text And delapan.Text <> enam.Text And delapan.Text <> lima.Text And delapan.Text <> empat.Text And delapan.Text <> tiga.Text And delapan.Text <> dua.Text And delapan.Text <> satu.Text And delapan.Text <> "0"

            End If
            Button9.Text = ""
        Next
    End Sub

    Private Sub btexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btexit.Click
        If MsgBox(" Do you want to exit? ", vbQuestion + vbYesNo + vbDefaultButton2, "Exit") = vbYes Then
            Me.Close()
        End If

    End Sub

    Private Sub satu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles satu.Click
        If dua.Text = "" Then
            dua.Text = satu.Text
            satu.Text = ""
        ElseIf empat.Text = "" Then
            empat.Text = satu.Text
            satu.Text = ""
        End If
    End Sub

    Private Sub dua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dua.Click
        If satu.Text = "" Then
            satu.Text = dua.Text
            dua.Text = ""
        ElseIf lima.Text = "" Then
            lima.Text = dua.Text
            dua.Text = ""
        ElseIf tiga.Text = "" Then
            tiga.Text = dua.Text
            dua.Text = ""
        End If
    End Sub

    Private Sub btrestart_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btrestart.Click
        If MsgBox(" Do you want to restart? ", vbInformation + vbYesNo, " Restart Game Puzzle ") = vbYes Then
            Application.Restart()
        End If
    End Sub
End Class

* Tampilan setelah dijalankan .


* Tampilan saat akan puzzle terurut .



*Tampilan saat akan direstart .


*Tampilan saat akan diexit .




Selamat Mencoba
SEKIAN TERIMAKASIH ^_^


Tidak ada komentar:

Posting Komentar