Commit before fixes
This commit is contained in:
parent
6d1f8bbc8b
commit
0276d70de3
37
board.lua
37
board.lua
|
@ -10,19 +10,10 @@ function Board.new()
|
|||
local locked = {} -- list of indexes
|
||||
|
||||
local reset = function()
|
||||
local t = [[
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0
|
||||
]]
|
||||
tiles = split(t)
|
||||
tiles = {}
|
||||
for i = 1, width * width do
|
||||
tiles[i] = 0
|
||||
end
|
||||
locked = {}
|
||||
end
|
||||
|
||||
|
@ -76,6 +67,16 @@ function Board.new()
|
|||
tiles[idx] = color
|
||||
end,
|
||||
|
||||
try_flip_tile = function(self, id)
|
||||
if locked[id] then return end
|
||||
if tiles[id] == 0 then
|
||||
tiles[id] = YELLOW
|
||||
elseif tiles[id] == YELLOW then
|
||||
tiles[id] = BLUE
|
||||
else tiles[id] = 0
|
||||
end
|
||||
end,
|
||||
|
||||
get_rows = function(self)
|
||||
local ret = {}
|
||||
for i = 1, width do
|
||||
|
@ -390,16 +391,16 @@ function Board.new()
|
|||
lock_tiles = function(self)
|
||||
locked = {}
|
||||
for k,v in ipairs(tiles) do
|
||||
if v > 0 then add(locked, k) end
|
||||
if v > 0 then locked[k] = true end
|
||||
end
|
||||
end,
|
||||
|
||||
is_locked = function(self, idx)
|
||||
return #find(locked, idx) > 0
|
||||
return locked[idx]
|
||||
end,
|
||||
|
||||
draw_bg = function(self)
|
||||
local w = width
|
||||
local w = tile_width
|
||||
fillp(▒)
|
||||
for k,v in ipairs(tiles) do
|
||||
local x,y = self:draw_coords(k)
|
||||
|
@ -409,14 +410,14 @@ function Board.new()
|
|||
|
||||
draw = function(self)
|
||||
self:draw_bg()
|
||||
local w = width
|
||||
local w = tile_width
|
||||
for k,v in ipairs(tiles) do
|
||||
self:draw_tile(k)
|
||||
end
|
||||
end,
|
||||
|
||||
draw_tile = function(self, idx)
|
||||
local w = width
|
||||
local w = tile_width
|
||||
local v = tiles[idx]
|
||||
if v > 0 then
|
||||
local x,y = self:draw_coords(idx)
|
||||
|
|
5
main.lua
5
main.lua
|
@ -99,7 +99,12 @@ local create = true
|
|||
|
||||
function _init()
|
||||
printh(" ")
|
||||
printh("*************")
|
||||
printh(" ")
|
||||
local date = stat(80)..stat(81)..stat(82)..stat(85)
|
||||
-- srand(date)
|
||||
srand(20227149)
|
||||
printh(date)
|
||||
mouse_x = 0
|
||||
mouse_y = 0
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ function state_game()
|
|||
local board
|
||||
local selected_id = 1
|
||||
|
||||
local function drawSelectedTile()
|
||||
local function draw_selected_tile()
|
||||
local x, y = board:draw_coords(selected_id)
|
||||
local w = board:get_tile_width()
|
||||
fillp(▒)
|
||||
|
@ -20,7 +20,7 @@ function state_game()
|
|||
local function _draw()
|
||||
cls()
|
||||
board:draw()
|
||||
drawSelectedTile()
|
||||
draw_selected_tile()
|
||||
end
|
||||
|
||||
local function _update()
|
||||
|
@ -35,6 +35,11 @@ function state_game()
|
|||
elseif btnp(RIGHT) then
|
||||
x += 1
|
||||
end
|
||||
|
||||
if btnp(BTN_O) then
|
||||
board:try_flip_tile(selected_id)
|
||||
end
|
||||
|
||||
if (x<1) x=size
|
||||
if (x>size) x=1
|
||||
if (y<1) y=size
|
||||
|
|
|
@ -37,14 +37,15 @@ function state_loading()
|
|||
|
||||
-- Remove tiles that can be removed
|
||||
local previous = {board:get_tiles_copy()} -- initial state
|
||||
local size = board:get_size()*board:get_size()
|
||||
while true do
|
||||
|
||||
board:set_tiles(previous[#previous])
|
||||
-- remove a random tile
|
||||
repeat
|
||||
removing_tile += 1
|
||||
until removing_tile == 100 or board:get_tiles_copy()[removing_tile] ~= 0
|
||||
if removing_tile == 100 then
|
||||
until removing_tile == size or board:get_tiles_copy()[removing_tile] ~= 0
|
||||
if removing_tile == size then
|
||||
break
|
||||
end
|
||||
|
||||
|
@ -111,9 +112,9 @@ function state_loading()
|
|||
cls()
|
||||
board:draw_bg()
|
||||
draw_tiles(board)
|
||||
|
||||
local s = board:get_size()*board:get_size()
|
||||
local l = print(message, 0, -100)
|
||||
local y = 118+removing_tile/8
|
||||
local y = 118+(removing_tile/s)*100/8
|
||||
local colors = {7,6,5,5}
|
||||
local ci = removing_tile\20+1
|
||||
local c = colors[ci]
|
||||
|
|
Loading…
Reference in New Issue
Block a user