Labels

Senin, 12 November 2012

Puzzle



                            Modifikasi Program Latihan 2 IF Dan Case.
kali ini ane akan mencoba memodifikasi program latihan 2
1.        Saat form dijalankan : semua isian tidak aktif, tombol isi data dan tutup aktif, tombol clear tidak aktif.


 









2.       Saat ditekan isi data : kodebarang, jumlah barang, cara beli, tombol clear aktif, tombol isi data tidak aktif.




















3.        Saat ditekan tombol clear sama dengan saat form dijalankan.


 









4.       Langkah – langkah membuat program tersebut diatas adalah sebagai berikut :

A.     Buka aplikasi Visual Basic lalu new project – windows – windows forms        aplication.
B.     Buat tampilan form seperti ini :

Tambahkan koding ini :





 Dan Case yang sebelumnya   menjadi :
a.    1.   Saat form dijalankan : semua isian tidak aktif, tombol isi data dan tutup aktif, tombol clear tidak aktif.






 













Membuat Game Puzzle

 Game ini merupakan game yang paling sederhana.
masih sangat mudah dipelajari..

Form Puzzle

 Saat dijalankan

Hasil sukses


isikan koding puzzle

PublicClassForm1

PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
        Kode_randomisasi()
EndSub

PrivateSub Kode_randomisasi()
Dim control As Windows.Forms.Control
ForEach control InMe.Controls
If control.GetType.Name = "Button"Then
Dim rndnumber AsRandom
                rndnumber = NewRandom
Dim number AsInteger
                control.Text = number

                number = rndnumber.Next(1, 10)
                Bt1.Text = number

If Bt2.Text = Bt1.Text Then
Do
                        number = rndnumber.Next(1, 10)
                        Bt2.Text = number
LoopUntil Bt2.Text <> Bt1.Text
EndIf

If Bt3.Text = Bt2.Text Or Bt3.Text = Bt1.Text Then
Do
                        number = rndnumber.Next(1, 10)
                        Bt3.Text = number
LoopUntil Bt3.Text <> Bt2.Text And Bt3.Text <> Bt1.Text
EndIf

If Bt4.Text = Bt3.Text Or Bt4.Text = Bt2.Text Or Bt4.Text = Bt1.Text Then
Do
                        number = rndnumber.Next(1, 10)
                        Bt4.Text = number
LoopUntil Bt4.Text <> Bt3.Text And Bt4.Text <> Bt2.Text And Bt4.Text <> Bt1.Text
EndIf

If Bt5.Text = Bt4.Text Or Bt5.Text = Bt3.Text Or Bt5.Text = Bt2.Text Or Bt5.Text = Bt1.Text Then
Do
                        number = rndnumber.Next(1, 10)
                        Bt5.Text = number
LoopUntil Bt5.Text <> Bt4.Text And Bt5.Text <> Bt3.Text And Bt5.Text <> Bt2.Text And Bt5.Text <> Bt1.Text
EndIf

If Bt6.Text = Bt5.Text Or Bt6.Text = Bt4.Text Or Bt6.Text = Bt3.Text Or Bt6.Text = Bt2.Text Or Bt6.Text = Bt1.Text Then
Do
                        number = rndnumber.Next(1, 10)
                        Bt6.Text = number
LoopUntil Bt6.Text <> Bt5.Text And Bt6.Text <> Bt4.Text And Bt6.Text <> Bt3.Text And Bt6.Text <> Bt2.Text And Bt6.Text <> Bt1.Text
EndIf

If Bt7.Text = Bt6.Text Or Bt7.Text = Bt5.Text Or Bt7.Text = Bt4.Text Or Bt7.Text = Bt3.Text Or Bt7.Text = Bt2.Text Or Bt7.Text = Bt1.Text Then
Do
                        number = rndnumber.Next(1, 10)
                        Bt7.Text = number
LoopUntil Bt7.Text <> Bt6.Text And Bt7.Text <> Bt5.Text And Bt7.Text <> Bt4.Text And Bt7.Text <> Bt3.Text And Bt7.Text <> Bt2.Text And Bt7.Text <> Bt1.Text
EndIf

If Bt8.Text = Bt7.Text Or Bt8.Text = Bt6.Text Or Bt8.Text = Bt5.Text Or Bt8.Text = Bt4.Text Or Bt8.Text = Bt3.Text Or Bt8.Text = Bt2.Text Or Bt8.Text = Bt1.Text Then
Do
                        number = rndnumber.Next(1, 10)
                        Bt8.Text = number
LoopUntil Bt8.Text <> Bt7.Text And Bt8.Text <> Bt6.Text And Bt8.Text <> Bt5.Text And Bt8.Text <> Bt4.Text And Bt8.Text <> Bt3.Text And Bt8.Text <> Bt2.Text And Bt8.Text <> Bt1.Text
EndIf

If Bt9.Text = Bt8.Text Or Bt9.Text = Bt7.Text Or Bt9.Text = Bt6.Text Or Bt9.Text = Bt5.Text Or Bt9.Text = Bt4.Text Or Bt9.Text = Bt3.Text Or Bt9.Text = Bt2.Text Or Bt9.Text = Bt1.Text Then
Do
                        number = rndnumber.Next(1, 10)
                        Bt9.Text = number
