logic separation done
This commit is contained in:
		
							parent
							
								
									af42e5e74e
								
							
						
					
					
						commit
						82120ea3db
					
				
							
								
								
									
										3
									
								
								main.lua
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								main.lua
									
									
									
									
									
								
							| @ -16,6 +16,9 @@ function love.load() | ||||
|     messages[1] = "Game Info" | ||||
|     board[1] = loadBoard(board.fn) | ||||
|     board[2] = cloneBoard(board[1]) | ||||
|     uiBoard[1] = cloneBoard(board[1]) | ||||
|     uiBoard[2] = cloneBoard(board[1]) | ||||
|     uiBoard[3] = cloneBoard(board[1]) | ||||
|     initUI() | ||||
| end | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										12
									
								
								ui/draw.lua
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								ui/draw.lua
									
									
									
									
									
								
							| @ -21,7 +21,7 @@ function drawSmallNumbers() | ||||
|     for x = 1, 9 do | ||||
|         for y = 1, 9 do | ||||
|             for i = 1, 9 do | ||||
|                 if board[#board][y][x] == 0 then | ||||
|                 if uiBoard[2][y][x] == 0 then | ||||
|                     local x1 = smallNumbers[x][y][i].x | ||||
|                     local y1 = smallNumbers[x][y][i].y | ||||
|                     if smallNumbersVal[x][y][i] then | ||||
| @ -39,13 +39,13 @@ end | ||||
| function drawBigNumbers() | ||||
|     for x = 1, 9 do | ||||
|         for y = 1, 9 do | ||||
|             if board[1][x][y] ~= 0 then | ||||
|                 local c = tostring(board[1][x][y]) | ||||
|             if uiBoard[1][x][y] ~= 0 then | ||||
|                 local c = tostring(uiBoard[1][x][y]) | ||||
|                 love.graphics.setFont(fonts.bigNumbersOriginal) | ||||
|                 setColor(colors.bigNumbersOriginal) | ||||
|                 love.graphics.print(c, grid[y][x].x1+25, grid[y][x].y1+10) | ||||
|             elseif board[2][x][y] ~= 0 then | ||||
|                 local c = tostring(board[2][x][y]) | ||||
|             elseif uiBoard[2][x][y] ~= 0 then | ||||
|                 local c = tostring(uiBoard[2][x][y]) | ||||
|                 love.graphics.setFont(fonts.bigNumbersPlayer) | ||||
|                 setColor(colors.bigNumbersPlayer) | ||||
|                 love.graphics.print(c, grid[y][x].x1+33, grid[y][x].y1+15) | ||||
| @ -57,7 +57,7 @@ end | ||||
| function drawCursor() | ||||
|     local x = grid[cursor.x][cursor.y].x1 | ||||
|     local y = grid[cursor.x][cursor.y].y1 | ||||
|     if board[1][cursor.y][cursor.x] == 0 then | ||||
|     if uiBoard[1][cursor.y][cursor.x] == 0 then | ||||
|         if cursor.editMode then | ||||
|             setColor(colors.cursorActiveSmall) | ||||
|         else | ||||
|  | ||||
| @ -9,3 +9,4 @@ smallNumbers = {} | ||||
| smallNumbersVal = {} | ||||
| 
 | ||||
| board = {} | ||||
| uiBoard = {} | ||||
|  | ||||
| @ -71,7 +71,7 @@ end | ||||
| function findFirstEmptyCell() | ||||
|     for x = 1, 9 do | ||||
|         for y = 1, 9 do | ||||
|             if board[1][y][x] == 0 then return y, x end | ||||
|             if uiBoard[1][y][x] == 0 then return y, x end | ||||
|         end | ||||
|     end | ||||
|     return -1, -1 | ||||
| @ -82,5 +82,3 @@ function initUI() | ||||
|     initGrid() | ||||
|     cursor.x, cursor.y = findFirstEmptyCell() | ||||
| end | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -15,7 +15,7 @@ end | ||||
| function handleRight(shift) | ||||
|     if shift then | ||||
|         for x in iterBoardLine(cursor.x) do | ||||
|             if board[1][cursor.y][x] == 0 then | ||||
|             if uiBoard[1][cursor.y][x] == 0 then | ||||
|                 cursor.x = x | ||||
|                 break | ||||
|             end | ||||
| @ -29,7 +29,7 @@ end | ||||
| function handleLeft(shift) | ||||
|     if shift then | ||||
|         for x in iterBoardLine(cursor.x, -1) do | ||||
|             if board[1][cursor.y][x] == 0 then | ||||
|             if uiBoard[1][cursor.y][x] == 0 then | ||||
|                 cursor.x = x | ||||
|                 break | ||||
|             end | ||||
| @ -43,7 +43,7 @@ end | ||||
| function handleDown(shift) | ||||
|     if shift then | ||||
|         for y in iterBoardLine(cursor.y) do | ||||
|             if board[1][y][cursor.x] == 0 then | ||||
|             if uiBoard[1][y][cursor.x] == 0 then | ||||
|                 cursor.y = y | ||||
|                 break | ||||
|             end | ||||
| @ -57,7 +57,7 @@ end | ||||
| function handleUp(shift) | ||||
|     if shift then | ||||
|         for y in iterBoardLine(cursor.y, -1) do | ||||
|             if board[1][y][cursor.x] == 0 then | ||||
|             if uiBoard[1][y][cursor.x] == 0 then | ||||
|                 cursor.y = y | ||||
|                 break | ||||
|             end | ||||
| @ -80,34 +80,38 @@ function love.keypressed(key, scancode) | ||||
|         handleDown(shift) | ||||
|     elseif key == "up" or key == "k" then | ||||
|         handleUp(shift) | ||||
|     elseif board[1][cursor.y][cursor.x] == 0 then | ||||
|     elseif uiBoard[1][cursor.y][cursor.x] == 0 then | ||||
|         local n = tonumber(key) or -1 | ||||
|         if n > 0 and n < 10 then | ||||
|             if shift or cursor.editMode then | ||||
|                 board[#board][cursor.y][cursor.x] = 0 | ||||
|                 uiBoard[2][cursor.y][cursor.x] = 0 | ||||
|                 cursor.editMode = true | ||||
|                 smallNumbersVal[cursor.x][cursor.y][n] = not smallNumbersVal[cursor.x][cursor.y][n] | ||||
|             else | ||||
|                 -- for i = 1, 9 do | ||||
|                 --     smallNumbersVal[cursor.x][cursor.y][i] = false | ||||
|                 -- end | ||||
|                 board[#board][cursor.y][cursor.x] = n | ||||
|                 uiBoard[2][cursor.y][cursor.x] = n | ||||
|             end | ||||
|         elseif key == "delete" or key == "0" then | ||||
|             if board[#board][cursor.y][cursor.x] ~= 0 then | ||||
|                 board[#board][cursor.y][cursor.x] = 0 | ||||
|             if uiBoard[2][cursor.y][cursor.x] ~= 0 then | ||||
|                 uiBoard[2][cursor.y][cursor.x] = 0 | ||||
|             else | ||||
|                 if board[1][cursor.y][cursor.x] == 0 then | ||||
|                 if uiBoard[1][cursor.y][cursor.x] == 0 then | ||||
|                     for i = 1, 9 do | ||||
|                         smallNumbersVal[cursor.x][cursor.y][i] = false | ||||
|                     end | ||||
|                 end | ||||
|             end | ||||
|         elseif key == "tab" then | ||||
|             if cursor.editMode == false and board[#board][cursor.y][cursor.x] ~= 0 then | ||||
|                 board[#board][cursor.y][cursor.x] = 0 | ||||
|             if cursor.editMode == false then | ||||
|                 uiBoard[3][cursor.y][cursor.x] = uiBoard[2][cursor.y][cursor.x] | ||||
|                 uiBoard[2][cursor.y][cursor.x] = 0 | ||||
|                 cursor.editMode = true | ||||
|             else | ||||
|                 uiBoard[2][cursor.y][cursor.x] = uiBoard[3][cursor.y][cursor.x] | ||||
|                 cursor.editMode = false | ||||
|             end | ||||
|             cursor.editMode = not cursor.editMode | ||||
|         end | ||||
|     end | ||||
| end | ||||
|  | ||||
| @ -17,11 +17,12 @@ function love.mousepressed(x, y, button, istouch) | ||||
|         n = mx + 3 * (my - 1) | ||||
|     end | ||||
|     if inBoard then | ||||
|         if board[1][cy][cx] == 0 then canChange = true end | ||||
|         if uiBoard[1][cy][cx] == 0 then canChange = true end | ||||
|     end | ||||
|     if inBoard and canChange then | ||||
|         if button == 1 then | ||||
|             cursor.editMode = false | ||||
|             uiBoard[2][cursor.y][cursor.x] = uiBoard[3][cursor.y][cursor.x] | ||||
|             if cursor.x == cx and cursor.y == cy then | ||||
|                 smallNumbersVal[cx][cy][n] = not smallNumbersVal[cx][cy][n] | ||||
|             else | ||||
| @ -30,9 +31,9 @@ function love.mousepressed(x, y, button, istouch) | ||||
|             end | ||||
|         elseif button == 2 then | ||||
|             cursor.editMode = true | ||||
|             board[#board][cursor.y][cursor.x] = 0 | ||||
|             uiBoard[3][cursor.y][cursor.x] = uiBoard[2][cursor.y][cursor.x] | ||||
|             uiBoard[2][cursor.y][cursor.x] = 0 | ||||
|             smallNumbersVal[cx][cy][n] = not smallNumbersVal[cx][cy][n] | ||||
|         end | ||||
|     end | ||||
| end | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user