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.
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:
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")
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.
bStarted = False
intTimeLeft = intTimeLeft + 1
intTimeLeft = 0
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.
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
If CInt(txtTimeRemaining) > 0 Then
txtTimeRemaining = CInt(txtTimeRemaining) - 1
- 23rd February, 2004: Initial post