camelCase -> snake_case

This commit is contained in:
2022-06-02 20:18:02 +02:00
parent 4920224034
commit cb1c76cd2d
6 changed files with 100 additions and 100 deletions
+18 -18
View File
@@ -1,11 +1,11 @@
function stateGame()
function state_game()
local board = Board.new()
local selectedId = 1
local selected_id = 1
local function drawSelectedTile()
local x, y = board:draw_coords(selectedId)
local w = board:getTileWidth()
local x, y = board:draw_coords(selected_id)
local w = board:get_tile_width()
rect2(x-1, y-1, w+2, w+2, 6)
end
@@ -15,43 +15,43 @@ function stateGame()
repeat
board:reset()
repeat
board:solveStep(true)
board:solve_step(true)
yield()
until board:isComplete()
until board:isValid()
until board:is_complete()
until board:is_valid()
printh("b: " .. time())
-- Remove tiles until randomness is unavoidable
local previous = {board:getTilesCopy()} -- initial state
local previous = {board:get_tiles_copy()} -- initial state
local i = 0
while true do
board:setTiles(previous[#previous])
board:set_tiles(previous[#previous])
-- remove a random tile
repeat
i += 1
until i == 100 or board:getTilesCopy()[i] ~= 0
until i == 100 or board:get_tiles_copy()[i] ~= 0
if i == 100 then
break
end
board:fill(i, 0)
add(previous, board:getTilesCopy())
add(previous, board:get_tiles_copy())
-- try to solve the board
local solved = ""
yield()
repeat
solved = board:solveStep()
until board:isComplete() or solved == "invalid"
solved = board:solve_step()
until board:is_complete() or solved == "invalid"
if solved == "invalid" then
deli(previous)
end
end -- end while
printh("c: " .. time())
board:setTiles(previous[#previous])
board:set_tiles(previous[#previous])
printh(board:tostring())
printh(count(board:getTilesCopy(), 0).." zeroes")
printh(count(board:get_tiles_copy(), 0).." zeroes")
end
local function _enter()
@@ -65,8 +65,8 @@ function stateGame()
end
local function _update()
local size = board:getSize()
local x, y = board:idx_xy(selectedId)
local size = board:get_size()
local x, y = board:idx_xy(selected_id)
if btnp(UP) then
y -= 1
elseif btnp(DOWN) then
@@ -80,7 +80,7 @@ function stateGame()
if (x>size) x=1
if (y<1) y=size
if (y>size) y=1
selectedId = board:xy_idx(x, y)
selected_id = board:xy_idx(x, y)
end
return {
+11 -11
View File
@@ -1,21 +1,21 @@
function stateMenu()
function state_menu()
local selected = 1
local function onBtnDraw(btn)
local function on_btn_draw(btn)
if selected == btn.data.i then
btn.color = 7
end
end
local buttons = {
makeButton({x=10, y=10, w=30, text="play", data={i=1},
onClick=function() setState(states.game) end,
onHover=function(btn) btn.color = 7 selected = 1 end,
onDraw=onBtnDraw}),
makeButton({x=10, y=20, w=30, text="rules", data={i=2},
onClick=function() setState(states.rules) end,
onHover=function(btn) btn.color = 7 selected = 2 end,
onDraw=onBtnDraw})
make_button({x=10, y=10, w=30, text="play", data={i=1},
on_click=function() set_state(states.game) end,
on_hover=function(btn) btn.color = 7 selected = 1 end,
on_draw=on_btn_draw}),
make_button({x=10, y=20, w=30, text="rules", data={i=2},
on_click=function() set_state(states.rules) end,
on_hover=function(btn) btn.color = 7 selected = 2 end,
on_draw=on_btn_draw})
}
local function _enter()
@@ -35,7 +35,7 @@ function stateMenu()
elseif btnp(DOWN) then
selected += 1
elseif btnp(BTN_O) then
buttons[selected]:onClick()
buttons[selected]:on_click()
end
selected = mid(1, selected, #buttons)
+11 -11
View File
@@ -1,4 +1,4 @@
function stateRules()
function state_rules()
local fade = split"0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,4,9,10,9,4,2,1"
local color = 1
@@ -7,17 +7,17 @@ function stateRules()
rect2(x,y,w,h,fade[color])
end
local function goBack()
setState(states.menu)
local function go_back()
set_state(states.menu)
end
local btnBack = makeButton({x=1, y=118, w=30, h=7, text="❎menu", color=8,
onClick=function() goBack() end,
onHover=function(btn) btn.color = 7 end})
local btn_back = make_button({x=1, y=118, w=30, h=7, text="❎menu", color=8,
on_click=function() go_back() end,
on_hover=function(btn) btn.color = 7 end})
return {
_update=function()
if frameCount%8==0 then
if frame_count%8==0 then
color += 1
end
if color>#fade then
@@ -26,14 +26,14 @@ function stateRules()
-- Back to the menu
if btnp(BTN_X) then
goBack()
go_back()
end
btnBack:update()
btn_back:update()
end,
_draw=function()
customFont()
custom_font()
print("1) yOU CAN'T HAVE MORE THAN\n TWO (2) CONSECUTIVE TILES\n OF THE SAME COLOR", 2,2, 7)
local x = 14
@@ -80,7 +80,7 @@ function stateRules()
--------------
btnBack:draw()
btn_back:draw()
end,
}
end