@@ -21,7 +21,7 @@ const (
2121 PaddingY = 20 // 面板
2222 ScreenHeight = PanelHeight + gridSize * Rows
2323 ScreenWidth = gridSize * Cols
24- MineCounts = 9
24+ MineCounts = 10
2525)
2626
2727var buttonRectRelativePos = image .Rect (0 , 0 , 32 , 32 ) // 一個方格大小的 button
@@ -30,9 +30,12 @@ type Coord struct {
3030 Row int
3131 Col int
3232}
33+
34+ // 遊戲畫面狀態
3335type GameLayout struct {
34- gameInstance * game.Game
35- ClickCoord * Coord
36+ gameInstance * game.Game // 遊戲物件
37+ ClickCoord * Coord // 使用者點擊座標
38+ elapsedTime int // 經過時間
3639}
3740
3841func NewGameLayout (gameInstance * game.Game ) * GameLayout {
@@ -50,6 +53,10 @@ func (g *GameLayout) Update() error {
5053 g .Restart ()
5154 }
5255 }
56+ // 當遊戲還沒停止時,就更新經過時間
57+ if ! g .gameInstance .IsGameOver && ! g .gameInstance .IsPlayerWin {
58+ g .elapsedTime = g .gameInstance .GetElapsedTime ()
59+ }
5360 // 當狀態為遊戲結束
5461 if g .gameInstance .IsGameOver || g .gameInstance .IsPlayerWin {
5562 return nil
@@ -163,7 +170,7 @@ func (g *GameLayout) drawFlag(screen *ebiten.Image, row, col int) {
163170 textXPos := col * gridSize + (gridSize )/ 2
164171 textYPos := PanelHeight + row * gridSize + (gridSize )/ 2
165172 textOpts := & text.DrawOptions {}
166- textOpts .ColorScale .ScaleWithColor (getTileColor (IsFlag ))
173+ textOpts .ColorScale .ScaleWithColor (getTileColor (- 1 ))
167174 textOpts .PrimaryAlign = text .AlignCenter
168175 textOpts .SecondaryAlign = text .AlignCenter
169176 textOpts .GeoM .Translate (float64 (textXPos ), float64 (textYPos ))
@@ -230,6 +237,8 @@ func (g *GameLayout) drawGamePanel(screen *ebiten.Image) {
230237 g .drawRemainingFlagInfo (screen )
231238 // 畫顯示狀態 button
232239 g .drawButtonWithIcon (screen , emojiIcon )
240+ // 畫出經過時間
241+ g .drawElaspedTimeInfo (screen )
233242}
234243
235244// drawButtonWithIcon - 繪製 buttonIcon
@@ -279,13 +288,42 @@ func (g *GameLayout) drawRemainingFlagInfo(screen *ebiten.Image) {
279288 emojiXPos := len (emojiValue )
280289 emojiYPos := PaddingY
281290 emojiOpts := & text.DrawOptions {}
282- emojiOpts .ColorScale .ScaleWithColor (getTileColor (- 1 ))
291+ emojiOpts .ColorScale .ScaleWithColor (getTileColor (IsFlag ))
283292 emojiOpts .PrimaryAlign = text .AlignStart
284293 emojiOpts .SecondaryAlign = text .AlignCenter
285294 emojiOpts .GeoM .Translate (float64 (emojiXPos ), float64 (emojiYPos ))
286295 text .Draw (screen , emojiValue , & text.GoTextFace {
287296 Source : emojiFaceSource ,
297+ Size : 30 ,
298+ }, emojiOpts )
299+ }
300+
301+ // drawElaspedTimeInfo
302+ func (g * GameLayout ) drawElaspedTimeInfo (screen * ebiten.Image ) {
303+ // 畫旗子面板(固定在左方)
304+ textValue := fmt .Sprintf ("%03d" , g .elapsedTime )
305+ textXPos := ScreenWidth - gridSize / 2 + len (textValue )
306+ textYPos := PaddingY
307+ textOpts := & text.DrawOptions {}
308+ textOpts .ColorScale .ScaleWithColor (getTileColor (- 1 ))
309+ textOpts .PrimaryAlign = text .AlignEnd
310+ textOpts .SecondaryAlign = text .AlignCenter
311+ textOpts .GeoM .Translate (float64 (textXPos ), float64 (textYPos ))
312+ text .Draw (screen , textValue , & text.GoTextFace {
313+ Source : mplusFaceSource ,
288314 Size : 20 ,
315+ }, textOpts )
316+ emojiValue := "⏰"
317+ emojiXPos := ScreenWidth - 3 * gridSize + len (emojiValue )
318+ emojiYPos := PaddingY
319+ emojiOpts := & text.DrawOptions {}
320+ emojiOpts .ColorScale .ScaleWithColor (getTileColor (IsClock ))
321+ emojiOpts .PrimaryAlign = text .AlignStart
322+ emojiOpts .SecondaryAlign = text .AlignCenter
323+ emojiOpts .GeoM .Translate (float64 (emojiXPos ), float64 (emojiYPos ))
324+ text .Draw (screen , emojiValue , & text.GoTextFace {
325+ Source : emojiFaceSource ,
326+ Size : 30 ,
289327 }, emojiOpts )
290328}
291329
0 commit comments