Solved

Problem with game creation

Posted on 2001-06-18
13
182 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 52

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 52

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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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 52

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 52

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 52

Accepted Solution

by:
Ryan Chong earned 50 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 52

Expert Comment

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

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

687 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