feat: finalize with step 5

This commit is contained in:
jonas committed 2026-09-03 23:39:25 +02:00
1 parent 129dd5d8b8
commit aab128b55c
10 files changed
+332 -37

No files matched your search

@@ -26,25 +26,33 @@ func DoHousework() *doHousework {
var _ State[Elsa] = (*doHousework)(nil)
// chores is our own small stand-in for the book's actual chore list
// - it only ever showed two examples in its sample output ("Moppin'
// the floor", "Makin' the bed"), so that's exactly what's reused
// here. One gets picked at random each tick.
// - its sample output shows three examples ("Moppin' the floor",
// "Makin' the bed", "Washin' the dishes"), so that's exactly what's
// reused here. One gets picked at random each tick.
var chores = []string{
"Moppin' the floor",
"Makin' the bed",
"Washin' the dishes",
}
// Enter does nothing - the book's sample output never shows a
// message when Elsa starts doing housework, only while she's doing
// it (Execute) and when she leaves the bathroom back into it.
func (s *doHousework) Enter(e *Elsa) {}
// Enter announces that Elsa is back to her ordinary routine. A
// sample run of the book's program shows this line printed right
// after she finishes cooking and switches back to this state - an
// earlier, more abridged sample output we saw didn't show this line
// after a bathroom-break revert, but that sample was explicitly
// described as just "a sample," not a complete transcript, so this
// message firing every time Enter runs (bathroom revert included)
// isn't a contradiction.
func (s *doHousework) Enter(e *Elsa) {
fmt.Printf("\n%s: Time to do some more housework!", GetNameOfEntity(e.ID()))
}
// Execute announces one randomly chosen chore per tick.
func (s *doHousework) Execute(e *Elsa) {
fmt.Printf("\n%s: %s", GetNameOfEntity(e.ID()), chores[rand.Intn(len(chores))])
}
// Exit does nothing, for the same reason as Enter.
// Exit does nothing - no sample output ever shows a message here.
func (s *doHousework) Exit(e *Elsa) {}
// OnMessage is required now that State[T] includes it, so that every