Minggu, 27 Maret 2011

VB.net PUZZLE

CARA BUAT PUZZEL

pertama kita buka  VB.NET 2008 lalu new project, kemudian buat desain seperti ini :
kemudian ganti nama

button1   textnya menjadi =3,seperti :
sampai button8...
button2  textnya menjadi =5
button3  textnya menjadi =6
button4  textnya menjadi =2
button5  textnya menjadi =1
button6  textnya menjadi =7
button7  textnya menjadi =8
button8  textnya menjadi =4
sedangkan button9
button9  menjadi visible = false *,seperti:
kemudian button-button tersebut diisi perintah,
dengan cara double klik pada button tersebut seperti berikut :

Public Class Form1

(button1):
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Button2.Visible = False Then
            Button2.Visible = True
            Button1.Visible = False
            Button2.Text = Button1.Text

        Else
            If Button4.Visible = False Then
                Button4.Visible = True
                Button1.Visible = False
                Button4.Text = Button1.Text
            End If
        End If

        kerja()
    End Sub

(button2):

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Button1.Visible = False Then
            Button1.Visible = True
            Button2.Visible = False
            Button1.Text = Button2.Text

        ElseIf Button3.Visible = False Then
            Button3.Visible = True
            Button2.Visible = False
            Button3.Text = Button2.Text

        ElseIf Button5.Visible = False Then
            Button2.Visible = True
            Button5.Visible = False
            Button5.Text = Button2.Text

        End If

        kerja()
    End Sub

(button3):

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Button2.Visible = False Then
            Button2.Visible = True
            Button3.Visible = False
            Button2.Text = Button3.Text
        Else
            If Button6.Visible = False Then
                Button6.Visible = True
                Button3.Visible = False
                Button6.Text = Button3.Text
            End If

        End If


    End Sub

(button4):

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button1.Visible = False Then
            Button1.Visible = True
            Button4.Visible = False
            Button1.Text = Button4.Text
        ElseIf Button5.Visible = False Then
            Button5.Visible = True
            Button4.Visible = False
            Button5.Text = Button4.Text
        ElseIf Button7.Visible = False Then
            Button7.Visible = True
            Button4.Visible = False
            Button7.Text = Button4.Text
        End If
        kerja()
    End Sub

(button5):

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If Button2.Visible = False Then
            Button2.Visible = True
            Button5.Visible = False
            Button2.Text = Button5.Text
        ElseIf Button4.Visible = False Then
            Button4.Visible = True
            Button5.Visible = False
            Button4.Text = Button5.Text
        ElseIf Button6.Visible = False Then
            Button6.Visible = True
            Button5.Visible = False
            Button6.Text = Button5.Text
        ElseIf Button8.Visible = False Then
            Button8.Visible = True
            Button5.Visible = False
            Button8.Text = Button5.Text
        End If

        kerja()
    End Sub

(button6):

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If Button3.Visible = False Then
            Button3.Visible = True
            Button6.Visible = False
            Button3.Text = Button6.Text
        ElseIf Button9.Visible = False Then
            Button9.Visible = True
            Button6.Visible = False
            Button9.Text = Button6.Text
        ElseIf Button5.Visible = False Then
            Button5.Visible = True
            Button6.Visible = False
            Button5.Text = Button6.Text
        End If
        kerja()
    End Sub

(button7):

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If Button8.Visible = False Then
            Button8.Visible = True
            Button7.Visible = False
            Button8.Text = Button7.Text
        Else
            If Button4.Visible = False Then
                Button4.Visible = True
                Button7.Visible = False
                Button4.Text = Button7.Text
            End If
        End If
        kerja()
    End Sub

(button8):

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If Button7.Visible = False Then
            Button7.Visible = True
            Button8.Visible = False
            Button7.Text = Button8.Text
        ElseIf Button9.Visible = False Then
            Button9.Visible = True
            Button8.Visible = False
            Button9.Text = Button8.Text
        ElseIf Button5.Visible = False Then
            Button5.Visible = True
            Button8.Visible = False
            Button5.Text = Button8.Text
        End If
        kerja()
    End Sub

(button9):

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If Button6.Visible = False Then
            Button6.Visible = True
            Button9.Visible = False
            Button6.Text = Button9.Text
        Else
            If Button8.Visible = False Then
                Button8.Visible = True
                Button9.Visible = False
                Button8.Text = Button9.Text
            End If
        End If
        kerja()
    End Sub

setelah selesai mengisi printah dari setiap button tersebut sekarang kita tambah methotnya :
    Private Sub kerja()
        If (Button1.Text = "1" And Button2.Text = "2" And Button3.Text = "3" And Button4.Text = "4") Then
            If (Button5.Text = "5" And Button6.Text = "6" And Button7.Text = "7") Then
                If (Button8.Text = "8") Then

                    MessageBox.Show(" selamat anda berhasil")
                End If
            End If
        End If
    End Sub
End Class

setelah selesai kemudian kita run, dan hasilnya seperti ini:

Tidak ada komentar:

Posting Komentar