@@ -11,8 +11,8 @@ import (
1111 "github.com/leetcode-golang-classroom/2048-game/internal/game"
1212)
1313
14- var restartButtonRect = image .Rect (165 , 250 , 285 , 300 ) // X1,Y1,X2,Y2
15-
14+ var restartButtonRect = image .Rect (165 , 250 , 285 , 300 ) // X1,Y1,X2,Y2
15+ var continueButtonRect = image . Rect ( 145 , 250 , 305 , 300 ) // X1,Y1,X2,Y2
1616const (
1717 tileSize = 100
1818 gridSize = 4
@@ -24,6 +24,8 @@ const (
2424type GameLayout struct {
2525 gameInstance * game.Game
2626 isGameOver bool
27+ isPlayerWin bool
28+ isContinue bool
2729}
2830
2931// drawCell - 透過目前值來畫出目前 cell 的格子顏色
@@ -63,6 +65,10 @@ func (g *GameLayout) Draw(screen *ebiten.Image) {
6365 screen .Fill (color.RGBA {250 , 248 , 239 , 255 })
6466 // 畫出目前局面
6567 g .drawBoard (screen )
68+ // 當完成了 2048 條件 顯示 You Win 與 Continue button
69+ if g .isPlayerWin && ! g .isContinue {
70+ g .drawYouWin (screen )
71+ }
6672 // 當 gameOver 顯示 GameOver
6773 if g .isGameOver {
6874 g .drawGameOver (screen )
@@ -113,6 +119,56 @@ func (g *GameLayout) drawGameOver(screen *ebiten.Image) {
113119 g .drawRestartButton (screen )
114120}
115121
122+ func (g * GameLayout ) drawConverOnYouWin (screen * ebiten.Image ) {
123+ w , h := screen .Bounds ().Dx (), screen .Bounds ().Dy ()
124+ vector .DrawFilledRect (
125+ screen ,
126+ 0 , 0 , // x, y
127+ float32 (w ), float32 (h ), // width, height
128+ color.RGBA {100 , 100 , 0 , 60 }, // 半透明黃色 (128 = 約 50% 透明)
129+ false ,
130+ )
131+ }
132+
133+ // drawYouWin 畫出 You Win
134+ func (g * GameLayout ) drawYouWin (screen * ebiten.Image ) {
135+ g .drawConverOnYouWin (screen )
136+ // 設定顯示 Game Over 文字
137+ textXPos := WinHeight / 2
138+ textYPos := WinWidth / 2
139+ textOpts := & text.DrawOptions {}
140+ textOpts .ColorScale .ScaleWithColor (color.RGBA {220 , 220 , 0 , 255 })
141+ textOpts .PrimaryAlign = text .AlignCenter
142+ textOpts .SecondaryAlign = text .AlignCenter
143+ textOpts .GeoM .Translate (float64 (textXPos ), float64 (textYPos ))
144+ text .Draw (screen , "You Win" , & text.GoTextFace {
145+ Source : mplusFaceSource ,
146+ Size : 48.0 ,
147+ }, textOpts )
148+ g .drawContinueButton (screen )
149+ }
150+
151+ func (g * GameLayout ) drawContinueButton (screen * ebiten.Image ) {
152+ // 畫 Restart 按鈕
153+ vector .DrawFilledRect (screen ,
154+ float32 (continueButtonRect .Min .X ),
155+ float32 (continueButtonRect .Min .Y ),
156+ float32 (continueButtonRect .Dx ()),
157+ float32 (continueButtonRect .Dy ()),
158+ color.RGBA {100 , 100 , 100 , 200 },
159+ true ,
160+ )
161+ textOpts := & text.DrawOptions {}
162+ textOpts .ColorScale .ScaleWithColor (color .Black )
163+ textOpts .PrimaryAlign = text .AlignCenter
164+ textOpts .SecondaryAlign = text .AlignCenter
165+ textOpts .GeoM .Translate (float64 (continueButtonRect .Min .X + continueButtonRect .Dx ()/ 2 ), float64 (continueButtonRect .Min .Y + continueButtonRect .Dy ()/ 2 ))
166+ text .Draw (screen , "Continue" , & text.GoTextFace {
167+ Source : mplusFaceSource ,
168+ Size : 30 ,
169+ }, textOpts )
170+ }
171+
116172// drawRestartButton - 畫出 restart button
117173func (g * GameLayout ) drawRestartButton (screen * ebiten.Image ) {
118174 // 畫 Restart 按鈕
0 commit comments