24 lines
1.1 KiB
FSharp
24 lines
1.1 KiB
FSharp
/// m06 view: from game state to a Scene. The picture is plain data; drawing it is somebody else's job (m07).
|
|
module Snake.View
|
|
|
|
open Snake.Model
|
|
|
|
/// A thing to draw.
|
|
type Shape =
|
|
| Rect of x: int * y: int * w: int * h: int * color: string
|
|
| Text of x: int * y: int * text: string * color: string * size: int * align: string
|
|
|
|
/// A picture: shapes drawn in order.
|
|
type Scene = Shape list
|
|
|
|
/// Pixels per board cell.
|
|
let CELL = 20
|
|
|
|
/// Describe the picture as data, in this order: background `Rect(0, 0, Width*CELL, Height*CELL, "#111111")`;
|
|
/// the apple (if any) as `Rect(ax*CELL+1, ay*CELL+1, CELL-2, CELL-2, "#e53935")`; each snake segment in list order,
|
|
/// same size, head "#7cb342" and body "#43a047"; `Text(6, 18, "Score: <n>", "#ffffff", 16, "left")`;
|
|
/// then an overlay centred at (Width*CELL/2, Height*CELL/2), all "#ffffff", align "center":
|
|
/// Paused: "Paused" (size 32) and, 30px lower, "Press Space to resume" (size 16);
|
|
/// GameOver: "Game Over" + "Press R to restart"; Won: "You Win!" + "Press R to restart"; Playing: none.
|
|
let view (state: GameState) : Scene = failwith "TODO m06"
|