Option Explicit
Public aryRoute As Variant, aryExpectedChars As Variant
Public aryRanges() As Range
Public idxCurrent As Long
Public isInitialized As Boolean
Sub StartWorking()
Sheets("Invul Diagram").Protect UserInterfaceOnly:=True, DrawingObjects:=True, Contents:=True, Scenarios:=True
Application.OnKey "~", "EnterPressed"
Application.OnKey "{ENTER}", "EnterPressed"
Application.OnKey "{UP}", "ArrowPressed"
Application.OnKey "{LEFT}", "ArrowPressed"
Application.OnKey "{DOWN}", "ArrowPressed"
Application.OnKey "{RIGHT}", "ArrowPressed"
End Sub
Sub StopWorking()
Sheets("Invul Diagram").Unprotect
Application.OnKey "~"
Application.OnKey "{ENTER}"
Application.OnKey "{UP}"
Application.OnKey "{LEFT}"
Application.OnKey "{DOWN}"
Application.OnKey "{RIGHT}"
End Sub
Sub ResetTelling()
If Range("Score").value > Range("HighScore").value Then
Range("HighScore").value = Range("Score").value
End If
Range("Score").value = 0
' Clear specified ranges
Range("InputSelleA").ClearContents
Range("InputSelleB").ClearContents
InitializeRoute
End Sub
Sub InitializeRoute()
Dim i As Long
'index base = 0
aryRoute = Array( _
"B4", "B5", "B6", "B7", "B8", "B9", "B10", "B11", "B12", "B13", "B14", "B15", "B16", _
"C16", "D16", "E16", "F16", "G16", "G15", "G14", "G13", "G12", "G11", "F11", "E11", "E10", "E9", "E8", _
"F8", "G8", "H8", "I8", "J8", "J9", "J10", "J11", "J12", "J13", "K13", "L13", "M13", "N13", "N12", "N11", "N10", _
"O10", "P10", "Q10", "Q9", "Q8", "R8", "S8", "S7", "S6", "S5", "R5", "Q5", "P5", "O5", "N5", "M5", "M4", "L4", "K4", "J4", _
"I4", "I5", "H5", "G5", "F5", "F4", "F3", "G3", "G2", "H2", "I2", "J2", "K2", "L2", "M2", "N2", "O2", "P2", "Q2", "R2", _
"R3", "S3", "T3", "U3", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "W9", "X9", "X8", "X7", "Y7", "Y6", "Y5", "Y4", "X4", _
"X3", "X2", "Y2", "Z2", "AA2", "AA3", "AA4", "AA5", "AA6", "AA7", "AA8", "AA9", "AA10", "Z10", "Z11", "Z12", "Z13", "Z14", "Z15", _
"Y15", "X15", "W15", "V15", "U15", "U16", "T16", "S16", "R16", "Q16", "P16", "O16", "N16", "M16")
'index base = 0
aryExpectedChars = Array( _
"8", "C", "r", "f", "e", """", "P", "N", "K", ";", "T", "_", "\", ".", "&", ">", "A", "b", "[", "!", _
"x", "r", ";", "3", "V", "3", "x", "j", "&", "C", "Z", "n", """", "z", "$", "i", "\", "w", "%", "N", _
"d", "H", "f", "Z", "H", "x", "E", "M", "V", "#", "V", "F", "3", "B", "q", "B", """", ":", "1", "v", "A", _
"y", "Q", "c", ":", "G", "c", "g", "K", "<", "{", "8", "g", "8", "g", "G", ":", "c", "Q", "y", "C", _
"2", "{", "K", "j", "K", "j", "B", "v", ";", "j", "Q", ";", "X", "L", "3", "#", "0", "@", "X", "@", "<", _
"}", "7", "j", "7", ".", "7", "[", "|", "[", "m", "}", "<", "M", "A", "F", "h", "F", ".", "L", "$", _
"w", "<", "D", "2", ".", ",", "w", "Q", "1", "a", "k", "i", "n", "a", "D", "%")
' Verify aryRoute and aryExpectedChars have same length
If UBound(aryRoute) <> UBound(aryExpectedChars) Then
MsgBox "Error: aryRoute and expected characters arrays don't match in length!", vbCritical
Exit Sub
End If
ReDim aryRanges(LBound(aryRoute) To UBound(aryRoute))
For i = LBound(aryRoute) To UBound(aryRoute)
Set aryRanges(i) = Worksheets("Invul Diagram").Range(aryRoute(i))
Next i
idxCurrent = 0
' Select the starting cell
aryRanges(idxCurrent).Select
isInitialized = True
StartWorking
End Sub
Sub EnterPressed()
If Len(aryRanges(idxCurrent)) = 0 Then
aryRanges(idxCurrent).Select
MsgBox "Can't leave it blank"
Exit Sub
End If
If CStr(aryRanges(idxCurrent).value) <> aryExpectedChars(idxCurrent) Then
aryRanges(idxCurrent).ClearContents
aryRanges(idxCurrent).Select
MsgBox "Character doesn't match"
Range("Score").value = Range("Score").value - 1
Exit Sub
End If
Range("Score").value = Range("Score").value + 2
idxCurrent = idxCurrent + 1
If idxCurrent < UBound(aryRanges) Then
aryRanges(idxCurrent).Select
Else
MsgBox "All done"
End If
End Sub
Sub ArrowPressed()
aryRanges(idxCurrent).Select
MsgBox "Can't use arrow keys, use Enter"
End Sub