setscreen ("offscreenonly,title:Snake,graphics:300;300")
var lengtx : int := 0
var lengty : int := 0
var x, y : int := 20
var x2 : int := x
var y2 : int := y
proc snake (x2, y2, clr : int)
drawfillbox (x, y, x2 + 9, y2 + 9, clr)
end snake
var key : array char of boolean
var move : int := 0
var dir : string := "up"
proc maze2
drawline (9, 9, 9, 290, 7)
drawline (9, 9, 290, 9, 7)
drawline (290, 9, 290, 290, 7)
drawline (9, 290, 290, 290, 7)
end maze2
maze2
var foodx, foody, food : int := 0
proc up
y += 10
dir := "up"
end up
proc down
y -= 10
dir := "down"
end down
proc left
x -= 10
dir := "left"
end left
proc right
x += 10
dir := "right"
end right
loop
if food = 0 then
loop
randint (foodx, 20, 270)
randint (foody, 20, 270)
if intstr (foodx) (*) = "0" then
if intstr (foody) (*) = "0" then
if whatdotcolor (foodx, foody) = 0 then
if x + 10 <= foodx and x >= foodx and y + 10 <= foody and y + 10 >= foody then
drawfillbox (foodx, foody, foodx + 9, foody + 9, 0)
exit
else
drawfillbox (foodx, foody, foodx + 9, foody + 9, 7)
exit
end if
end if
end if
end if
end loop
food := 1
end if
snake (x, y, 0)
Input.KeyDown (key)
if key (KEY_UP_ARROW) then %up arrow
if dir not= "down" then
up
else
down
end if
elsif key (KEY_DOWN_ARROW) then %down
if dir not= "up" then
down
else
up
end if
elsif key (KEY_LEFT_ARROW) then %left
if dir not= "right" then
left
else
right
end if
elsif key (KEY_RIGHT_ARROW) then %right
if dir not= "left" then
right
else
left
end if
else
if dir = "up" then
y += 10
elsif dir = "down" then
y -= 10
elsif dir = "left" then
x -= 10
elsif dir = "right" then
x += 10
end if
end if
exit when x <= 5| x >= 290| y <= 5| y >= 290
snake (x, y, 1)
View.Update
if whatdotcolor (foodx, foody) = 1 then
food := 0
end if
delay (30)
end loop
maze2
|