Kamis, Oktober 15, 2009

Visual Basic - Game

Yang mo Bikin Game uji kecepatan mengetik nih kodenya.

Option Explicit
Dim c As Long
Dim First As Boolean
Dim Best As Long

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()
c = 0
Best = 0
First = True
End Sub

Private Sub Command1_Click()
c = 0
Best = 0
First = True
Timer1.Enabled = False
Text1.Text = ""
Text1.SetFocus
Timer1.Enabled = False
Waktu.Caption = "Waktu :"
End Sub


Private Sub Text1_KeyPress(KeyAscii As Integer)
If First Then
Timer1.Enabled = True
Timer1.Interval = 1
End If
First = False
If KeyAscii = 13 Then
If UCase(Text1.Text) = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Then
Timer1.Enabled = False
MsgBox "Waktu             :" & Str(c / 100) & " Detik" & 
vbCrLf & "Kecepatan      : " & 26 / (c / 100) & " Huruf/Detik"
If Best = 0 Or c < Best Then Best = c
BestTime.Caption = "Best Time: " & (Best / 100) & " Detik"
c = 0
First = True
Text1.Text = ""
Text1.SetFocus
Timer1.Enabled = False
Waktu.Caption = "Waktu :"
Else
MsgBox "Masih ada yang salah!" & vbCrLf & "Silahkan anda ulang...!"
End If
End If
End Sub

Private Sub Timer1_Timer()
c = c + 1
Waktu.Caption = "Waktu :" & Str(c / 100) & " Detik"
End Sub

jangan lupa name Label2 ganti jadi Waktu and Label3 jadi BestTime.