feat: westworldwithwoman. add elsa
This commit is contained in:
1 parent
2764849943
commit
0e7482e04c
28 files changed
+1946
No files matched your search
@@ -0,0 +1,48 @@
|
||||
package westworldwithwoman
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// doHousework is Elsa's everyday default state - the singleton
|
||||
// pattern is the same one used throughout this package.
|
||||
type doHousework struct{}
|
||||
|
||||
var (
|
||||
doHouseworkInstance *doHousework
|
||||
doHouseworkOnce sync.Once
|
||||
)
|
||||
|
||||
// DoHousework is the Go stand-in for "DoHousework::Instance()".
|
||||
func DoHousework() *doHousework {
|
||||
doHouseworkOnce.Do(func() {
|
||||
doHouseworkInstance = &doHousework{}
|
||||
})
|
||||
return doHouseworkInstance
|
||||
}
|
||||
|
||||
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.
|
||||
var chores = []string{
|
||||
"Moppin' the floor",
|
||||
"Makin' the bed",
|
||||
}
|
||||
|
||||
// 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) {}
|
||||
|
||||
// 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.
|
||||
func (s *doHousework) Exit(e *Elsa) {}
|
||||
Reference in new issue
Block a user