25 lines
933 B
FSharp
25 lines
933 B
FSharp
/// 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
|