Selasa, 11 Desember 2012

Tutorial cara membuat puzzle


Tutorial cara membuat puzzle

Kami akan memberikan tutorial cara membuat puzzle, berikut adalah cara cara membuat puzzle dengan visual basic 2010.
1. buka terlebih dahulu visual basic 2010
2. lalu pada form pertama buatlah seperti pada gambar dibawah ini




Dan berikut ini merupakan komponen pada form1
no
komponen
keterangan
1
button1
text = 1
2
button2
text = 2
3
button3
text = 3
4
button4
text = 4
5
button5
text = 5
6
button6
text = 6
7
button7
text = 7
8
button8
text = 8
9
button9
text = 9
10
button10
text = acak
11
button11
text = stop
12
button12
text = menyerah
13
button13
text = tidak
14
button14
text = ya
15
textbox1
-
16
label1
text = 0
17
label2
text = mau main lagi?
18
label3
text = selamat kamu menang








Dan berikut ini merupakan listing dari form1
Public Class Form1
    Dim pindah As String
    Dim acak, skor As Integer
    Dim spin As System.Media.SoundPlayer = New System.Media.SoundPlayer(WindowsApplication1.My.Resources.Spin)
    Dim but As System.Media.SoundPlayer = New System.Media.SoundPlayer(WindowsApplication1.My.Resources.CLICK)
    Dim sp As System.Media.SoundPlayer = New System.Media.SoundPlayer(WindowsApplication1.My.Resources.TADA)

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        spin.PlayLooping()
        Timer2.Enabled = False
        Timer1.Enabled = True
        Label4.Text = "0 s"
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = "0"
        pindah = Button9.Text
        Button9.Text = Button4.Text
        Button4.Text = pindah

        pindah = Button9.Text
        Button9.Text = Button3.Text
        Button3.Text = pindah

        pindah = Button2.Text
        Button2.Text = Button7.Text
        Button7.Text = pindah

        pindah = Button2.Text
        Button2.Text = Button6.Text
        Button6.Text = pindah

        pindah = Button3.Text
        Button3.Text = Button8.Text
        Button8.Text = pindah

        pindah = Button3.Text
        Button3.Text = Button1.Text
        Button1.Text = pindah

        pindah = Button5.Text
        Button5.Text = Button8.Text
        Button8.Text = pindah

        pindah = Button5.Text
        Button5.Text = Button7.Text
        Button7.Text = pindah

        pindah = Button6.Text
        Button6.Text = Button1.Text
        Button1.Text = pindah
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        Timer1.Enabled = False
        spin.Stop()
        Timer2.Enabled = True
    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.Text
            Button9.Text = Button6.Text
            Button6.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button8.Text = "" Then
            pindah = Button9.Text
            Button9.Text = Button8.Text
            Button8.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        End If
        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
            menang()
        End If
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If Button7.Text = "" Then
            pindah = Button8.Text
            Button8.Text = Button7.Text
            Button7.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button5.Text = "" Then
            pindah = Button8.Text
            Button8.Text = Button5.Text
            Button5.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button9.Text = "" Then
            pindah = Button8.Text
            Button8.Text = Button9.Text
            Button9.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        End If
        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
            menang()
        End If
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If Button2.Text = "" Then
            pindah = Button1.Text
            Button1.Text = Button2.Text
            Button2.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button4.Text = "" Then
            pindah = Button1.Text
            Button1.Text = Button4.Text
            Button4.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        End If
        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
            menang()
        End If
    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.Text
            Button2.Text = Button1.Text
            Button1.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button3.Text = "" Then
            pindah = Button2.Text
            Button2.Text = Button3.Text
            Button3.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button5.Text = "" Then
            pindah = Button2.Text
            Button2.Text = Button5.Text
            Button5.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        End If
        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
            menang()
        End If
    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.Text
            Button3.Text = Button2.Text
            Button2.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button6.Text = "" Then
            pindah = Button3.Text
            Button3.Text = Button6.Text
            Button6.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        End If
        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
            menang()
        End If
    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.Text
            Button4.Text = Button1.Text
            Button1.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button5.Text = "" Then
            pindah = Button4.Text
            Button4.Text = Button5.Text
            Button5.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button7.Text = "" Then
            pindah = Button4.Text
            Button4.Text = Button7.Text
            Button7.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        End If
        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
            menang()
        End If
    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.Text
            Button5.Text = Button2.Text
            Button2.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button4.Text = "" Then
            pindah = Button5.Text
            Button5.Text = Button4.Text
            Button4.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button6.Text = "" Then
            pindah = Button5.Text
            Button5.Text = Button6.Text
            Button6.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button8.Text = "" Then
            pindah = Button5.Text
            Button5.Text = Button8.Text
            Button8.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        End If
        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
            menang()
        End If
    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.Text
            Button6.Text = Button3.Text
            Button3.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button5.Text = "" Then
            pindah = Button6.Text
            Button6.Text = Button5.Text
            Button5.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button9.Text = "" Then
            pindah = Button6.Text
            Button6.Text = Button9.Text
            Button9.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        End If
        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
            menang()
        End If
    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.Text
            Button7.Text = Button4.Text
            Button4.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        ElseIf Button8.Text = "" Then
            pindah = Button7.Text
            Button7.Text = Button8.Text
            Button8.Text = pindah
            but.Play()
            Label1.Text = Int(Label1.Text) + 1
        End If
        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
            menang()
        End If
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        MsgBox("Maaf, Anda Gagal", 0, "Exit")
        Form2.Close()
    End Sub
    Private Sub menang()
        sp.Play()
        Label4.Hide()
        Label5.Hide()
        Label2.Show()
        Label3.Show()
        Button14.Show()
        Button13.Show()
        Button1.Hide()
        Label1.Hide()
        TextBox1.Hide()
        Button2.Hide()
        Button3.Hide()
        Button4.Hide()
        Button5.Hide()
        Button6.Hide()
        Button7.Hide()
        Button8.Hide()
        Button9.Hide()
        Button10.Hide()
        Button11.Hide()
        Button12.Hide()

    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        sp.Stop()
        Label4.Show()
        Label5.Show()
        Label2.Hide()
        Label3.Hide()
        Button14.Hide()
        Button13.Hide()
        Button1.Show()
        Label1.Show()
        TextBox1.Show()
        Button2.Show()
        Button3.Show()
        Button4.Show()
        Button5.Show()
        Button6.Show()
        Button7.Show()
        Button8.Show()
        Button9.Show()
        Button10.Show()
        Button11.Show()
        Button12.Show()

    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim testMsg As String

        testMsg = MsgBox("Lihat Score-Mu?", vbYesNo + vbQuestion, "Puzzle 27")

        If testMsg = vbNo Then
            Form2.Close()
        ElseIf testMsg = vbYes Then
            Form4.Show()
            Me.Hide()
        End If

    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Label4.Text = Val(Label4.Text) + 1 & " s"
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button13_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button13_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        Dim testMsg As String

        testMsg = MsgBox("Lihat Score-Mu?", vbYesNo + vbQuestion, "Puzzle 27")

        If testMsg = vbNo Then
            Form2.Close()
        ElseIf testMsg = vbYes Then
            Form4.Show()
            Me.Hide()
        End If
    End Sub

    Private Sub Button14_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        sp.Stop()
        Label4.Show()
        Label5.Show()
        Label2.Hide()
        Label3.Hide()
        Button14.Hide()
        Button13.Hide()
        Button1.Show()
        Label1.Show()
        TextBox1.Show()
        Button2.Show()
        Button3.Show()
        Button4.Show()
        Button5.Show()
        Button6.Show()
        Button7.Show()
        Button8.Show()
        Button9.Show()
        Button10.Show()
        Button11.Show()
        Button12.Show()
    End Sub
