Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem with game creation

Posted on 2001-06-18
13
Medium Priority
?
187 Views
Last Modified: 2010-05-02
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?
0
Comment
Question by:paulzeb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +2
13 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6204998
Hi, create an array that save whether the place had been marked by any player.

Something like

if arrayCheck(Index) = True then exit sub ..

'Hope wil help.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6205003
Then set arrayCheck(Index) = True after image's clicked
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6205013
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

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

by:Microsoft
ID: 6205245
STORE IT IN A MULTI DIM ARRAY REPRESENTING THE GRID

cheers andy
0
 

Author Comment

by:paulzeb
ID: 6206595
Sorry guys, but all of the answers above did not work.  It just did the same thing it's doing now.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6206625
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

0
 

Author Comment

by:paulzeb
ID: 6206813
I copyed and pasted this code.  The code in Form Load doesn't work.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6206982
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
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6208815
Hi Paul, Of course it it not working, we must define it first:

Option Explicit
Dim arrayCheck(8) as Boolean

..
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6208822

>>>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???
0
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 200 total points
ID: 6208917
Hi guys, please allow me to post my complete code, thanks:

Dim arrayCheck(8) As Boolean
Dim i As Integer, Player As Byte

Private Sub Form_Load()
    For i = LBound(arrayCheck) To UBound(arrayCheck)
        arrayCheck(i) = False
    Next i
    Player = 1
End Sub

Private Sub Image1_Click(Index As Integer)
    If arrayCheck(Index) 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
0
 

Author Comment

by:paulzeb
ID: 6210915
This code did exactly what I needed.  Thank you.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6212656
Hi Paul, glad can help you.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question