Clickable buttons

This commit is contained in:
2022-05-29 18:38:07 +02:00
parent 9fd3208aaf
commit 977d2c342b
5 changed files with 514 additions and 423 deletions
+54
View File
@@ -0,0 +1,54 @@
function stateGame()
local board = Board.new()
function _enter()
-- Create a board
repeat
board:reset()
repeat
board:solveStep(true)
until board:isComplete()
until board:isValid()
-- Remove tiles until randomness is unavoidable
local previous = {board:getTilesCopy()} -- initial state
local invalidcount = 0
while true do
-- remove a random tile
board:setTiles(previous[#previous])
local i = board:getRandomNonZero()
board:fill(i, 0)
add(previous, board:getTilesCopy())
-- try to solve the board
local solved = ""
repeat
solved = board:solveStep()
until board:isComplete() or solved == "invalid"
if board:isComplete() then
invalidcount = 0
end
if solved == "invalid" then
deli(previous)
invalidcount += 1
end
if invalidcount == 100 then
break
end
end -- end while
board:setTiles(previous[#previous])
printh(board:tostring())
end
return {
_enter = _enter,
_update = function()
end,
_draw = function()
board:draw()
end,
}
end
+27
View File
@@ -0,0 +1,27 @@
function stateMenu()
local items = {"play", "rules"}
local buttons = {}
function _enter()
for k,v in ipairs(items) do
local button = makeButton(10, k*10, 30, 6, v, function() printh("click") end)
add(buttons, button)
end
end
return {
_enter = _enter,
_update = function()
for button in all(buttons) do
button:update()
end
end,
_draw = function()
for button in all(buttons) do
button:draw()
end
end
}
end