End Class

3. lalu lanjut dengan membuat form2 seperti gambar dibawah ini.



Dan dibawah ini merupakan komponen yang digunakan
no
komponen
keterangan
1
label1
text = welcome to
2
label2
text = puzzle 27 game
3
label3
text = do you want to try?
4
button1
text = yes
5
button2
text = no
6
picture box1
-



Dan dibawah ini merupakan listing yang digunakan
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

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Hide()
        MsgBox("Kau Akan Menyesal")
        Me.Close()
    End Sub
End Class

4. lalu lanjut dengan membuat form3 seperti gambar dibawah ini



Lalu komponen nya seperti tabel dibawah ini
no
komponen
keterangan
1
label1
text = kamu menang!!
2
label2
text = mau main lagi??
3
button1
text = ya
4
button2
text = tidak



Dan ikuti listing dibawah ini
Public Class Form3
  
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form1.Show()
        Me.Hide()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        MsgBox("Terima Kasih :)")
        Form2.Close()
    End Sub
End Class


5. setelah membuat form3 lalu buat form4 seperti gambar dibawah ini



Buatlah komponen mengikuti tabel ini
no
komponen
keterangan
1
label1
text = your score
2
label2
text = A+
3
button1
text = exit



Masukan listing dibawah ini
Public Class Form4
    Dim Tada As System.Media.SoundPlayer = New System.Media.SoundPlayer(WindowsApplication1.My.Resources.TADA)
    Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Tada.Play()
        If Val(Form1.TextBox1.Text) <= 50 Then
            Label2.Text = "A"
            If Val(Form1.Label4.Text) >= 1000 Then
                Label3.Text = "-"
            Else
                Label3.Text = "+"
            End If
        ElseIf Val(Form1.TextBox1.Text) > 50 And Val(Form1.TextBox1.Text) <= 100 Then
            Label2.Text = "B"
            If Val(Form1.Label4.Text) >= 1000 Then
                Label3.Text = "-"
            Else
                Label3.Text = "+"
            End If
        ElseIf Val(Form1.TextBox1.Text) > 100 And Val(Form1.TextBox1.Text) <= 150 Then
            Label2.Text = "C"
            If Val(Form1.Label4.Text) >= 1000 Then
                Label3.Text = "-"
            Else
                Label3.Text = "+"
            End If
        ElseIf Val(Form1.TextBox1.Text) > 150 Then
            Label2.Text = "D"
            If Val(Form1.Label4.Text) >= 1000 Then
                Label3.Text = "-"
            Else
                Label3.Text = "+"
            End If
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form2.Close()
    End Sub
End Class

6. lalu setelah itu klik 2 kali my project pada solution explorer, lalu pilih application, lalu pilih start up form =  form2












Tidak ada komentar:

Posting Komentar