Memory Game... need help!

Status
Not open for further replies.

Legion2005

In Runtime
Messages
119
Ok, I also have a friend who needs help with a memory program (the flip two cards and match them memory card game)...

"I have the entire game nearly done except for one major problem. I have it so there are 16 cards... 8 matches total. At the form load the cards are randomly shuffled and placed... face down. Now I need to use the flag variable blnFirstTurn to determine when I click a card if it's my first card or second card turned over. At the beginning, the flag is true. After the first card is picked, it's changed to false. The cards are in a control array, and the variable intFirstPick is set equal to the Index of the control. At the end of the procedure blnFirstTurn is set to false. Then when it is clicked again, an If statement calls a sub procedure to test for a match. My problem is that when I click the first and second cards, it works. Then the second card I picked is being saved like it's the first card picked for the next turn. Can anyone help and maybe give me some helpful code?"
 
When you say first turn, you mean first turn in a pair, right? So you'd pick two cards, and then when you pick another card it's considered the "first turn"?

If so, why not just use:

If blnFirstTurn = True Then
blnFirstTurn = False
Else
blnFirstTurn = True
End If

(This would be in the procedure called when you click on a card) I'm not sure if this is even what you're talking about, but a look at the code that isn't working would help. :)
 
Yeah, same here. Could you give a step by step example and the vlues of blnFirstTurn for each step?

I think what you want is
Code:
If blnFirstTurn=False Then
[2nd card code here]
blnFirstTurn=True ` <---Did you forget this line?
End If
 
I made a memory game! here is my code. it is a little n00bish but it was teh first second game i ever made >.>

Code:

-----------------------------------------------------------------------------------
Option Explicit
Const imgBoat As String = "/BOAT.GIF"
Const imgCar As String = "/CAR.JPG"
Const imgHawk As String = "/hawk.jpg"
Const imgZ As String = "/z.JPG"
Const imgDbz As String = "/DBZ.jpg"
Const imgPenny As String = "/PENNY.JPG"
Const imgTile As String = "/TILE.JPG"
Dim Face(12) As String
Dim IntrNd As Integer
Dim IntcoUnt As Integer
Dim strPick1
Dim strPick2
Dim varIndexpick1
Dim varindexpiCk2
Private Sub cmdend_Click()
End
End Sub

Private Sub cmdnewgame_Click()
Call Start_Game
Call Shuffle_Cards
End Sub

Private Sub Form_Load()
Call Start_Game
Call Shuffle_Cards

End Sub
Private Sub Swap_CaRds(Curcard As Integer, rNdCard As Integer)
Dim strtemp As String
strtemp = Face(Curcard)
Face(Curcard) = Face(rNdCard)
Face(rNdCard) = strtemp
End Sub
Private Sub Start_Game()
For IntcoUnt = 0 To 11
Image1(IntcoUnt).Visible = True
Image1(IntcoUnt).Picture = LoadPicture(App.Path & imgTile)
Next IntcoUnt
End Sub
Private Function Shuffle_Cards()
Face(0) = imgBoat
Face(1) = imgBoat
Face(2) = imgCar
Face(3) = imgCar
Face(4) = imgHawk
Face(5) = imgHawk
Face(6) = imgDbz
Face(7) = imgDbz
Face(8) = imgZ
Face(9) = imgZ
Face(10) = imgPenny
Face(11) = imgPenny
For IntcoUnt = 0 To 11
Randomize
IntrNd = Int(Rnd * 12)
Call Swap_CaRds(IntcoUnt, IntrNd)
Next
End Function
Private Sub check_enD_gaMe()
Dim X
Dim over As Boolean
over = True
For X = 0 To 11
If Image1(X).Visible = True Then
over = False
End If
Next
If over = True Then
MsgBox "gameover"
End If
End Sub
Private Sub delay_clIck()
Dim oOoOoOo
For oOoOoOo = 1 To 50000
DoEvents
Next
End Sub
Public Function RandColor(obj As Object)
Dim c(2) As Byte
Dim X As Integer
For X = 0 To 2
Randomize
c(X) = Int((255 - 0 + 1) * Rnd + 0)
Next X
obj.BackColor = RGB(c(0), c(1), c(2))
End Function
Private Sub Image1_Click(Index As Integer)
Call RandColor(frmMemory)
Image1(Index).Picture = LoadPicture(App.Path & Face(Index))
If strPick1 = "" Then
strPick1 = Face(Index)
varIndexpick1 = Index
Else
If Index <> varIndexpick1 Then
strPick2 = Face(Index)
varindexpiCk2 = Index
Else
Exit Sub
End If
End If
If strPick2 <> "" Then
If strPick1 = strPick2 Then
Call delay_clIck
Image1(varIndexpick1).Visible = False
Image1(varindexpiCk2).Visible = False
strPick1 = ""
strPick2 = ""
Call check_enD_gaMe
Else
Call delay_clIck
Image1(Index) = LoadPicture(App.Path & imgTile)
Image1(varIndexpick1) = LoadPicture(App.Path & imgTile)
varIndexpick1 = ""
strPick1 = ""
strPick2 = ""
End If
Else
Exit Sub
End If

End Sub
------------------------------------------------------------------------------------------

just follow that and you should find what ever you needed
if you paste it into vb it will be easlier to read :D
 
Status
Not open for further replies.
Back
Top Bottom