Skip to content

Commit fc43710

Browse files
committed
🚑 (sudoku-game): fix no out of ragne bug
1 parent e4f60f8 commit fc43710

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

‎internal/layout/input-control.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ func handleKeyInput(board *game.Board, targetCell *game.Cell, key ebiten.Key,
6565
board.IncreaseFilledCount()
6666
}
6767
safed := board.IsSafe(targetRow, targetCol, value)
68+
if targetCell.Value == value {
69+
return
70+
}
6871
if !safed {
6972
handleConflict(board, cellType, targetRow, targetCol)
7073
} else {

‎internal/layout/number-buttons.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ func (gameLayout *GameLayout) detectNumberButtonHandler() {
115115
// detect range
116116
if xPos >= 0 && xPos <= 3*cellSize &&
117117
yPos >= 0 && yPos <= 3*cellSize {
118-
row := yPos / cellSize
119-
col := xPos / cellSize
118+
row := (yPos / cellSize) % cellSize
119+
col := (xPos / cellSize) % cellSize
120120
gameLayout.handleNumberButtonClick(row, col)
121121
}
122122
return
@@ -139,6 +139,9 @@ func (gameLayout *GameLayout) handleNumberButtonClick(row, col int) {
139139
}
140140
value := numberButtonValues[row][col]
141141
safed := board.IsSafe(cursorRow, cursorCol, value)
142+
if targetCell.Value == value {
143+
return
144+
}
142145
if !safed {
143146
handleConflict(board, cellType, cursorRow, cursorCol)
144147
} else {

0 commit comments

Comments
 (0)