LoopUntil Bt9.Text <> Bt8.Text And Bt9.Text <> Bt7.Text And Bt9.Text <> Bt6.Text And Bt9.Text <> Bt5.Text And Bt9.Text <> Bt4.Text And Bt9.Text <> Bt3.Text And Bt9.Text <> Bt2.Text And Bt9.Text <> Bt1.Text
EndIf
EndIf
Next

        Btacak.Text = "Acak Angka"

If Bt1.Text = "9"Then
            Bt1.Text = ""
EndIf
If Bt2.Text = "9"Then
            Bt2.Text = ""
EndIf
If Bt3.Text = "9"Then
            Bt3.Text = ""
EndIf
If Bt4.Text = "9"Then
            Bt4.Text = ""
EndIf
If Bt5.Text = "9"Then
            Bt5.Text = ""
EndIf
If Bt6.Text = "9"Then
            Bt6.Text = ""
EndIf
If Bt7.Text = "9"Then
            Bt7.Text = ""
EndIf
If Bt8.Text = "9"Then
            Bt8.Text = ""
EndIf
If Bt9.Text = "9"Then
            Bt9.Text = ""
EndIf

EndSub

PrivateSub Bt1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt1.Click
If Bt2.Text = ""Then
            Bt2.Text = Bt1.Text
            Bt1.Text = ""
ElseIf Bt4.Text = ""Then
            Bt4.Text = Bt1.Text
            Bt1.Text = ""
EndIf
        Berhasil()
EndSub

PrivateSub Bt2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt2.Click
If Bt1.Text = ""Then
            Bt1.Text = Bt2.Text
            Bt2.Text = ""
ElseIf Bt3.Text = ""Then
            Bt3.Text = Bt2.Text
            Bt2.Text = ""
ElseIf Bt5.Text = ""Then
            Bt5.Text = Bt2.Text
            Bt2.Text = ""
EndIf
        Berhasil()
EndSub

PrivateSub Bt3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt3.Click
If Bt2.Text = ""Then
            Bt2.Text = Bt3.Text
            Bt3.Text = ""
ElseIf Bt6.Text = ""Then
            Bt6.Text = Bt3.Text
            Bt3.Text = ""
EndIf
        Berhasil()
EndSub

PrivateSub Bt4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt4.Click
If Bt1.Text = ""Then
            Bt1.Text = Bt4.Text
            Bt4.Text = ""
ElseIf Bt5.Text = ""Then
            Bt5.Text = Bt4.Text
            Bt4.Text = ""
ElseIf Bt7.Text = ""Then
            Bt7.Text = Bt4.Text
            Bt4.Text = ""
EndIf
        Berhasil()
EndSub

PrivateSub Bt5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt5.Click
If Bt2.Text = ""Then
            Bt2.Text = Bt5.Text
            Bt5.Text = ""
ElseIf Bt4.Text = ""Then
            Bt4.Text = Bt5.Text
            Bt5.Text = ""
ElseIf Bt6.Text = ""Then
            Bt6.Text = Bt5.Text
            Bt5.Text = ""
ElseIf Bt8.Text = ""Then
            Bt8.Text = Bt5.Text
            Bt5.Text = ""
EndIf
        Berhasil()
EndSub

PrivateSub Bt6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt6.Click
If Bt3.Text = ""Then
            Bt3.Text = Bt6.Text
            Bt6.Text = ""
ElseIf Bt5.Text = ""Then
            Bt5.Text = Bt6.Text
            Bt6.Text = ""
ElseIf Bt9.Text = ""Then
            Bt9.Text = Bt6.Text
            Bt6.Text = ""
EndIf
        Berhasil()
EndSub

PrivateSub Bt7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt7.Click
If Bt4.Text = ""Then
            Bt4.Text = Bt7.Text
            Bt7.Text = ""
ElseIf Bt8.Text = ""Then
            Bt8.Text = Bt7.Text
            Bt7.Text = ""
EndIf
        Berhasil()
EndSub

PrivateSub Bt8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt8.Click
If Bt5.Text = ""Then
            Bt5.Text = Bt8.Text
            Bt8.Text = ""
ElseIf Bt7.Text = ""Then
            Bt7.Text = Bt8.Text
            Bt8.Text = ""
ElseIf Bt9.Text = ""Then
            Bt9.Text = Bt8.Text
            Bt8.Text = ""
EndIf
        Berhasil()
EndSub

PrivateSub Bt9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt9.Click
If Bt6.Text = ""Then
            Bt6.Text = Bt9.Text
            Bt9.Text = ""
ElseIf Bt8.Text = ""Then
            Bt8.Text = Bt9.Text
            Bt9.Text = ""
EndIf
        Berhasil()
EndSub

PrivateSub Berhasil()
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
MessageBox.Show("Selamat Anda Berhasil")
EndIf
EndSub

PrivateSub Btacak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btacak.Click
        Kode_randomisasi()
EndSub

EndClass

sekian, terima kasih.......