From ac92962ef8122de4585b053584fa5720cb46b3d5 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 15 Nov 2014 20:51:11 -0500 Subject: [PATCH] you can make bombs again --- bomb.go | 30 ++++++++++++++++++++++++++++++ idle.go | 14 ++++++++++++++ main.go | 2 ++ 3 files changed, 46 insertions(+) diff --git a/bomb.go b/bomb.go index 3f2e66e..91d2a07 100644 --- a/bomb.go +++ b/bomb.go @@ -44,3 +44,33 @@ func (b *Bomb) Tick(frame int64) { func (b *Bomb) String() string { return fmt.Sprintf("[bomb from: %v to: %v lived: %s]", b.origin, b.target, time.Since(b.start)) } + +type MakeBombState struct { + CommandSuite + *System + start int64 +} + +func MakeBomb(s *System) ConnectionState { + m := &MakeBombState{System: s} + return m +} + +func (m *MakeBombState) Enter(c *Connection) { + c.Printf("Making a bomb...\n") +} + +func (m *MakeBombState) Tick(c *Connection, frame int64) ConnectionState { + if m.start == 0 { + m.start = frame + } + if framesToDur(frame-m.start) >= options.makeBombTime { + return Idle(m.System) + } + return m +} + +func (m *MakeBombState) Exit(c *Connection) { + c.bombs += 1 + c.Printf("Done! You now have %v bombs.\n", c.bombs) +} diff --git a/idle.go b/idle.go index fb4242d..c97abaf 100644 --- a/idle.go +++ b/idle.go @@ -53,6 +53,11 @@ func Idle(sys *System) ConnectionState { arity: 0, handler: i.scan, }, + Command{ + name: "make", + help: "makes things", + handler: i.maek, + }, } return i } @@ -131,3 +136,12 @@ func (i *IdleState) scan(c *Connection, args ...string) { c.Printf("Scanning the galaxy for signs of life...\n") currentGame.Register(NewScan(i.System)) } + +func (i *IdleState) maek(c *Connection, args ...string) { + switch args[0] { + case "bomb": + c.SetState(MakeBomb(i.System)) + default: + c.Printf("I don't know how to make a %v.\n", args[0]) + } +} diff --git a/main.go b/main.go index 72b720c..59e10bb 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ var options struct { frameRate int frameLength time.Duration lightSpeed float64 + makeBombTime time.Duration moneyMean float64 moneySigma float64 playerSpeed float64 @@ -114,4 +115,5 @@ func init() { flag.BoolVar(&options.debug, "debug", false, "puts the game in debug mode") flag.StringVar(&options.speckPath, "speck-path", "/projects/exo/expl.speck", "path to exoplanet speck file") flag.DurationVar(&options.respawnTime, "respawn-time", 60*time.Second, "time for player respawn") + flag.DurationVar(&options.makeBombTime, "bomb-time", 5*time.Second, "time it takes to make a bomb") }