-- By Rick3137 http://rb23.yolasite.com/
function MakeSquare( row , column )
local x = 200 local y = -40 local x2 = 0 local y2 = 0
color (25,225,200)
x = x + column * 70 y = y + row * 70 x2 = x + 67 y2 = y + 67
fillbox (x,y,x2,y2)
color (25,150,150)
line (x,y,x2,y) line (x2,y,x2,y2) line (x2,y2,x,y2) line (x+1,y2,x+1,y)
line (x+3,y2,x+3,y)
for a = 1 , 18 do
x=x+2 y=y+2 x2 = x2-2 y2 = y2-2
line (x,y,x2,y) line (x2,y,x2,y2) line (x2,y2,x+3,y2) line (x+3,y2,x+3,y+3)
end
end
function DisplaySquares()
local a = 0
for row = 1,10 do
for column = 1,10 do
a = BoardArray [ row ][ column ]
if a == 0 then MakeSquare ( row , column ) end
end
end
end
function MakeBoard()
color (0,0,0)
fillbox(250,20,980,740 )
color (0,100,100)
fillbox(260,25,975,735 )
end
-- Starts Program
cnt = 0 x = 0 y = 0 key = 0 col = 0 rw = 0 x2 = 0 y2 = 0
screen (1380,760,32," Board Array Demo ")
backcolor (0,0,80)
clearscreen()
BoardArray = {} -- create the Array
for row = 1,10 do
BoardArray [ row ] = {} -- create a new row
for column = 1,10 do
BoardArray [ row ][ column ] = 0
end
end
-- you now have a 2d array with 100 elements, ready to use.
for row = 1,10 do
for column = 1,10 do
BoardArray [ row ][ column ] = 0
end
end
MakeBoard()
DisplaySquares()
while cnt < 10000
do
x = mousex() x2 = x - 270
y = mousey() y2 = y - 30
col = floor( x2/70 ) + 1
rw = floor ( y2/70 ) + 1
clearscreen()
drawtext (200,100,x)
drawtext (200,120,y)
drawtext (200,140,col)
drawtext (200,160,rw)
drawtext (100,100,"x")
drawtext (100,120,"y")
drawtext (100,140,"column")
drawtext (100,160,"row")
drawtext (40,200,"Hold down Spacebar to end ")
MakeBoard()
DisplaySquares()
redraw()
wait (100)
key = getkey()
if key == 32 then break end
cnt = cnt + 1
end
-- redraw()
inkey()
closewindow() -- This ends the program.