paulzeb
asked on
Problem with game creation
I am in the process of making a Tic-Tac-Toe based game. This is the code I am using>
Private Sub Image1_Click(Index As Integer)
If Player = 1 Then
Image1(Index).Picture = O.Picture
Player = 2
Else
Image1(Index).Picture = X.Picture
Player = 1
End If
End Sub
This is the problem:
After a player makes a mark (an X or O) on a box, the other player can make a mark over it, erasing the mark that was already there. How do I fix this?
Private Sub Image1_Click(Index As Integer)
If Player = 1 Then
Image1(Index).Picture = O.Picture
Player = 2
Else
Image1(Index).Picture = X.Picture
Player = 1
End If
End Sub
This is the problem:
After a player makes a mark (an X or O) on a box, the other player can make a mark over it, erasing the mark that was already there. How do I fix this?
Then set arrayCheck(Index) = True after image's clicked
Try this no arrays to create
Private Sub Image1_Click(Index As Integer)
If Image1(Index).Tag = 1 then exit sub
If Player = 1 Then
Image1(Index).Picture = O.Picture
Image1(Index).Tag = 1
Player = 2
Else
Image1(Index).Picture = X.Picture
Image1(Index).Tag = 1
Player = 1
End If
End Sub
When game is done
For a = 0 to Image1.Ubound
Image1(Index).Tag = 0
Next a
Private Sub Image1_Click(Index As Integer)
If Image1(Index).Tag = 1 then exit sub
If Player = 1 Then
Image1(Index).Picture = O.Picture
Image1(Index).Tag = 1
Player = 2
Else
Image1(Index).Picture = X.Picture
Image1(Index).Tag = 1
Player = 1
End If
End Sub
When game is done
For a = 0 to Image1.Ubound
Image1(Index).Tag = 0
Next a
STORE IT IN A MULTI DIM ARRAY REPRESENTING THE GRID
cheers andy
cheers andy
ASKER
Sorry guys, but all of the answers above did not work. It just did the same thing it's doing now.
Hi, The code below ensure players cannot click the same place twice in a single game..
Private Sub Image1_Click(Index As Integer)
if arrayCheck(Index) = True Then Exit Sub
If Player = 1 Then
Image1(Index).Picture = O.Picture
Player = 2
Else
Image1(Index).Picture = X.Picture
Player = 1
End If
arrayCheck(Index) = True
End Sub
Private sub Form_load()
for i = LBound(arrayCheck) to Ubound(arrayCheck)
arrayCheck(i) = False
Next i
End sub
Private Sub Image1_Click(Index As Integer)
if arrayCheck(Index) = True Then Exit Sub
If Player = 1 Then
Image1(Index).Picture = O.Picture
Player = 2
Else
Image1(Index).Picture = X.Picture
Player = 1
End If
arrayCheck(Index) = True
End Sub
Private sub Form_load()
for i = LBound(arrayCheck) to Ubound(arrayCheck)
arrayCheck(i) = False
Next i
End sub
ASKER
I copyed and pasted this code. The code in Form Load doesn't work.
Disable the image control after setting its picture:
Image1(Index).enabled = false
If Player = 1 Then
Image1(Index).Picture = O.Picture
Player = 2
Else
Image1(Index).Picture = X.Picture
Player = 1
End If
' add
Image1(Index).enabled = false
Image1(Index).enabled = false
If Player = 1 Then
Image1(Index).Picture = O.Picture
Player = 2
Else
Image1(Index).Picture = X.Picture
Player = 1
End If
' add
Image1(Index).enabled = false
Hi Paul, Of course it it not working, we must define it first:
Option Explicit
Dim arrayCheck(8) as Boolean
..
Option Explicit
Dim arrayCheck(8) as Boolean
..
>>>Sorry guys, but all of the answers above did not work. It just did the same thing it's doing now
What error did you get using the .Tag property???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This code did exactly what I needed. Thank you.
Hi Paul, glad can help you.
Something like
if arrayCheck(Index) = True then exit sub ..
'Hope wil help.