@@ -3,6 +3,7 @@ package layout
33import (
44 "fmt"
55 "image/color"
6+ "time"
67
78 "github.com/hajimehoshi/ebiten/v2"
89 "github.com/hajimehoshi/ebiten/v2/text/v2"
@@ -20,16 +21,18 @@ const (
2021)
2122
2223type GameLayout struct {
23- gameInstance * game.Game
24- difficulty game.Difficulty
25- isPlayerWin bool
24+ gameInstance * game.Game
25+ difficulty game.Difficulty
26+ isPlayerWin bool
27+ elapsedSeconds int
2628}
2729
2830func (gameLayout * GameLayout ) Update () error {
2931 gameLayout .handleRestartButton ()
3032 if gameLayout .isPlayerWin {
3133 return nil
3234 }
35+ gameLayout .elapsedSeconds = gameLayout .gameInstance .GetElaspedTime ()
3336 gameLayout .DetectCursor ()
3437 gameLayout .DetectInput ()
3538 // 檢查狀態
@@ -45,6 +48,7 @@ func (gameLayout *GameLayout) Draw(screen *ebiten.Image) {
4548 gameLayout .drawBugCount (screen )
4649 gameLayout .drawBoardStatus (screen )
4750 gameLayout .drawRestartButton (screen )
51+ gameLayout .drawTimeLayout (screen )
4852 // 畫出 cursor
4953 gameLayout .drawCursor (screen )
5054 // 根據遊戲狀態來畫出盤面
@@ -144,6 +148,7 @@ func NewGameLayout() *GameLayout {
144148 gameInstance .Board .GenerateSolution ()
145149 defaultDifficulty := game .Easy
146150 gameInstance .Board .MakePuzzleFromSolution (int (defaultDifficulty ))
151+ gameInstance .StartTime = time .Now ().UTC ()
147152 return & GameLayout {
148153 gameInstance : gameInstance ,
149154 difficulty : defaultDifficulty ,
0 commit comments