Results 1 to 17 of 17

Thread: Help on game

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Location
    America
    Posts
    5

    Question Help on game

    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 ExFlag 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.
    I am teh anit-programmer

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    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).

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Location
    America
    Posts
    5
    Alright here is the zip file
    Attached Files Attached Files
    I am teh anit-programmer

  4. #4
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860

    Red face hmm

    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

    VB Code:
    1. 'this assumes there's 10 command buttons
    2. dim names(0 to 4)
    3. dim combutton(0 to 9) as string
    4. dim turned as byte
    5. dim messups as integer 'how many times the player misses
    6. dim matches as integer 'how many matches the player has
    7.  
    8. private sub form_load
    9.  dim a as byte
    10.  'set the names to whatever, add more if you want, just have 2x
    11.  'as many command buttons
    12.  names(0) = "whatever0"
    13.  names(1) = "whatever1"
    14.  names(2) = "whatever2"
    15.  names(3) = "whatever3"
    16.  names(4) = "whatever4"
    17.  
    18.  do until a = 10
    19.   'picks a random number between 0 and 9
    20.   b = int(rnd *10)
    21.   'This checks if the commandbutton has been assigned a name
    22.   'yet, int(a/2) makes 2 command buttons get same thing so you
    23.   'can have matches
    24.   if combutton(b) = "" then combutton(b) = names(int(a/2)): a =  a  + 1
    25.  loop
    26.  
    27. end sub
    28.  
    29. Private sub Commands_click(index as integer)
    30.  'Have an array of command buttons named commands
    31.  'this sub is for when a button is clicked
    32.  Commands(index).caption = ComButton(index)
    33.  'if nothing else is turned, then remember this button
    34.  If Turned = 0 then turned = Index
    35.  'if something else is flipped, check if its the same, if it is, disable both
    36.  If Turned > 0 and Commands(index).caption = Commands(Turned).caption then Commands(index).enabled = false: Commands(Turned).enabled = false:matches = matches + 1
    37.  'if its not, set them back to normal
    38.  If Turned > 0 and not Commands(index).caption = Commands(Turned).caption then Commands(index).caption = "": Commands(turned).caption = "": turned = 0:messups = messups + 1
    39.  
    40. 'now, to see if he's won or lost..
    41. 'put the number of possibilities here, if its more then 5
    42. if matches => 5 then msgbox "you win!": end
    43. 'how many times they can get it wrong.. you might want more then 5
    44. if messups > 5 then msgbox "you lose!: end
    45. end sub

    Btw, i made this up on the spot here, so theres no guaranties about errors etc... maybe I should save it... heh
    Don't pay attention to this signature, it's contradictory.

  5. #5
    Addicted Member
    Join Date
    Apr 2002
    Location
    Israel
    Posts
    152
    I have built this memory games ages ago hope it will help you

  6. #6
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by KingArthur
    I have built this memory games ages ago hope it will help you
    What this.....

  7. #7
    Member CrazedWombat's Avatar
    Join Date
    Oct 2002
    Location
    asylum
    Posts
    47
    heheheh go kingarthur...er..code? or program? shizznits
    Wombat

    "I like to go to the schoolyard where i can watch the little kids jumping and screaming....but they dont know im using blanks"

    "Before you set yourself on fire, remember to take off your shoes... nothing smells worse than burning rubber."

    "They advertise that certain laundry detergents can take blood stains out of clothes, i say that if you have blood stains on your clothes, maybe your laundry is the least of your worries."

    Sometimes when I'm driving around I see a sign that says, CAUTION: SMALL CHILDREN PLAYING. I slow down, and then it occurs to me: I'm not afraid of small children.

    "My programs dont have bugs, they have random features" - MisianThrop

    "The good thing about our ticket to the future is that it's always blank" - Trigun

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Location
    America
    Posts
    5

    Question

    Okay alkatran that didn't work at all. But for real can anyone help me with the existing code i have
    Attached Files Attached Files
    I am teh anit-programmer

  9. #9
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    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....
    Attached Files Attached Files

  10. #10
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860

    Unhappy :(

    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)
    Don't pay attention to this signature, it's contradictory.

  11. #11
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: :(

    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....

  12. #12

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Location
    America
    Posts
    5

    Question

    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?
    I am teh anit-programmer

  13. #13
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    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
    Attached Files Attached Files

  14. #14

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Location
    America
    Posts
    5
    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
    Attached Files Attached Files
    I am teh anit-programmer

  15. #15
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    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...
    Attached Files Attached Files

  16. #16
    Lively Member H-Zence's Avatar
    Join Date
    Jul 2002
    Posts
    94

    Re: Help on game

    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...
    www.mindset1.com
    Religious Debate Forums

  17. #17
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Re: Help on game

    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width