|
| 1 | +package layout |
| 2 | + |
| 3 | +import ( |
| 4 | + "image/color" |
| 5 | + |
| 6 | + "github.com/hajimehoshi/ebiten/v2" |
| 7 | + "github.com/hajimehoshi/ebiten/v2/vector" |
| 8 | + "github.com/leetcode-golang-classroom/sudoku-game/internal/game" |
| 9 | +) |
| 10 | + |
| 11 | +func (gameLayout *GameLayout) drawHighLightCell(screen *ebiten.Image, row, col int) { |
| 12 | + board := gameLayout.gameInstance.Board |
| 13 | + cursorRow := board.CursorRow |
| 14 | + cursorCol := board.CursorCol |
| 15 | + |
| 16 | + // 跳過自己 |
| 17 | + if row == cursorRow && col == cursorCol { |
| 18 | + return |
| 19 | + } |
| 20 | + // highLight relative row, col |
| 21 | + if row == cursorRow || col == cursorCol { |
| 22 | + gameLayout.drawHighLightCover(screen, row, col) |
| 23 | + return |
| 24 | + } |
| 25 | + boxSize := game.BoxSize |
| 26 | + boxRow := (cursorRow / boxSize) * boxSize |
| 27 | + boxCol := (cursorCol / boxSize) * boxSize |
| 28 | + // highLight Box value check |
| 29 | + for r := 0; r < boxSize; r++ { |
| 30 | + for c := 0; c < boxSize; c++ { |
| 31 | + br := boxRow + r |
| 32 | + bc := boxCol + c |
| 33 | + if br == row && bc == col { |
| 34 | + gameLayout.drawHighLightCover(screen, row, col) |
| 35 | + break |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +func (gameLayout *GameLayout) drawHighLightCover(screen *ebiten.Image, row, col int) { |
| 42 | + xPos := col * cellSize |
| 43 | + yPos := PanelHeight + row*cellSize |
| 44 | + // stable blue |
| 45 | + bgColor := color.RGBA{0x6a, 0x5a, 0xcd, 128} |
| 46 | + if col%3 == 0 { |
| 47 | + xPos += thinkLineWidth |
| 48 | + } else { |
| 49 | + xPos += leanLineWidth |
| 50 | + } |
| 51 | + if row%3 == 0 { |
| 52 | + yPos += thinkLineWidth |
| 53 | + } else { |
| 54 | + yPos += leanLineWidth |
| 55 | + } |
| 56 | + vector.DrawFilledRect( |
| 57 | + screen, |
| 58 | + float32(xPos), |
| 59 | + float32(yPos), |
| 60 | + cellSize-1, |
| 61 | + cellSize-1, |
| 62 | + bgColor, |
| 63 | + false, |
| 64 | + ) |
| 65 | +} |
0 commit comments