Qbasicnews.com
November 20, 2019, 11:37:17 AM *
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]
  Print  
Author Topic: Mix and match (need a tiny bit of help)  (Read 2137 times)
Tia
Member
*
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.

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

Code:
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
    else
    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.
Logged
Tia
Member
*
Posts: 37


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

Never mind found a solution

Code:
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
    Else
        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
    Else
        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"
    Else
        lblMsg.Caption = "Click a Box"
    End If
End Sub
Logged
Pages: [1]
  Print  
 
Jump to:  

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