PDA

Click to See Complete Forum and Search --> : Help on game


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.

NoteMe
Nov 26th, 2002, 09:39 AM
So here is a link and i posted the form image and here is the code.

Link???
Form image???

Can you please just upload your code, so we can look at it....(zip it).

archlas86
Dec 3rd, 2002, 05:39 PM
Alright here is the zip file

alkatran
Dec 3rd, 2002, 06:10 PM
Ok, here's a way to do it, use this as a reference to help you out.

oh, use [*vbcode] without the * to do this, and [*/vbcode) to stop it


'this assumes there's 10 command buttons
dim names(0 to 4)
dim combutton(0 to 9) as string
dim turned as byte
dim messups as integer 'how many times the player misses
dim matches as integer 'how many matches the player has

private sub form_load
dim a as byte
'set the names to whatever, add more if you want, just have 2x
'as many command buttons
names(0) = "whatever0"
names(1) = "whatever1"
names(2) = "whatever2"
names(3) = "whatever3"
names(4) = "whatever4"

do until a = 10
'picks a random number between 0 and 9
b = int(rnd *10)
'This checks if the commandbutton has been assigned a name
'yet, int(a/2) makes 2 command buttons get same thing so you
'can have matches
if combutton(b) = "" then combutton(b) = names(int(a/2)): a = a + 1
loop

end sub

Private sub Commands_click(index as integer)
'Have an array of command buttons named commands
'this sub is for when a button is clicked
Commands(index).caption = ComButton(index)
'if nothing else is turned, then remember this button
If Turned = 0 then turned = Index
'if something else is flipped, check if its the same, if it is, disable both
If Turned > 0 and Commands(index).caption = Commands(Turned).caption then Commands(index).enabled = false: Commands(Turned).enabled = false:matches = matches + 1
'if its not, set them back to normal
If Turned > 0 and not Commands(index).caption = Commands(Turned).caption then Commands(index).caption = "": Commands(turned).caption = "": turned = 0:messups = messups + 1

'now, to see if he's won or lost..
'put the number of possibilities here, if its more then 5
if matches => 5 then msgbox "you win!": end
'how many times they can get it wrong.. you might want more then 5
if messups > 5 then msgbox "you lose!: end
end sub


Btw, i made this up on the spot here, so theres no guaranties about errors etc... maybe I should save it... heh

KingArthur
Dec 4th, 2002, 07:10 AM
I have built this memory games ages ago hope it will help you

NoteMe
Dec 4th, 2002, 07:14 AM
Originally posted by KingArthur
I have built this memory games ages ago hope it will help you

What this.....

CrazedWombat
Dec 4th, 2002, 04:46 PM
heheheh go kingarthur...er..code? or program? shizznits

archlas86
Dec 4th, 2002, 09:42 PM
Okay alkatran that didn't work at all. But for real can anyone help me with the existing code i have

NoteMe
Dec 5th, 2002, 05:11 AM
OK, I'm not that good in afican flags ;) but I think it works now....you have switced some of the labels with som of the pictureboxes....;)

alkatran
Dec 5th, 2002, 05:15 AM
sorry, guess I made a mistake, like it said in post, I made it up on the spot.. anyone see my error?? (its about 4 posts up)

NoteMe
Dec 5th, 2002, 05:18 AM
Originally posted by alkatran
sorry, guess I made a mistake, like it said in post, I made it up on the spot.. anyone see my error?? (its about 4 posts up)

If you read my post...it was nothing wrog with his code, it was he switching labels and pictureboxes....

archlas86
Dec 5th, 2002, 08:28 AM
Aight i see what the problem was with the names and the pictures. Man i can't belevie i didn't see that. Well i got that fixed and i got it where when you click the box the flag comes up and the name shows but one thing that I am having a lot of trouble with is making them dissappear after about 2 seconds. Any Ideas?

NoteMe
Dec 5th, 2002, 08:42 AM
I have made that work. And I have attached a working sample. But don't use the code. Use it as a reference. That is the way you learn...

What I did, was making a "global" variable that holds the index of the picture selected. Then when you click a picture. The index of that picture is signed to a variable long (called toClose). Then a timer is enabled. The timer interval is set to 2000 (2sec). Then when the timer event occurs, it closes the picture.

Post again if you have problems with my code :)

archlas86
Dec 5th, 2002, 05:53 PM
Aight well i read over the code and i see how you got it to work. That is pretty cool man. But i noticed a couple of errors. First when you click the picture box the name also comes up below it(i made an adjustment to where the name's visibility = false and then when you click the pic box it shows up) but i can't make it go away. So that is one problem. And then also there are two labels on the side called lblPick1 and lblPick2. And lblPick1 has to display the first pick and then lblPick2 has to display the second pick. Below i got the newley furnished memory. I just added the visibility = false to the lblFlagName. Aight

NoteMe
Dec 5th, 2002, 06:03 PM
OK, I made the Label disapear after 2sec, and you can see in the first label on the right the name of the flag you clicked on. But I don't want to do the whole game for you, so you have to do the second Label on your own...

You will have to use an if sentence to see if you already have clicked an other one...post if you have more problems...but I think this is so simple so I think you can do tjis on your own...

H-Zence
Dec 7th, 2002, 03:52 PM
Originally posted by archlas86
And i ran into a problem. I don't know how to do it.

lolololoololololol

roflroflrofl

then maybe u should learn vb first!

sorry i couldnt help myself...

NoteMe
Dec 7th, 2002, 06:44 PM
Originally posted by H-Zence
lolololoololololol

roflroflrofl

then maybe u should learn vb first!

sorry i couldnt help myself...


I can see what you are meaning, and I do think some of the same thoughts...but I don't think that it's necessary post your thoughts like that....if you would tell him to learn VB before making games, then tell him then and don't make fun of those who are not as good as you. Because I know that you are not a newbie anymore, but you once was. So try to be kind to the neebies, or don't post at all...that is my thoughts about this case...;)