Minggu, 28 Oktober 2012

TUGAS 3 PEMROGRAMAN VISUAL

Memodifikasi Program  dan Membuat Permainan Puzzle

Assalamua'alaikum... 
Pada kesempatan ini saya akan sedikit menjelaskan cara memodifikasi program dan cara membuat permainan Puzzle. Langsung saja...

Memodifikasi Program
Program yang saya modifikasi merupakan program yang sudah dibuat pada tugas 2 pemrograman visual Latihan if dan case. Sehingga kali ini saya hanya akan menampilkan listing dari modifikasi program tersebut. 

1. Saat form dijalankan : semua isian tidak aktif, tombol isi data dan tutup aktif, tombol clear tidak   aktif
 
Berikut listing pada saat form dijalankan:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cmbkode.Items.Add("SPT")
        cmbkode.Items.Add("SND")
        cmbkode.Items.Add("TST")
        cmbkode.Items.Add("TOP")
        cmbkode.Items.Add("TAS")

        Dim Control As Windows.Forms.Control
        For Each Control In Me.Controls
            cmbkode.Enabled = False
            btnclear.Enabled = False
            btnisidata.Enabled = True
            btntutup.Enabled = True
            txtnama.Enabled = False
            txtharga.Enabled = False
            txtjumlah.Enabled = False
            txtdiskon.Enabled = False
            txttotal.Enabled = False
            txtbayar.Enabled = False
            radiotunai.Enabled = False
            radiokredit.Enabled = False
        Next
    End Sub

2. Saat ditekan tombol isi data : kodebarang, jumlahbarang, cara beli, tombol clear, aktif, tombol isidata tidak aktif
 
Bertikut listingnya pada saat menekan tombol isi data:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cmbkode.Items.Add("SPT")
        cmbkode.Items.Add("SND")
        cmbkode.Items.Add("TST")
        cmbkode.Items.Add("TOP")
        cmbkode.Items.Add("TAS")

        Dim Control As Windows.Forms.Control
        For Each Control In Me.Controls
            cmbkode.Enabled = False
            btnclear.Enabled = False
            btnisidata.Enabled = True
            btntutup.Enabled = True
            txtnama.Enabled = False
            txtharga.Enabled = False
            txtjumlah.Enabled = False
            txtdiskon.Enabled = False
            txttotal.Enabled = False
            txtbayar.Enabled = False
            radiotunai.Enabled = False
            radiokredit.Enabled = False
        Next         

    End Sub

Kemudian isi data-data tersebut seperti dibawah ini:
 

3. Saat ditekan combol clear sama dengan saat form dijalankan
 
Berikut listing pada tombol clear:

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
        Dim Control As Windows.Forms.Control
        For Each Control In Me.Controls
            cmbkode.Enabled = False
            btnclear.Enabled = False
            btnisidata.Enabled = True
            btntutup.Enabled = True
            txtnama.Enabled = False
            txtharga.Enabled = False
            txtjumlah.Enabled = False
            txtdiskon.Enabled = False
            txttotal.Enabled = False
            txtbayar.Enabled = False
            radiotunai.Enabled = False
            radiokredit.Enabled = False
        Next


        txtdiskon.Clear()
        txtharga.Clear()
        txtjumlah.Clear()
        txtnama.Clear()
        txttotal.Clear()
        txtbayar.Clear()
        cmbkode.Text = " "

    End Sub
 
Permainan Puzzle
Cara membuat permainan Puzzle langkah -langkahnya sebagai berikut:
1. Buat 1 form dan 9 Button, dengan Name Button: btn1, btn2, btn3, btn4,  btn5, btn6, btn7, btn8, dan btn9.
2. Ubah Text Form1: Puzzle, dan ubah Text masing-masing button dari btn1: 1 seterusnya sampai btn8: 8. Untuk btn9 tidak diberi Text (kosong).
3. Pada saat form dijalankan posisi angka acak, seperti gambar dibawah ini:
 Listing programnya sebagai berikut:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim control As Windows.Forms.Control
        For Each control In Me.Controls
            If control.GetType.Name = "Button" Then
                btn1.Text = "6"
                btn2.Text = "1"
                btn3.Text = "8"
                btn4.Text = "7"
                btn5.Text = "5"
                btn6.Text = "2"
                btn7.Text = "4"
                btn8.Text = "3"
                btn9.Text = " "
            End If
        Next

    End Sub

