Dim lastcolor As String
Dim memoryStack() As String
Dim gameMemoryStack() As String 'make a connection with the memorycounters thats i
Dim firstColor As String
Dim memoryCounter As Integer
Dim roundNumber As Integer
Dim arrTemp() As String
Private Function pop() As String
Debug.Print "memcountbeg pop " & memoryCounter
Dim arrTemp() As String
ReDim arrTemp(UBound(memoryStack))
arrTemp() = reverseOrder(memoryStack)
pop = arrTemp(UBound(arrTemp))
ReDim Preserve arrTemp(UBound(arrTemp) - 1)
If UBound(arrTemp) = 0 Then
roundNumber = roundNumber + 1
Call nextRound 'gets the next round
End If
Debug.Print "memcountend pop " & memoryCounter ********
End Function 'memorycounter = 0
Private Sub Form_Load()
'sets default values to the two arrays used to hold values of the letters pushed
Dim i As Integer
Dim randomNumber As Integer
Dim gameColor As String
ReDim memoryStack(0)
ReDim gameMemoryStack(24)
roundNumber = 1
Randomize
'decides what the colors are going to be for the whole game
'fills an array with random colors of red,yellow,blue, and green
For i = 0 To 24
randomNumber = Int(4 * Rnd)
Select Case randomNumber
Case 0
gameColor = "Yellow"
Case 1
gameColor = "Red"
Case 2
gameColor = "Blue"
Case 3
gameColor = "Green"
End Select
gameMemoryStack(i) = gameColor
Next i
firstColor = gameMemoryStack(0)
Call nextRound
End Sub
Private Sub lblYellowbutton_click()
Dim begColor As String
Dim colorPush As String
colorPush = "Yellow"
Debug.Print UBound(memoryStack)
If (colorPush = memoryStack(memoryCounter)) Then
lastcolor = pop
memoryCounter = memoryCounter + 1
If UBound(arrTemp) = 0 Then
roundNumber = roundNumber + 1
Call nextRound
End If
Else
End
End If
End Sub
Private Sub lblBluebutton_click()
Dim begColor As String
Dim colorPush As String
colorPush = "Blue"
Debug.Print UBound(memoryStack)
If (colorPush = memoryStack(memoryCounter)) Then
lastcolor = pop
memoryCounter = memoryCounter + 1
If UBound(arrTemp) = 0 Then 'changes memory stack to arrtemp
roundNumber = roundNumber + 1
Call nextRound
End If
Else
End
End If
End Sub
Private Sub lblGreenbutton_click()
Dim begColor As String
Dim colorPush As String
colorPush = "Green"
Debug.Print UBound(memoryStack)
If (colorPush = memoryStack(memoryCounter)) Then
lastcolor = pop
memoryCounter = memoryCounter + 1
Debug.Print UBound(memoryStack)
If UBound(arrTemp) = 0 Then
roundNumber = roundNumber + 1
Call nextRound
End If
Else
End
End If
End Sub
Private Sub lblRedbutton_click()
Dim begColor As String
Dim colorPush As String
colorPush = "Red"
Debug.Print UBound(memoryStack)
If (colorPush = memoryStack(memoryCounter)) Then
lastcolor = pop
memoryCounter = memoryCounter + 1
If UBound(arrTemp) = 0 Then '***********************************
roundNumber = roundNumber + 1 'this may be a problem ??????????????
Call nextRound '***********************************
End If
Else
End
End If
End Sub
Private Sub TMRBLINK_Timer()
'this procedure makes the buttons blink
Dim i As Integer, j As Integer
Static blinkNumber As Integer
Debug.Print "memcountbeg tmr " & memoryCounter********
If blinkNumber < UBound(memoryStack) Then
'NOw memorycounter = 1????
Debug.Print memoryStack(blinkNumber)
firstColor = memoryStack(blinkNumber)
Call colorSelect
tmrblink.Enabled = False
tmrColorBlinked.Enabled = True
blinkNumber = blinkNumber + 1
Else
blinkNumber = 0
tmrblink.Enabled = False
End If
Debug.Print "memcountend tmr " & memoryCounter
End Sub
Private Function reverseOrder(arrName() As String) As String()
'this function reverses the order of the array so that we can
'pull from the bottom
Debug.Print "memcountbeg revord " & memoryCounter
Dim i As Integer
Dim tempArr() As String
ReDim tempArr(UBound(arrName))
For i = 0 To UBound(arrName)
tempArr(i) = arrName(UBound(arrName) - 1)
Next i
reverseOrder = tempArr
Debug.Print "memcountend revord " & memoryCounter
End Function
Private Sub tmrColorBlinked_Timer()
'sets the colors back to the original backcolor
lblYellowButton.BackColor = &HC0C0&
lblRedButton.BackColor = &HC0&
lblGreenButton.BackColor = &H8000&
lblBlueButton.BackColor = &H800000
tmrColorBlinked.Enabled = False
tmrblink.Enabled = True
End Sub
Private Sub nextRound()
'this sub procedure starts a new round of the game
'it pulls a new number out of the gameMemoryStack array
'and adds it to the memorystack
Dim i As Integer
memoryCounter = 0 'intitializes the memory counter
ReDim memoryStack(roundNumber)
MsgBox "Round " & roundNumber
For i = 0 To roundNumber - 1
memoryStack(i) = gameMemoryStack(i) 'fills the array to be tested
Next i
ReDim arrTemp(UBound(memoryStack))
'arrTemp() = reverseOrder(memoryStack)
tmrblink.Enabled = True 'tells the color button to flash
Debug.Print "memcountend nxtrnd " & memoryCounter
End Sub
Private Sub MessageBox()
'Just a simple message box
Dim mbox As Integer
Dim title As String
Dim message As String
title = "Game Over"
message = "You got " & roundNumber & " correct"
mbox = MsgBox(message, , title)
End Sub
Private Sub colorSelect()
Select Case firstColor
Case "Yellow"
lblYellowButton.BackColor = vbYellow
Case "Red"
lblRedButton.BackColor = vbRed
Case "Blue"
lblBlueButton.BackColor = vbBlue
Case "Green"
lblGreenButton.BackColor = vbGreen
End Select
End Sub