85 lines
2.4 KiB
Lua
85 lines
2.4 KiB
Lua
function initSmallNumbers()
|
|
local dx = math.floor((cell.width - 2 * cell.mx) / 3) + 2
|
|
local dy = math.floor((cell.width - 2 * cell.my) / 3)
|
|
for x = 1, 9 do
|
|
smallNumbers[x] = {}
|
|
smallNumbersVal[x] = {}
|
|
for y = 1, 9 do
|
|
smallNumbers[x][y] = {}
|
|
smallNumbersVal[x][y] = {}
|
|
local x1 = grid.x1 + (x - 1) * cell.width
|
|
local y1 = grid.y1 + (y - 1) * cell.height
|
|
local n = 1
|
|
for j = 1, 3 do
|
|
for i = 1, 3 do
|
|
local x2 = x1 + cell.mx + (i-1) * dx
|
|
local y2 = y1 + cell.my + (j-1) * dy
|
|
smallNumbers[x][y][n] = {x=x2, y=y2}
|
|
smallNumbersVal[x][y][n] = false
|
|
n = n + 1
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function initGrid()
|
|
grid.x2 = grid.x1 + 9 * cell.width
|
|
grid.y2 = grid.y1 + 9 * cell.height
|
|
for i = 1, 9 do
|
|
grid[i] = {}
|
|
for j = 1, 9 do
|
|
local x = grid.x1 + (i - 1) * cell.width
|
|
local y = grid.y1 + (j - 1) * cell.height
|
|
grid[i][j] = {x1=x, y1=y, x2=x+cell.width, y2=y+cell.height}
|
|
end
|
|
end
|
|
local n = 0
|
|
local m = 0
|
|
grid.vline = {}
|
|
for x = grid.x1, grid.x1 + 9 * cell.width, cell.width do
|
|
n = n + 1
|
|
if n % 3 ~= 1 then
|
|
m = m + 1
|
|
grid.vline[m] = {x1=x, y1=grid.y1, x2=x, y2=grid.y1+9*cell.height}
|
|
end
|
|
end
|
|
n = 0
|
|
m = 0
|
|
grid.hline = {}
|
|
for y = grid.y1, grid.y1 + 9 * cell.height, cell.height do
|
|
n = n + 1
|
|
if n % 3 ~= 1 then
|
|
m = m + 1
|
|
grid.hline[m] = {x1=grid.x1, y1=y, x2=grid.x1+9*cell.width, y2=y}
|
|
end
|
|
end
|
|
n = 0
|
|
grid.vbline = {}
|
|
for x = grid.x1, grid.x1+9 * cell.width, cell.width * 3 do
|
|
n = n + 1
|
|
grid.vbline[n] = {x1=x, y1=grid.y1, x2=x, y2=grid.y1+9*cell.height}
|
|
end
|
|
n = 0
|
|
grid.hbline = {}
|
|
for y = grid.y1, grid.y1+9*cell.height, cell.height * 3 do
|
|
n = n + 1
|
|
grid.hbline[n] = {x1=grid.x1, y1=y, x2=grid.x1+9*cell.width, y2=y}
|
|
end
|
|
end
|
|
|
|
function findFirstEmptyCell()
|
|
for x = 1, 9 do
|
|
for y = 1, 9 do
|
|
if uiBoard[1][y][x] == 0 then return y, x end
|
|
end
|
|
end
|
|
return -1, -1
|
|
end
|
|
|
|
function initUI()
|
|
initSmallNumbers()
|
|
initGrid()
|
|
cursor.x, cursor.y = findFirstEmptyCell()
|
|
end
|