Yjasl Examples
snake.yjasl
/* Game of life: A really old 'life-simulator'
This version (w) by René 'Neotec' Jeschke
Version uses nested arrays
Uses: Yjasl v2.00 */
width = 60
height = 40
width2 = width - 1
height2 = height - 1
field = array(width)
tfield = array(width)
for x = 0, width2 do
field[x] = array(height)
tfield[x] = array(height, 0)
end
cclear()
for x = 0, width2 do
for y = 0, height2 do
field[x][y] = rand(0, 2)
end
end
function getcell(x, y)
if x < 0 then
x = width + x
elseif x > width2 then
x = x - width
end
if y < 0 then
y = height + y
elseif y > height2 then
y = y - height
end
return field[x][y]
end
while getkey() == null do
t0 = timetick()
for y = 0, height2 do
for x = 0, width2 do
c = 0
for x1 = -1, 1 do
for y1 = -1, 1 do
if !(x1 || y1) then
continue
end
if getcell(x + x1, y + y1) then
c = c + 1
end
end
end
switch c do
case 2:
tfield[x][y] = field[x][y]
break
case 3:
tfield[x][y] = 1
break
default:
tfield[x][y] = 0
end
end
end
chome()
for y = 0, height2 do
for x = 0, width2 do
if tfield[x][y] then
print("+")
else
print(" ")
end
field[x][y] = tfield[x][y]
end
println()
end
t1 = timetick()
println((t1 - t0).." ms ")
end
© by René 'Neotec' Jeschke in 2006, 2007
Last updated: 14 JUN 2007 (under construction)
|
|