?
Solved

Problem with game creation

Posted on 2001-06-18
13
Medium Priority
?
184 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

801 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