archlas86
Nov 26th, 2002, 08:56 AM
Alright well i have started programming with the wonderful language of VB. And i am now making a memory game. And i ran into a problem. I don't know how to do it. I got the basic stuff down. Here is how it works. When the form loads up there is 16 yellow squares and when you click on one a flag comes up. Now you go and try to find the matching flag in one of the other 15 spaces. And there are a couple of problems that i am having. The first is that i can't get the flag to match up with the name below it Ex:(Flag is America -- Name is Canada) and then another problem that i am having is that when the flags do match they don't dissapear. So here is a link and i posted the form image and here is the code.
Option Explicit
Const conMaxMatches As Integer = 8
Dim blnFirstTurn As Boolean
Dim intNumMatches As Integer
Dim intFirstPick As Integer
Dim Index As Integer
Dim strCountry As Integer
Dim i As Integer
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdStart_Click()
Call swap_names
Call load_names
Call set_up_blanks
End Sub
Private Sub Form_Load()
blnFirstTurn = True
intNumMatches = 0
lblMsg.Caption = "Click a Box"
Call load_names
Call set_up_blanks
Call swap_names
End Sub
Private Function load_names()
lblFlagName(0).Caption = "Ethiopia.bmp"
lblFlagName(8).Caption = "Ethiopia.bmp"
lblFlagName(1).Caption = "Ghana.bmp"
lblFlagName(9).Caption = "Ghana.bmp"
lblFlagName(2).Caption = "Guinea.bmp"
lblFlagName(10).Caption = "Guinea.bmp"
lblFlagName(3).Caption = "Malagass.bmp"
lblFlagName(11).Caption = "Malagass.bmp"
lblFlagName(4).Caption = "Morocco.bmp"
lblFlagName(12).Caption = "Morocco.bmp"
lblFlagName(5).Caption = "Namibia.bmp"
lblFlagName(13).Caption = "Namibia.bmp"
lblFlagName(6).Caption = "Senegal.bmp"
lblFlagName(14).Caption = "Senegal.bmp"
lblFlagName(7).Caption = "Sierleon.bmp"
lblFlagName(15).Caption = "Sierleon.bmp"
End Function
Private Function set_up_blanks()
For i = 0 To 15
picFlag(i).Picture = LoadPicture("blank.bmp")
picFlag(i).Visible = True
picFlag(i).Enabled = True
Next i
End Function
Private Function swap_names()
Dim strName As String
Dim intSwap1 As Integer
Dim intSwap2 As Integer
Dim i As Integer
Randomize
For i = 0 To 15 'swap names 16 times
intSwap1 = Int(16 * Rnd) 'generate two random places
intSwap2 = Int(16 * Rnd) 'to swap
'this code performs the swap
strName = lblFlagName(intSwap1).Caption
lblFlagName(intSwap1).Caption = lblFlagName(intSwap2).Caption
lblFlagName(intSwap2).Caption = strName
Next i
End Function
Private Function test_for_match()
End Function
Public Sub get_flag_name()
End Sub
Private Sub picFlag_Click(Index As Integer)
picFlag(Index).Picture = LoadPicture(lblFlagName(Index))
blnFirstTurn = True
intFirstPick = Index
End Sub
Thanks.
Option Explicit
Const conMaxMatches As Integer = 8
Dim blnFirstTurn As Boolean
Dim intNumMatches As Integer
Dim intFirstPick As Integer
Dim Index As Integer
Dim strCountry As Integer
Dim i As Integer
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdStart_Click()
Call swap_names
Call load_names
Call set_up_blanks
End Sub
Private Sub Form_Load()
blnFirstTurn = True
intNumMatches = 0
lblMsg.Caption = "Click a Box"
Call load_names
Call set_up_blanks
Call swap_names
End Sub
Private Function load_names()
lblFlagName(0).Caption = "Ethiopia.bmp"
lblFlagName(8).Caption = "Ethiopia.bmp"
lblFlagName(1).Caption = "Ghana.bmp"
lblFlagName(9).Caption = "Ghana.bmp"
lblFlagName(2).Caption = "Guinea.bmp"
lblFlagName(10).Caption = "Guinea.bmp"
lblFlagName(3).Caption = "Malagass.bmp"
lblFlagName(11).Caption = "Malagass.bmp"
lblFlagName(4).Caption = "Morocco.bmp"
lblFlagName(12).Caption = "Morocco.bmp"
lblFlagName(5).Caption = "Namibia.bmp"
lblFlagName(13).Caption = "Namibia.bmp"
lblFlagName(6).Caption = "Senegal.bmp"
lblFlagName(14).Caption = "Senegal.bmp"
lblFlagName(7).Caption = "Sierleon.bmp"
lblFlagName(15).Caption = "Sierleon.bmp"
End Function
Private Function set_up_blanks()
For i = 0 To 15
picFlag(i).Picture = LoadPicture("blank.bmp")
picFlag(i).Visible = True
picFlag(i).Enabled = True
Next i
End Function
Private Function swap_names()
Dim strName As String
Dim intSwap1 As Integer
Dim intSwap2 As Integer
Dim i As Integer
Randomize
For i = 0 To 15 'swap names 16 times
intSwap1 = Int(16 * Rnd) 'generate two random places
intSwap2 = Int(16 * Rnd) 'to swap
'this code performs the swap
strName = lblFlagName(intSwap1).Caption
lblFlagName(intSwap1).Caption = lblFlagName(intSwap2).Caption
lblFlagName(intSwap2).Caption = strName
Next i
End Function
Private Function test_for_match()
End Function
Public Sub get_flag_name()
End Sub
Private Sub picFlag_Click(Index As Integer)
picFlag(Index).Picture = LoadPicture(lblFlagName(Index))
blnFirstTurn = True
intFirstPick = Index
End Sub
Thanks.