Mouse.ButtonChoose ("multibutton")
setscreen ("offscreenonly")
var box : array 0 .. 65, 0 .. 41 of int
var dead : array 0 .. 65, 0 .. 41 of int
var mx, my, mb, count, colr, live, turns : int := 0
var window : int
for a : 0 .. 65
for b : 0 .. 41
box (a, b) := 0
dead (a, b) := 0
end for
end for
process counter
window := Window.Open ("position:100,100,graphics:220;220")
loop
for c : 1 .. 64
for d : 1 .. 40
if box (c, d) = 1 then
live := live + 1
end if
end for
end for
locate (1, 1)
put live
put turns
live := 0
end loop
end counter
for a : 0 .. maxx by 10
drawline (a, maxy, a, 0, black)
end for
for a : 0 .. maxy by 10
drawline (maxx, a, 0, a, black)
end for
View.Update
fork counter
loop
mousewhere (mx, my, mb)
if mb = 1 then
drawfill (mx, my, brightred, black)
box (mx div 10 + 1, my div 10 + 1) := 1
dead (mx div 10 + 1, my div 10 + 1) := 1
View.Update
end if
exit when mb = 100
end loop
loop
for a : 1 .. 64
for b : 1 .. 40
if box (a + 1, b + 1) = 1 then
count := count + 1
end if
if box (a + 1, b) = 1 then
count := count + 1
end if
if box (a + 1, b - 1) = 1 then
count := count + 1
end if
if box (a - 1, b + 1) = 1 then
count := count + 1
end if
if box (a - 1, b - 1) = 1 then
count := count + 1
end if
if box (a - 1, b) = 1 then
count := count + 1
end if
if box (a, b + 1) = 1 then
count := count + 1
end if
if box (a, b - 1) = 1 then
count := count + 1
end if
if count = 3 then
dead (a, b) := 1
end if
if count > 3 or count < 2 then
dead (a, b) := 0
end if
count := 0
end for
end for
for a : 1 .. 64
for b : 1 .. 40
if dead (a, b) = 1 and box (a, b) = 0 then
box (a, b) := 1
drawfill (a * 10 - 5, b * 10 - 5, brightred, black)
elsif dead (a, b) = 0 and box (a, b) = 1 then
box (a, b) := 0
drawfill (a * 10 - 5, b * 10 - 5, white, black)
end if
end for
end for
turns := turns + 1
View.Update
delay (300)
end loop
|