4. Saat ditekan tombol yang terletak di dekat tombol kosong maka tombol tersebut akan menempati tombol kosong, begitu seterusnya sampai dengan angkanya tersusun dari 1 sampai 8.
 
 Berikut listing programnya:

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
        Dim tuker As String
        If btn2.Text = " " Then
            tuker = btn1.Text
            btn1.Text = btn2.Text
            btn2.Text = tuker
        ElseIf btn4.Text = " " Then
            tuker = btn1.Text
            btn1.Text = btn4.Text
            btn4.Text = tuker
        End If
        benar()
    End Sub

    Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
        Dim tuker As String
        If btn1.Text = " " Then
            tuker = btn2.Text
            btn2.Text = btn1.Text
            btn1.Text = tuker
        ElseIf btn3.Text = " " Then
            tuker = btn2.Text
            btn2.Text = btn3.Text
            btn3.Text = tuker
        ElseIf btn5.Text = " " Then
            tuker = btn2.Text
            btn2.Text = btn5.Text
            btn5.Text = tuker
        End If
        benar()
    End Sub

    Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
        Dim tuker As String
        If btn2.Text = " " Then
            tuker = btn3.Text
            btn3.Text = btn2.Text
            btn2.Text = tuker
        ElseIf btn6.Text = " " Then
            tuker = btn3.Text
            btn3.Text = btn6.Text
            btn6.Text = tuker
        End If
        benar()
    End Sub

    Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
        Dim tuker As String
        If btn1.Text = " " Then
            tuker = btn4.Text
            btn4.Text = btn1.Text
            btn1.Text = tuker
        ElseIf btn5.Text = " " Then
            tuker = btn4.Text
            btn4.Text = btn5.Text
            btn5.Text = tuker
        ElseIf btn7.Text = " " Then
            tuker = btn4.Text
            btn4.Text = btn7.Text
            btn7.Text = tuker
        End If
        benar()
    End Sub

    Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
        Dim tuker As String
        If btn2.Text = " " Then
            tuker = btn5.Text
            btn5.Text = btn2.Text
            btn2.Text = tuker
        ElseIf btn4.Text = " " Then
            tuker = btn5.Text
            btn5.Text = btn4.Text
            btn4.Text = tuker
        ElseIf btn6.Text = " " Then
            tuker = btn5.Text
            btn5.Text = btn6.Text
            btn6.Text = tuker
        ElseIf btn8.Text = " " Then
            tuker = btn5.Text
            btn5.Text = btn8.Text
            btn8.Text = tuker
        End If
        benar()
    End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
        Dim tuker As String
        If btn9.Text = " " Then
            tuker = btn6.Text
            btn6.Text = btn9.Text
            btn9.Text = tuker
        ElseIf btn3.Text = " " Then
            tuker = btn6.Text
            btn6.Text = btn3.Text
            btn3.Text = tuker
        ElseIf btn5.Text = " " Then
            tuker = btn6.Text
            btn6.Text = btn5.Text
            btn5.Text = tuker
        End If
        benar()
    End Sub

Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
        Dim tuker As String
        If btn4.Text = " " Then
            tuker = btn7.Text
            btn7.Text = btn4.Text
            btn4.Text = tuker
        ElseIf btn8.Text = " " Then
            tuker = btn7.Text
            btn7.Text = btn8.Text
            btn8.Text = tuker
        End If
        benar()
    End Sub

    Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
        Dim tuker As String
        If btn9.Text = " " Then
            tuker = btn8.Text
            btn8.Text = btn9.Text
            btn9.Text = tuker
        ElseIf btn7.Text = " " Then
            tuker = btn8.Text
            btn8.Text = btn7.Text
            btn7.Text = tuker
        ElseIf btn5.Text = " " Then
            tuker = btn8.Text
            btn8.Text = btn5.Text
            btn5.Text = tuker
        End If
        benar()
    End Sub

    Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
        Dim tuker As String
        If btn6.Text = " " Then
            tuker = btn9.Text
            btn9.Text = btn6.Text
            btn6.Text = tuker
        ElseIf btn8.Text = " " Then
            tuker = btn9.Text
            btn9.Text = btn8.Text
            btn8.Text = tuker
        End If
        benar()
    End Sub

5. Saat angka sudah tersusun tampilkan pesan selamat anda berhasil
 
Berikut listing programnya:


Private Sub benar()
        If btn1.Text = "1" And btn2.Text = "2" And btn3.Text = "3" And btn4.Text = "4" And btn5.Text = "5" And btn6.Text = "6" And btn7.Text = "7" And btn8.Text = "8" Then
            MessageBox.Show("SELAMAT ANDA BERHASIL")
        End If

    End Sub

Demikian penjelasan singkat program tersebut, semoga bermanfaat bagi para pembaca. Terima kasih.
Wassalamu'alaikum...