Click here to Skip to main content
Click here to Skip to main content

Campaign Button Memory Game 2 (Random Placement, Time Limits)

, 23 Feb 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
This version of campaign button memory uses timers to limit the game time and to limit how long users see their selected images when the images don’t match. This version also randomly places the political buttons on the form so that the game can be played infinite times.

Introduction

This campaign button memory game part 2 is brought to you by www.pcbutton.com - (2004 campaign buttons, political buttons and memorabilia buttons).

This version of campaign button memory uses timers to limit the game time and to limit how long users see their selected images when the images don't match. This version also randomly places the political buttons on the form so that the game can be played infinite times.

When the user selects two campaign buttons, they get between 1-2 seconds to view them. Then if the two political buttons are the same, they stay visible, otherwise they disappear. The entire game is also running on a 30 second time limit. At the end of the 30-second time limit, if the user has not matched all of the campaign buttons, then he/she loses the game. If before the end of the 30-second time limit, the user matches all of the political buttons, then he/she wins the game. At the end of each game, the “Start Another Game” button appears so that the user can play another round.

Sample image

How are the Campaign Buttons Randomly Placed?

When the political button data (data.xml) is loaded, the campaign button nodes are pulled from random locations and placed at the end of the document. This is done 100 times and the data is only 12 nodes long so they are well randomized. If the political button data was well over 100 nodes long, then this logic would have to be modified to iterate more times.

Instantiate a document to hold the political button data:

Set pDoc = New MSXML2.DOMDocument

Load the political button data:

pDoc.Load "data.xml"

Iterate 100 times and randomly pull campaign buttons from the political button data and place them at the end of the document.

    Dim i As Integer
    For i = 0 To 100
        Dim nl As IXMLDOMNodeList
        Set nl = pDoc.selectNodes("./images/image")
        Dim iLen As Integer
        iLen = nl.length
        Dim iFirstNode As Integer
        iFirstNode = getRandLocation(iLen)
        Dim temp1 As MSXML2.IXMLDOMNode
        Set temp1 = nl.Item(iFirstNode)
        Dim newtemp1 As MSXML2.IXMLDOMNode
        Set newtemp1 = temp1.cloneNode(True)
        Dim imgs As MSXML2.IXMLDOMNode
        Set imgs = pDoc.selectSingleNode("./images")
        imgs.appendChild newtemp1
        imgs.removeChild temp1
    Next

How Does the Timing Work?

We are only using the timer to count one-second intervals and incrementing counters. The value of the counters since they were last reset determines how many seconds have passed. This approach has a resolution of one second but works for our purposes.

Private Sub tmrSecond_Timer()

If user has selected two campaign buttons:

If bStarted = True Then

If their time to view their two campaign buttons is up:

If intTimeLeft = difficulty Then

Then continue which will leave the campaign buttons uncovered if they are a match or hide them if they did not match.

        continue
        bStarted = False
    End If
    intTimeLeft = intTimeLeft + 1
Else
    intTimeLeft = 0
End If

If game started:

If bSecondsRemainingStarted = True Then

If time is up:

If txtTimeRemaining = "0" Then

End game because not all political buttons were matched in time.

            stopGameTimer
            stopGameTimer
            cmdButton.Caption = "Start Another Game"
            lblOuput = "Click ""Start Another Game"" _
			to begin playing Campaign Button Memory"
            MsgBox "Sorry, time is up. Game over."
            cmdButton.Visible = True
        End If
        If CInt(txtTimeRemaining) > 0 Then
            txtTimeRemaining = CInt(txtTimeRemaining) - 1
        End If
    End If
End Sub

History

  • 23rd February, 2004: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

dzzxyz
Web Developer
United States United States
Keep on coding!

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.1411022.1 | Last Updated 24 Feb 2004
Article Copyright 2004 by dzzxyz
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid