2022-06-02 20:18:02 +02:00
|
|
|
function state_game()
|
2022-05-29 18:38:07 +02:00
|
|
|
|
2022-06-02 22:39:23 +02:00
|
|
|
local board
|
2022-06-02 20:18:02 +02:00
|
|
|
local selected_id = 1
|
2022-07-02 20:45:11 +02:00
|
|
|
local timer_clue = 0
|
|
|
|
|
|
|
|
local function show_clues()
|
|
|
|
-- local result = board:is_valid()
|
|
|
|
-- if result ~= true and result ~= false then
|
|
|
|
-- local rule,what,where = unpack(result)
|
|
|
|
-- --printh("Rule: " .. rule .. " " .. what .. " " .. where[1].. " " .. where[2])
|
|
|
|
-- end
|
|
|
|
end
|
2022-06-01 23:14:22 +02:00
|
|
|
|
2022-07-01 19:50:08 +02:00
|
|
|
local function draw_selected_tile()
|
2022-06-02 20:18:02 +02:00
|
|
|
local x, y = board:draw_coords(selected_id)
|
|
|
|
local w = board:get_tile_width()
|
2022-06-02 22:39:23 +02:00
|
|
|
fillp(▒)
|
2022-06-01 23:14:22 +02:00
|
|
|
rect2(x-1, y-1, w+2, w+2, 6)
|
2022-06-02 22:39:23 +02:00
|
|
|
fillp(█)
|
2022-06-01 23:14:22 +02:00
|
|
|
end
|
|
|
|
|
2022-06-02 22:39:23 +02:00
|
|
|
local function _enter(_board)
|
|
|
|
board = _board
|
2022-06-03 23:31:26 +02:00
|
|
|
-- lock the initial tiles
|
|
|
|
board:lock_tiles()
|
2022-05-29 18:38:07 +02:00
|
|
|
end
|
|
|
|
|
2022-07-02 20:45:11 +02:00
|
|
|
local function _leave()
|
|
|
|
-- stopcoroutine(show_clues)
|
|
|
|
end
|
|
|
|
|
2022-06-01 23:14:22 +02:00
|
|
|
local function _draw()
|
2022-06-02 17:55:52 +02:00
|
|
|
cls()
|
2022-06-01 23:14:22 +02:00
|
|
|
board:draw()
|
2022-07-01 19:50:08 +02:00
|
|
|
draw_selected_tile()
|
2022-06-01 23:14:22 +02:00
|
|
|
end
|
2022-05-29 18:38:07 +02:00
|
|
|
|
2022-06-01 23:14:22 +02:00
|
|
|
local function _update()
|
2022-07-02 20:45:11 +02:00
|
|
|
timer_clue += 1
|
|
|
|
if timer_clue % 120 == 0 then
|
|
|
|
show_clues()
|
|
|
|
end
|
2022-06-02 20:18:02 +02:00
|
|
|
local size = board:get_size()
|
|
|
|
local x, y = board:idx_xy(selected_id)
|
2022-06-01 23:14:22 +02:00
|
|
|
if btnp(UP) then
|
|
|
|
y -= 1
|
|
|
|
elseif btnp(DOWN) then
|
|
|
|
y += 1
|
|
|
|
elseif btnp(LEFT) then
|
|
|
|
x -= 1
|
|
|
|
elseif btnp(RIGHT) then
|
|
|
|
x += 1
|
|
|
|
end
|
2022-07-01 19:50:08 +02:00
|
|
|
|
|
|
|
if btnp(BTN_O) then
|
|
|
|
board:try_flip_tile(selected_id)
|
|
|
|
end
|
|
|
|
|
2022-06-01 23:14:22 +02:00
|
|
|
if (x<1) x=size
|
|
|
|
if (x>size) x=1
|
|
|
|
if (y<1) y=size
|
|
|
|
if (y>size) y=1
|
2022-06-02 20:18:02 +02:00
|
|
|
selected_id = board:xy_idx(x, y)
|
2022-06-01 23:14:22 +02:00
|
|
|
end
|
2022-05-29 18:38:07 +02:00
|
|
|
|
2022-06-01 23:14:22 +02:00
|
|
|
return {
|
|
|
|
_enter = _enter,
|
|
|
|
_update = _update,
|
|
|
|
_draw = _draw,
|
2022-07-02 20:45:11 +02:00
|
|
|
_leave = _leave
|
2022-05-29 18:38:07 +02:00
|
|
|
}
|
|
|
|
end
|