@@ -24,18 +24,42 @@ type GameLayout struct {
2424}
2525
2626func (gameLayout * GameLayout ) Update () error {
27+ gameLayout .DetectCursor ()
28+ gameLayout .DetectInput ()
2729 return nil
2830}
2931
3032func (gameLayout * GameLayout ) Draw (screen * ebiten.Image ) {
3133 // 畫出基本背景
3234 gameLayout .drawBoardBackground (screen )
35+ // // 畫出 cursor
36+ gameLayout .drawCursor (screen )
3337 // 根據遊戲狀態來畫出盤面
3438 gameLayout .drawCellValuesOnBoard (screen )
3539 // 畫出盤面格線
3640 gameLayout .drawLinesOnBoard (screen )
3741}
3842
43+ func (gameLayout * GameLayout ) drawCursor (screen * ebiten.Image ) {
44+ cursorBgColor := color.RGBA {0xff , 0 , 0 , 128 }
45+ targetRow := gameLayout .gameInstance .Board .CursorRow
46+ targetCol := gameLayout .gameInstance .Board .CursorCol
47+ if gameLayout .gameInstance .Board .Cells [targetRow ][targetCol ].Type == game .Preset {
48+ cursorBgColor = color.RGBA {0xff , 0xff , 0 , 128 }
49+ }
50+ if gameLayout .gameInstance .Board .Cells [targetRow ][targetCol ].Type == game .Input {
51+ cursorBgColor = color.RGBA {0x00 , 0xff , 0x00 , 128 }
52+ }
53+ if gameLayout .gameInstance .Board .Cells [targetRow ][targetCol ].Type == game .InputConflict {
54+ cursorBgColor = color.RGBA {0x00 , 0xff , 0xff , 128 }
55+ }
56+ gameLayout .drawCellBackground (screen ,
57+ gameLayout .gameInstance .Board .CursorRow ,
58+ gameLayout .gameInstance .Board .CursorCol ,
59+ cursorBgColor ,
60+ )
61+ }
62+
3963// drawBoardBackground - 畫出盤面背景顏色
4064func (gameLayout * GameLayout ) drawBoardBackground (screen * ebiten.Image ) {
4165 boardBgColor := color.RGBA {0xFF , 0xFF , 0xFF , 0xFF }
@@ -50,8 +74,13 @@ func (gameLayout *GameLayout) drawCellValuesOnBoard(screen *ebiten.Image) {
5074 for row := 0 ; row < game .BoardSize ; row ++ {
5175 for col := 0 ; col < game .BoardSize ; col ++ {
5276 // draw preset value
53- if board.Cells [row ][col ].Type == game .Preset {
54- gameLayout .drawCellBackground (screen , row , col , getTileBgColor (board.Cells [row ][col ].Type ))
77+ if board.Cells [row ][col ].Type == game .Preset ||
78+ board.Cells [row ][col ].Type == game .Input ||
79+ board.Cells [row ][col ].Type == game .InputConflict {
80+ if row != gameLayout .gameInstance .Board .CursorRow ||
81+ col != gameLayout .gameInstance .Board .CursorCol {
82+ gameLayout .drawCellBackground (screen , row , col , getTileBgColor (board.Cells [row ][col ].Type ))
83+ }
5584 gameLayout .drawCellValue (screen , row , col , board.Cells [row ][col ].Value ,
5685 getTileColor (board.Cells [row ][col ].Type ),
5786 )
0 commit comments