Selasa, 12 Januari 2010

Game TicTacToe


Dim sp1 As Boolean 'Player 1 Var

Dim sp2 As Boolean 'Player 2 Var
Dim p1p As Integer 'Player 1 Points
Dim p2p As Integer 'Player 2 Points

Function lösch()
'Function buat semua Invisible
O1.Visible = False
O2.Visible = False
O3.Visible = False
O4.Visible = False
O5.Visible = False
O6.Visible = False
O7.Visible = False
O8.Visible = False
O9.Visible = False

X1.Visible = False
X2.Visible = False
X3.Visible = False
X4.Visible = False
X5.Visible = False
X6.Visible = False
X7.Visible = False
X8.Visible = False
X9.Visible = False
End Function
Private Sub Image1_Click()

If sp1 = True And O1.Visible = False Then
X1.Visible = True
sp2 = True
sp1 = False
Exit Sub
End If

If sp2 = True And X1.Visible = False Then
O1.Visible = True
sp1 = True
sp2 = False
Exit Sub
End If

End Sub

Private Sub Form_Load()
'Set Player1 Maen
sp1 = True
sp2 = False

'Buat Semua Invisible
X1.Visible = False
X2.Visible = False
X3.Visible = False
X4.Visible = False
X5.Visible = False
X6.Visible = False
X7.Visible = False
X8.Visible = False
X9.Visible = False

O1.Visible = False
O2.Visible = False
O3.Visible = False
O4.Visible = False
O5.Visible = False
O6.Visible = False
O7.Visible = False
O8.Visible = False
O9.Visible = False
End Sub

Private Sub Image2_Click()

'Klik utk Visible
If sp1 = True And O2.Visible = False Then
X2.Visible = True
sp2 = True
sp1 = False
Exit Sub
End If

If sp2 = True And X2.Visible = False Then
O2.Visible = True
sp1 = True
sp2 = False
Exit Sub
End If

End Sub

Private Sub Image3_Click()

If sp1 = True And O3.Visible = False Then
X3.Visible = True
sp2 = True
sp1 = False
Exit Sub
End If

If sp2 = True And X3.Visible = False Then
O3.Visible = True
sp1 = True
sp2 = False
Exit Sub
End If

End Sub

Private Sub Image4_Click()

If sp1 = True And O4.Visible = False Then
X4.Visible = True
sp2 = True
sp1 = False
Exit Sub
End If

If sp2 = True And X4.Visible = False Then
O4.Visible = True
sp1 = True
sp2 = False
Exit Sub
End If

End Sub

Private Sub Image5_Click()

If sp1 = True And O5.Visible = False Then
X5.Visible = True
sp2 = True
sp1 = False
Exit Sub
End If

If sp2 = True And X5.Visible = False Then
O5.Visible = True
sp1 = True
sp2 = False
Exit Sub
End If

End Sub

Private Sub Image6_Click()
If sp1 = True And O6.Visible = False Then
X6.Visible = True
sp2 = True
sp1 = False
Exit Sub
End If

If sp2 = True And X6.Visible = False Then
O6.Visible = True
sp1 = True
sp2 = False
Exit Sub
End If

End Sub

Private Sub Image7_Click()
If sp1 = True And O7.Visible = False Then
X7.Visible = True
sp2 = True
sp1 = False
Exit Sub
End If

If sp2 = True And X7.Visible = False Then
O7.Visible = True
sp1 = True
sp2 = False
Exit Sub
End If

End Sub

Private Sub Image8_Click()
If sp1 = True And O8.Visible = False Then
X8.Visible = True
sp2 = True
sp1 = False
Exit Sub
End If

If sp2 = True And X8.Visible = False Then
O8.Visible = True
sp1 = True
sp2 = False
Exit Sub
End If

End Sub

Private Sub Image9_Click()
If sp1 = True And O9.Visible = False Then
X9.Visible = True
sp2 = True
sp1 = False
Exit Sub
End If

If sp2 = True And X9.Visible = False Then
O9.Visible = True
sp1 = True
sp2 = False
Exit Sub
End If

End Sub

Private Sub Timer1_Timer()
If sp1 = True Then Form1.MousePointer = 2
If sp2 = True Then Form1.MousePointer = 12
End Sub

Private Sub Timer2_Timer()
'Player X Menang??
If X1.Visible = True And X2.Visible = True And X3.Visible = True Then
MsgBox "Player X wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p1p = p1p + 1
Timer2.Enabled = True
End If

If X1.Visible = True And X4.Visible = True And X7.Visible = True Then
MsgBox "Player X wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p1p = p1p + 1
Timer2.Enabled = True
End If

If X1.Visible = True And X5.Visible = True And X9.Visible = True Then
MsgBox "Player X wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p1p = p1p + 1
Timer2.Enabled = True
End If

If X2.Visible = True And X5.Visible = True And X8.Visible = True Then
MsgBox "Player X wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p1p = p1p + 1
Timer2.Enabled = True
End If

If X3.Visible = True And X6.Visible = True And X9.Visible = True Then
MsgBox "Player X wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p1p = p1p + 1
Timer2.Enabled = True
End If

If X3.Visible = True And X5.Visible = True And X7.Visible = True Then
MsgBox "Player X wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p1p = p1p + 1
Timer2.Enabled = True
End If

If X4.Visible = True And X5.Visible = True And X6.Visible = True Then
MsgBox "Player X wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p1p = p1p + 1
Timer2.Enabled = True
End If

If X7.Visible = True And X8.Visible = True And X9.Visible = True Then
MsgBox "Player X wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p1p = p1p + 1
Timer2.Enabled = True
End If

'Player O Menang??
If O1.Visible = True And O2.Visible = True And O3.Visible = True Then
MsgBox "Player O wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p2p = p2p + 1
Timer2.Enabled = True
End If

If O1.Visible = True And O4.Visible = True And O7.Visible = True Then
MsgBox "Player O wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p2p = p2p + 1
Timer2.Enabled = True
End If

If O1.Visible = True And O5.Visible = True And O9.Visible = True Then
MsgBox "Player O wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p2p = p2p + 1
Timer2.Enabled = True
End If

If O2.Visible = True And O5.Visible = True And O8.Visible = True Then
MsgBox "Player O wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p2p = p2p + 1
Timer2.Enabled = True
End If

If O3.Visible = True And O6.Visible = True And O9.Visible = True Then
MsgBox "Player O wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p2p = p2p + 1
Timer2.Enabled = True
End If

If O3.Visible = True And O5.Visible = True And O7.Visible = True Then
MsgBox "Player O wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p2p = p2p + 1
Timer2.Enabled = True
End If

If O4.Visible = True And O5.Visible = True And O6.Visible = True Then
MsgBox "Player O wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p2p = p2p + 1
Timer2.Enabled = True
End If

If O7.Visible = True And O8.Visible = True And O9.Visible = True Then
MsgBox "Player O wins", vbOKOnly, "The End"
Timer2.Enabled = False
lösch
p2p = p2p + 1
Timer2.Enabled = True
End If

End Sub

Private Sub Timer3_Timer()
'Label Skor di Update
Label3.Caption = p1p
Label4.Caption = p2p
End Sub


vbgames6.homestead.com