feat(fsharp): m11 pong capstone (model, rules, view, app) with tests
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
038a375027
commit
1d0b8c3a5c
@@ -0,0 +1,24 @@
|
||||
/// m11 pong view: the same Scene shapes as the snake view, so the same drawScene and runtime draw it.
|
||||
module Snake.Pong.View
|
||||
|
||||
open Snake.View
|
||||
open Snake.Pong.Model
|
||||
|
||||
let private text x y str size = Text(x, y, str, "#ffffff", size, "center")
|
||||
|
||||
let private paddle column y = Rect(column * PCELL, y * PCELL, PCELL, PADDLE * PCELL, "#ffffff")
|
||||
|
||||
let private overlay (state: PongState) : Scene =
|
||||
match state.Status with
|
||||
| PongStatus.Over ->
|
||||
[ 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 ]
|
||||
| PongStatus.Playing -> []
|
||||
|
||||
let pongView (state: PongState) : Scene =
|
||||
[ Rect(0, 0, 640, 400, "#111111")
|
||||
paddle PLAYER_X state.Player
|
||||
paddle CPU_X state.Cpu
|
||||
Rect(state.Ball.X * PCELL, state.Ball.Y * PCELL, PCELL, PCELL, "#ffeb3b")
|
||||
text 320 30 $"{state.Score.Player} {state.Score.Cpu}" 24 ]
|
||||
@ overlay state
|
||||
Reference in New Issue
Block a user