setscreen ("graphics:150;150,nobuttonbar,position:center;center,offscreenonly")
colorback (black)
color (white)
cls
var spot : array 1 .. maxrow + 1, 1 .. maxcol + 1 of int
% The +1 is for when the game is running, it checks at maxrow+1 which does not exist . . so lets make it exist
for q : 1 .. upper (spot, 1) %maxrow
for i : 1 .. upper (spot, 2) %maxcol
spot (q, i) := Rand.Int (0, 4) %4 means cannot walk there
end for
end for
spot (1, 1) := 0 %Make the first spot open
var x, y : int := 1 %(x,y) starts at (1,1) which is =0
var xHold, yHold : int := x
var valueHold : string := ""
var key : array char of boolean
proc refresh
for q : 1 .. upper (spot, 1) - 1 %we cannot go to maxrow+1 so dont
for i : 1 .. upper (spot, 2) - 1 %we cannot go to maxcol+1 so dont
color (spot (q, i)+28)
locate (q, i) %locate properly
put spot (q, i) .. %put whatever value is there
end for
end for
color (10)
locate (x, y) %locate where our man is
put "P" ..
end refresh
loop
Input.KeyDown (key)
% Basically the if statements say, if the next spot is NOT 4 and is NOT off screen then go ahead
if key (KEY_LEFT_ARROW) and y - 1 not= 0 and spot (x, y - 1) not= 4 then
y -= 1
elsif key (KEY_RIGHT_ARROW) and y + 1 <= maxcol and spot (x, y + 1) not= 4 then
y += 1
end if
if key (KEY_UP_ARROW) and x - 1 not= 0 and spot (x - 1, y) not= 4 then
x -= 1
elsif key (KEY_DOWN_ARROW) and x + 1 <= maxrow and spot (x + 1, y) not= 4 then
x += 1
end if
refresh
View.Update
delay (100)
end loop |