'------------------------------------------------
'Get the Game Loop going
createtarget()
createplayer()
game()
'------------------------------------------------
'The Main Game Loop
Sub game
GraphicsWindow.KeyDown = OnKeyDown
continue = "True"
While (continue)
'Listen for keys
If (keyIsUpdated = "True") Then
If(key = "Space") then
key = ""
restartgame()
elseif(key = "Escape") Then
continue = "False"
keyIsUpdated = "False"
Program.End()
elseif (key = "Left") then
playerx = playerx - 1
movecells()
elseif (key = "Right") then
playerx = playerx + 1
movecells()
elseif (key = "Up") then
playery = playery - 1
movecells()
elseif (key = "Down") then
playery = playery + 1
movecells()
EndIf
gamerules()
keyIsUpdated = "False"
EndIf
gamerules()
'Game Loop Ends Here
EndWhile
endsub
Sub OnKeyDown
key = GraphicsWindow.LastKey
keyIsUpdated = "True"
EndSub
'Restart the game
Sub RestartGame
GraphicsWindow.Clear()
game()
EndSub
'------------------------------------------------
Sub movecells
shapes.Move(player,playerx,playery)
EndSub
sub gamerules
If targetx+3 = playerx and targety+3 = playery and scoreshown <> 1 Then
scoreshown = 1
GraphicsWindow.ShowMessage("You win!", "You win!")
EndIf
EndSub