39 lines
995 B
Lua
39 lines
995 B
Lua
require 'grid'
|
|
require 'line'
|
|
require 'point'
|
|
|
|
-- Constructs line from { start x, start y, end x, end y, color }
|
|
---@param table table
|
|
---@return Line
|
|
local function makeLine( table )
|
|
local startpoint = GridPoint:new( table[1], table[2] )
|
|
local endpoint = GridPoint:new( table[3], table[4] )
|
|
return Line:new( startpoint, endpoint, Color[table[5]] )
|
|
end
|
|
|
|
-- Constructs all game objects using data table
|
|
-- table = {
|
|
-- -- Size
|
|
-- width = 5,
|
|
-- height = 5,
|
|
-- -- Lines
|
|
-- lines = {
|
|
-- -- start x, start y, end x, end y, color
|
|
-- { 1, 1, 3, 3, "red" },
|
|
-- { 1, 5, 5, 2, "green" },
|
|
-- { 2, 5, 5, 3, "blue" }
|
|
-- }
|
|
-- }
|
|
---@param table table
|
|
---@return Grid
|
|
function MakeGrid( table )
|
|
local size = Point:new( table.width, table.height )
|
|
local grid = Grid:new( size )
|
|
|
|
for _, lineData in ipairs( table.lines ) do
|
|
local line = makeLine( lineData )
|
|
grid:push( line )
|
|
end
|
|
|
|
return grid
|
|
end
|