Turing: |
setscreen ("nocursor, noecho, nobuttonbar")
colourback (green)
cls
var chars : string (1)
var boxx1 : int := 35
var boxy1 : int := 15
var locationx, locationy, x1, y1 : int
var dot : array 1 .. 10, 1 .. 2 of int
var font1, font2, font3, font4 : int
font1 := Font.New ("serif:20")
font2 := Font.New ("serif:15")
%Draws the white background and the lines for the box
procedure box
Draw.FillBox (25, 25, 275, 275, white)
for x : 1 .. 11
for y : 1 .. 11
drawline (25, (x * 25), 275, (x * 25), black)
drawline ((x * 25), 25, (x * 25), 275, black)
end for
end for
end box
%Randomizes the location of the dots
procedure dots
var randomdots : int := Rand.Int (1, 10)
for a : 1 .. randomdots
locationx := Rand.Int (2, 9)
locationy := Rand.Int (2, 9)
if locationx = 2 then
x1 := 63
elsif locationx = 3 then
x1 := 88
elsif locationx = 4 then
x1 := 113
elsif locationx = 5 then
x1 := 138
elsif locationx = 6 then
x1 := 163
elsif locationx = 7 then
x1 := 188
elsif locationx = 8 then
x1 := 213
elsif locationx = 9 then
x1 := 238
end if
if locationy = 2 then
y1 := 63
elsif locationy = 3 then
y1 := 88
elsif locationy = 4 then
y1 := 113
elsif locationy = 5 then
y1 := 138
elsif locationy = 6 then
y1 := 163
elsif locationy = 7 then
y1 := 188
elsif locationy = 8 then
y1 := 213
elsif locationy = 9 then
y1 := 238
end if
Draw.FillOval (x1, y1, 5, 5, red)
dot (a, 1) := x1
dot (a, 2) := y1
end for
end dots
box
dots
drawfilloval (boxx1, boxy1, 5, 5, blue)
loop
getch (chars )
%if it is on the corner then move it to the side
if chars = 'W' or chars = 'w' and boxy1 = 15 and boxx1 = 35 then
boxy1 + = 25
boxx1 - = 25
drawfilloval (boxx1 + 25, boxy1 - 25, 5, 5, green)
elsif chars = 'W' or chars = 'w' and boxy1 = 15 and boxx1 = 260 then
boxy1 + = 25
boxx1 + = 25
drawfilloval (boxx1 - 25, boxy1 - 25, 5, 5, green)
elsif chars = 'W' or chars = 'w' and boxy1 = 15 and boxy1 + 25 < 35 then
boxy1 + = 25
drawfilloval (boxx1, boxy1 - 25, 5, 5, green)
elsif chars = 'W' or chars = 'w' and boxy1 >= 40 and boxy1 + 25 < 300 then
boxy1 + = 25
drawfilloval (boxx1, boxy1 - 25, 5, 5, green)
elsif chars = 'A' or chars = 'a' and boxx1 = 10 and boxx1 - 25 > 5 then
boxx1 - = 25
drawfilloval (boxx1 + 25, boxy1, 5, 5, green)
elsif chars = 'A' or chars = 'a' and boxx1 >= 275 and boxy1 >= 40 then
boxx1 - = 25
boxy1 + = 25
drawfilloval (boxx1 + 25, boxy1 - 25, 5, 5, green)
elsif chars = 'A' or chars = 'a' then
boxx1 - = 25
drawfilloval (boxx1 + 25, boxy1, 5, 5, green)
elsif chars = 'S' or chars = 's' and boxx1 = 35 and boxy1 >= 285 then
boxy1 - = 25
boxx1 - = 25
drawfilloval (boxx1 + 25, boxy1 + 25, 5, 5, green)
elsif chars = 'S' or chars = 's' and boxx1 = 260 and boxy1 >= 40 then
boxy1 - = 25
boxx1 + = 25
drawfilloval (boxx1 - 25, boxy1 + 25, 5, 5, green)
elsif chars = 'S' or chars = 's' and boxx1 = 285 and boxy1 = 40 then
boxy1 - = 25
boxx1 - = 25
drawfilloval (boxx1 + 25, boxy1 + 25, 5, 5, green)
elsif chars = 'S' or chars = 's' and boxx1 > 34 and boxx1 < 285 and boxy1 = 15 and boxy1 - 25 > 10 then
boxy1 - = 25
drawfilloval (boxx1, boxy1 + 25, 5, 5, green)
elsif chars = 'S' or chars = 's' then
boxy1 - = 25
drawfilloval (boxx1, boxy1 + 25, 5, 5, green)
elsif chars = 'D' or chars = 'd' and boxx1 = 10 and boxy1 >= 260 then
boxx1 + = 25
boxy1 + = 25
drawfilloval (boxx1 - 25, boxy1 - 25, 5, 5, green)
elsif chars = 'D' or chars = 'd' and boxx1 = 10 and boxy1 = 40 then
boxx1 + = 25
boxy1 - = 25
drawfilloval (boxx1 - 25, boxy1 + 25, 5, 5, green)
elsif chars = 'D' or chars = 'd' then
boxx1 + = 25
drawfilloval (boxx1 - 25, boxy1, 5, 5, green)
end if
drawfilloval (boxx1, boxy1, 5, 5, blue)
View.Update
end loop
|
How is that? Any suggestions? |