04 Mei 2012

Visual Basic - Membuat game tebak warna sederhana.

Buatlah tampilan seperti di bawah ini:


Berikut script code untuk membuat game sederhana di atas:
Note : pada bagian timer jangan lupa diisi interval

 ---------------------------------------------------------------------------------------------

Private Sub Command1_Click()
If Command1.Caption = "Stop" Then Timer1.Enabled = False If (O1.Value = True) And (Label2.BackColor = vbRed) Then
           MsgBox "Selamat Tebakan Anda Tepat (^_^)", , "CONGRATULATION" ElseIf (O2.Value = True) And (Label3.BackColor = vbYellow) Then
           MsgBox "Selamat Tebakan Anda Tepat (^_^)", , "CONGRATULATION" ElseIf (O3.Value = True) And (Label4.BackColor = vbGreen) Then
           MsgBox "Selamat Tebakan Anda Tepat (^_^)", , "CONGRATULATION"
 Else
           MsgBox "Tebakan Anda Belum Tepat" + vbCrLf + "Silahkan Coba Lagi.", , "YOU LOSE"
 End If

----------------------------------------------------------------------------------------------

Command1.Caption = "Start"
Else
           Timer1.Enabled = True
           Command1.Caption = "Stop"
End If
End Sub

----------------------------------------------------------------------------------------------

Private Sub Command2_Click()
End
End Sub 

---------------------------------------------------------------------------------------------

Private Sub Form_Load()
Me.Width = 10
End Sub 

----------------------------------------------------------------------------------------------

Private Sub Timer1_Timer()
If Label2.BackColor = vbRed Then
           Label2.BackColor = &H8000000F
           Label3.BackColor = vbYellow
           Label4.BackColor = &H8000000F
ElseIf Label3.BackColor = vbYellow Then
           Label2.BackColor = &H8000000F
           Label3.BackColor = &H8000000F
           Label4.BackColor = vbGreen
Else:
           Label4.BackColor = vbGreen
                   Label2.BackColor = vbRed
                   Label3.BackColor = &H8000000F
                   Label4.BackColor = &H8000000F
 End If
End Sub

----------------------------------------------------------------------------------------------

Private Sub Timer2_Timer()
If Label1.Visible = True Then
Label1.Visible = False
Else
Label1.Visible = True
End If
End Sub 

----------------------------------------------------------------------------------------------

Private Sub Timer3_Timer()
Me.Width = Me.Width + 100
Tengah
If Me.Width >= 6200 Then
        Timer3.Enabled = False
        Tengah
End If
End Sub 

----------------------------------------------------------------------------------------------

Public Sub Tengah()
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
End Sub

 ----------------------------------------------------------------------------------------------

0 komentar:

Posting Komentar

Template by:

Free Blog Templates