docs(0.S): the doc fences migrated by ludic migrate state; LANGUAGE.md's state section says what the tool and the checker do now; no module-level var left in the docs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
19fcf60599
commit
a476ec7976
79 changed files with 481 additions and 355 deletions
|
|
@ -14,11 +14,13 @@ A <code>become</code> statement performs a transition. Inside a <code>machine</c
|
|||
```ludic
|
||||
program EncounterFlow {
|
||||
enum Stage { Explore, Battle, Victory }
|
||||
var stage: int = Stage.Explore
|
||||
var enemies_left: int = 2
|
||||
state EncounterFlowState {
|
||||
stage: int = Stage.Explore
|
||||
}
|
||||
let enemies_left: int = 2
|
||||
|
||||
handler RunStage phase Update {
|
||||
machine stage {
|
||||
handler RunStage(encounter_flow_st: mut EncounterFlowState) phase Update {
|
||||
machine encounter_flow_st.stage {
|
||||
state Explore {
|
||||
if Input.key() == ' ' { become Battle }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,12 +13,14 @@ order: 9
|
|||
|
||||
```ludic
|
||||
program FindFirst {
|
||||
var found: int = 0 - 1
|
||||
state FindFirstState {
|
||||
found: int = 0 - 1
|
||||
}
|
||||
|
||||
handler Scan phase Update {
|
||||
handler Scan(find_first_st: mut FindFirstState) phase Update {
|
||||
for i in 0 .. 10 {
|
||||
if i * i > 20 {
|
||||
found = i
|
||||
find_first_st.found = i
|
||||
break # stop at the first i whose square exceeds 20
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,12 +13,14 @@ order: 10
|
|||
|
||||
```ludic
|
||||
program SumOdds {
|
||||
var total: int = 0
|
||||
state SumOddsState {
|
||||
total: int = 0
|
||||
}
|
||||
|
||||
handler Add phase Update {
|
||||
handler Add(sum_odds_st: mut SumOddsState) phase Update {
|
||||
for i in 0 .. 10 {
|
||||
if i % 2 == 0 { continue } # skip even numbers
|
||||
total = total + i
|
||||
sum_odds_st.total = sum_odds_st.total + i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,12 @@ A <code>machine</code> turns an integer store into an explicit state machine, re
|
|||
```ludic
|
||||
program TurnOrder {
|
||||
enum Phase { KnightMenu, KnightResolve, EnemyTurn }
|
||||
var battle_phase: int = Phase.KnightMenu
|
||||
state TurnOrderState {
|
||||
battle_phase: int = Phase.KnightMenu
|
||||
}
|
||||
|
||||
handler RunTurn phase Update {
|
||||
machine battle_phase {
|
||||
handler RunTurn(turn_order_st: mut TurnOrderState) phase Update {
|
||||
machine turn_order_st.battle_phase {
|
||||
state KnightMenu {
|
||||
if Input.key() == ' ' { become KnightResolve }
|
||||
}
|
||||
|
|
@ -30,9 +32,9 @@ program TurnOrder {
|
|||
}
|
||||
}
|
||||
|
||||
handler DrawWorld phase Render {
|
||||
handler DrawWorld(turn_order_st: TurnOrderState) phase Render {
|
||||
Screen.clear(Color.MidnightBlue)
|
||||
Screen.draw_number(x: 8, y: 8, value: battle_phase, color: Color.Gold, scale: 2)
|
||||
Screen.draw_number(x: 8, y: 8, value: turn_order_st.battle_phase, color: Color.Gold, scale: 2)
|
||||
Screen.show()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,17 +14,19 @@ A <code>state</code> declares one state of an enclosing <code>machine</code>: a
|
|||
```ludic
|
||||
program DoorControl {
|
||||
enum DoorState { Closed, Opening, Open }
|
||||
var door: int = DoorState.Closed
|
||||
var elapsed_frames: int = 0
|
||||
state DoorControlState {
|
||||
door: int = DoorState.Closed
|
||||
elapsed_frames: int = 0
|
||||
}
|
||||
|
||||
handler RunDoor phase Update {
|
||||
machine door {
|
||||
handler RunDoor(door_control_st: mut DoorControlState) phase Update {
|
||||
machine door_control_st.door {
|
||||
state Closed {
|
||||
if Input.key() == ' ' { elapsed_frames = 0; become Opening }
|
||||
if Input.key() == ' ' { door_control_st.elapsed_frames = 0; become Opening }
|
||||
}
|
||||
state Opening {
|
||||
elapsed_frames = elapsed_frames + 1
|
||||
if elapsed_frames >= 30 { become Open }
|
||||
door_control_st.elapsed_frames = door_control_st.elapsed_frames + 1
|
||||
if door_control_st.elapsed_frames >= 30 { become Open }
|
||||
}
|
||||
state Open {
|
||||
Screen.status("door open")
|
||||
|
|
|
|||
|
|
@ -13,20 +13,22 @@ A <code>while</code> loop re-evaluates its condition before every pass and runs
|
|||
|
||||
```ludic
|
||||
program Countdown {
|
||||
var fuse: int = 5
|
||||
var elapsed_frames: int = 0
|
||||
state CountdownState {
|
||||
fuse: int = 5
|
||||
elapsed_frames: int = 0
|
||||
}
|
||||
|
||||
handler Tick phase Update {
|
||||
elapsed_frames = elapsed_frames + 1
|
||||
while fuse > 0 and elapsed_frames % 60 == 0 {
|
||||
fuse = fuse - 1
|
||||
elapsed_frames = elapsed_frames + 1
|
||||
handler Tick(countdown_st: mut CountdownState) phase Update {
|
||||
countdown_st.elapsed_frames = countdown_st.elapsed_frames + 1
|
||||
while countdown_st.fuse > 0 and countdown_st.elapsed_frames % 60 == 0 {
|
||||
countdown_st.fuse = countdown_st.fuse - 1
|
||||
countdown_st.elapsed_frames = countdown_st.elapsed_frames + 1
|
||||
}
|
||||
}
|
||||
|
||||
handler DrawWorld phase Render {
|
||||
handler DrawWorld(countdown_st: CountdownState) phase Render {
|
||||
Screen.clear(Color.MidnightBlue)
|
||||
Screen.draw_number(x: 8, y: 8, value: fuse, color: Color.Crimson, scale: 3)
|
||||
Screen.draw_number(x: 8, y: 8, value: countdown_st.fuse, color: Color.Crimson, scale: 3)
|
||||
Screen.show()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue