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,47 @@
|
||||
package westworldwithwoman
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// visitBathroom is a "blip" state: it interrupts whatever Elsa was
|
||||
// doing, does its one bit of business, and immediately hands control
|
||||
// straight back to whatever she was doing before - it never leads
|
||||
// anywhere new on its own.
|
||||
type visitBathroom struct{}
|
||||
|
||||
var (
|
||||
visitBathroomInstance *visitBathroom
|
||||
visitBathroomOnce sync.Once
|
||||
)
|
||||
|
||||
// VisitBathroom is the Go stand-in for "VisitBathroom::Instance()".
|
||||
func VisitBathroom() *visitBathroom {
|
||||
visitBathroomOnce.Do(func() {
|
||||
visitBathroomInstance = &visitBathroom{}
|
||||
})
|
||||
return visitBathroomInstance
|
||||
}
|
||||
|
||||
var _ State[Elsa] = (*visitBathroom)(nil)
|
||||
|
||||
// Enter announces the trip to the bathroom.
|
||||
func (s *visitBathroom) Enter(e *Elsa) {
|
||||
fmt.Printf("\n%s: Walkin' to the can. Need to powda mah pretty li'l nose", GetNameOfEntity(e.ID()))
|
||||
}
|
||||
|
||||
// Execute is the entire "blip": do the business, then immediately
|
||||
// revert to whatever state was active before VisitBathroom
|
||||
// interrupted it. RevertToPreviousState runs the normal ChangeState
|
||||
// dance (Exit here, Enter there), so nothing extra is needed.
|
||||
func (s *visitBathroom) Execute(e *Elsa) {
|
||||
fmt.Printf("\n%s: Ahhhhhh! Sweet relief!", GetNameOfEntity(e.ID()))
|
||||
e.FSM().RevertToPreviousState()
|
||||
}
|
||||
|
||||
// Exit announces leaving the bathroom - this runs automatically as
|
||||
// part of the RevertToPreviousState call above.
|
||||
func (s *visitBathroom) Exit(e *Elsa) {
|
||||
fmt.Printf("\n%s: Leavin' the john", GetNameOfEntity(e.ID()))
|
||||
}
|
||||
Reference in new issue
Block a user