feat(scala): m11 pong capstone (model, rules, view, app) with tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c6ecb7c013
commit
f4b671678e
10 files changed
+479
-1
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package snake
|
||||
package pong
|
||||
|
||||
import PongModel.*
|
||||
|
||||
/** m11 pong view: the same Scene shapes as the snake view, so the same drawScene and runtime draw it. */
|
||||
object PongView:
|
||||
|
||||
private def text(x: Int, y: Int, str: String, size: Int): Shape = Shape.Text(x, y, str, "#ffffff", size, "center")
|
||||
|
||||
private def paddle(column: Int, y: Int): Shape =
|
||||
Shape.Rect(column * PCELL, y * PCELL, PCELL, PADDLE * PCELL, "#ffffff")
|
||||
|
||||
private def overlay(state: PongState): Scene = state.status match
|
||||
case PongStatus.Over =>
|
||||
List(
|
||||
text(320, 200, if state.score.player > state.score.cpu then "You Win!" else "CPU Wins", 32),
|
||||
text(320, 230, "Press R to restart", 16)
|
||||
)
|
||||
case PongStatus.Playing => Nil
|
||||
|
||||
def pongView(state: PongState): Scene =
|
||||
List(
|
||||
Shape.Rect(0, 0, 640, 400, "#111111"),
|
||||
paddle(PLAYER_X, state.player),
|
||||
paddle(CPU_X, state.cpu),
|
||||
Shape.Rect(state.ball.x * PCELL, state.ball.y * PCELL, PCELL, PCELL, "#ffeb3b"),
|
||||
text(320, 30, s"${state.score.player} ${state.score.cpu}", 24)
|
||||
) ++ overlay(state)
|
||||
Reference in new issue
Block a user