July 03, 2020, 01:53:23 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
   Home   Help Search Login Register  
Pages: [1]
Author Topic: Mix and match (need a tiny bit of help)  (Read 2243 times)
Posts: 37

« on: April 13, 2008, 04:37:27 PM »

This isn't in QuickBasic it is actually in Visual Basic but I am hoping someone can help me.  It a memory game where you try and select the like cards.  I am having trouble making sure the user has selected one card and if the next card he/she selects is either a match or not a match here is the code.

Option Explicit
Dim blnFirstTurn As Boolean
Dim intNumMatches As Integer

Private Sub Form_Load()
    blnFirstTurn = True
    intNumMatches = 0
    Call set_up_blanks
    Call load_names
    Call swap_names
    frmMemory.Top = (Screen.Height - frmMemory.Height) / 2
    frmMemory.Left = (Screen.Width - frmMemory.Width) / 2
End Sub

Private Sub imgCard_Click(Index As Integer)
    imgCard(Index).Picture = LoadPicture(lblCardName(Index))
End Sub

Private Sub load_names()
    lblCardName(0).Caption = "I:\vb\memory\alienware_new_logo01.jpg"
    lblCardName(8).Caption = "I:\vb\memory\alienware_new_logo01.jpg"
    lblCardName(1).Caption = "I:\vb\memory\dell.gif"
    lblCardName(9).Caption = "I:\vb\memory\dell.gif"
    lblCardName(2).Caption = "I:\vb\memory\hp-logo.jpg"
    lblCardName(10).Caption = "I:\vb\memory\hp-logo.jpg"
    lblCardName(3).Caption = "I:\vb\memory\logo-gateway.gif"
    lblCardName(11).Caption = "I:\vb\memory\logo-gateway.gif"
    lblCardName(4).Caption = "I:\vb\memory\intel-logo.jpg"
    lblCardName(12).Caption = "I:\vb\memory\intel-logo.jpg"
    lblCardName(5).Caption = "I:\vb\memory\amd.gif"
    lblCardName(13).Caption = "I:\vb\memory\amd.gif"
    lblCardName(6).Caption = "I:\vb\memory\nvidia_logo.jpg"
    lblCardName(14).Caption = "I:\vb\memory\nvidia_logo.jpg"
    lblCardName(7).Caption = "I:\vb\memory\ati_logo_1204_rgb1.jpg"
    lblCardName(15).Caption = "I:\vb\memory\ati_logo_1204_rgb1.jpg"
End Sub

Private Sub set_up_blanks()
    Dim intX As Integer
    For intX = 0 To 15
        imgCard(intX).Picture = LoadPicture("I:\vb\memory\mego_blank.jpg")
    Next intX
End Sub

Public Sub swap_names()
    Dim I As Integer
    Dim strName As String
    Dim intSwap1 As Integer
    Dim intSwap2 As Integer
    For I = 1 To 16
        intSwap1 = Int(16 * Rnd)
        intSwap2 = Int(16 * Rnd)
        strName = lblCardName(intSwap1).Caption
        lblCardName(intSwap1).Caption = lblCardName(intSwap2).Caption
        lblCardName(intSwap2).Caption = strName
    Next I
End Sub

I was thinking that using blnFirstTurn (value can be true or false) which is automatically set to true on the form load will be set to false on the click of the card and then when the user clicks the next card (this is part im having a bit of trouble with) it sets it to false and resets the card.  which I think would look something like.  This is without all the other code btw.

blnFirstTurn = true

Private Sub imgCard_Click(Index As Integer)
    count = 1
    if count = 1 then
    blnFirstTurn = false
    end if
    if cardname = cardname then
    match is true
    match is not true
    count = count - 1
end sub

something like the above (which I don't think will work.  Any help is much appreciated.
Posts: 37

« Reply #1 on: April 14, 2008, 07:45:20 PM »

Never mind found a solution

Private Sub imgCard_Click(Index As Integer)
    imgCard(Index).Picture = LoadPicture(lblCardName(Index))
    imgCard(Index).Enabled = False
    If blnFirstTurn = True Then
        intFirstPick = imgCard(Index).Index
        blnFirstTurn = False
        intSecondPick = imgCard(Index).Index
        Call test_for_match
    End If
End Sub

Public Sub test_for_match()
    Dim intY As Integer
    Static intnumMatches As Integer
    intMaxMatches = 8
    If lblCardName(intFirstPick) = lblCardName(intSecondPick) Then
        lblMsg.Caption = "Match"
        intnumMatches = intnumMatches + 1
        Call delay(1)
        imgCard(intFirstPick).Enabled = False
        imgCard(intSecondPick).Enabled = False
        imgCard(intFirstPick).Visible = False
        imgCard(intSecondPick).Visible = False
        blnFirstTurn = True
        lblMsg.Caption = "No Match"
        Call delay(1)
        imgCard(intFirstPick).Picture = LoadPicture("I:\vb\memory\mego_blank.jpg")
        imgCard(intSecondPick).Picture = LoadPicture("I:\vb\memory\mego_blank.jpg")
        blnFirstTurn = True
        imgCard(intFirstPick).Enabled = True
        imgCard(intSecondPick).Enabled = True
        imgCard(intFirstPick).Visible = True
        imgCard(intSecondPick).Visible = True
    End If
    If intnumMatches = intMaxMatches Then
        lblMsg.Caption = "Game Over"
        lblMsg.Caption = "Click a Box"
    End If
End Sub
Pages: [1]
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!