diff --git a/bomb.go b/bomb.go index 2de4859..26a4ba6 100644 --- a/bomb.go +++ b/bomb.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "strings" "time" ) @@ -81,3 +82,17 @@ func (m *MakeBombState) Exit(c *Connection) { c.bombs += 1 c.Printf("Done! You now have %v bombs.\n", c.bombs) } + +func (m *MakeBombState) PrintStatus(c *Connection) { + elapsedFrames := c.game.frame - m.start + elapsedDur := framesToDur(elapsedFrames) + + msg := fmt.Sprintf(` +Currently making a bomb! + +Current System: %s +Build time elapsed: %v +Build time remaining: %v +`, m.System, elapsedDur, options.makeBombTime-elapsedDur) + c.Printf(strings.TrimSpace(msg)) +} diff --git a/colony.go b/colony.go index 407d4f0..104b09b 100644 --- a/colony.go +++ b/colony.go @@ -48,3 +48,7 @@ func (m *MakeColonyState) Exit(c *Connection) { m.System.colonizedBy = c c.Printf("Established colony on %v.\n", m.System) } + +func (m *MakeColonyState) PrintStatus(c *Connection) { + panic("not done") +} diff --git a/commands.go b/commands.go index 417e1df..b9607a6 100644 --- a/commands.go +++ b/commands.go @@ -40,6 +40,8 @@ func (c CommandSet) GetCommand(name string) *Command { return &helpCommand case "commands": return &commandsCommand + case "status": + return &statusCommand } for _, cmd := range c { if cmd.name == name { @@ -50,7 +52,7 @@ func (c CommandSet) GetCommand(name string) *Command { } func (c CommandSet) Commands() []Command { - return append([]Command(c), helpCommand, commandsCommand) + return append([]Command(c), statusCommand, helpCommand, commandsCommand) } var helpCommand = Command{ @@ -100,6 +102,14 @@ are farther away take longer to communicate with. }, } +var statusCommand = Command{ + name: "status", + help: "display your current status", + handler: func(conn *Connection, args ...string) { + conn.ConnectionState.PrintStatus(conn) + }, +} + // this isn't a real command it just puts command in the list of commands, this // is weird and circular, this is a special case. var commandsCommand = Command{ diff --git a/connection.go b/connection.go index 2155dc1..49f665b 100644 --- a/connection.go +++ b/connection.go @@ -202,6 +202,7 @@ func (c *Connection) Die(frame int64) { type ConnectionState interface { CommandSuite String() string + PrintStatus(c *Connection) Enter(c *Connection) Tick(c *Connection, frame int64) ConnectionState Exit(c *Connection) diff --git a/dead.go b/dead.go index 2e0fbe8..6c241c1 100644 --- a/dead.go +++ b/dead.go @@ -29,3 +29,7 @@ func (d *DeadState) Exit(c *Connection) { func (d *DeadState) String() string { return "dead" } + +func (d *DeadState) PrintStatus(c *Connection) { + panic("not done") +} diff --git a/errors.go b/errors.go index cf5a90f..2cdecba 100644 --- a/errors.go +++ b/errors.go @@ -62,3 +62,7 @@ func (e *ErrorState) String() string { func (e *ErrorState) RunCommand(c *Connection, name string, args ...string) ConnectionState { return e } + +func (e *ErrorState) PrintStatus(c *Connection) { + panic("not done") +} diff --git a/idle.go b/idle.go index 40d3fc0..158ab6b 100644 --- a/idle.go +++ b/idle.go @@ -135,3 +135,7 @@ func (i *IdleState) maek(c *Connection, args ...string) { c.Printf("I don't know how to make a %v.\n", args[0]) } } + +func (i *IdleState) PrintStatus(c *Connection) { + panic("not done") +} diff --git a/lobby.go b/lobby.go index 43df51c..271bae9 100644 --- a/lobby.go +++ b/lobby.go @@ -92,6 +92,10 @@ func (st *LobbyState) Enter(c *Connection) { func (st *LobbyState) Tick(c *Connection, frame int64) ConnectionState { return st } +func (st *LobbyState) PrintStatus(c *Connection) { + panic("not done") +} + var newGameCommand = Command{ name: "new", help: "starts a new game", diff --git a/mining.go b/mining.go index be4c01b..c9b7bf1 100644 --- a/mining.go +++ b/mining.go @@ -70,3 +70,7 @@ func (m *MiningState) info(c *Connection, args ...string) { c.Printf("Mined so far: %v\n", m.mined) c.Printf("Remaining space duckets on %v: %v\n", m.System, m.money) } + +func (m *MiningState) PrintStatus(c *Connection) { + panic("not done") +} diff --git a/shield.go b/shield.go index 460abff..e564d91 100644 --- a/shield.go +++ b/shield.go @@ -46,6 +46,10 @@ func (m *MakeShieldState) String() string { return fmt.Sprintf("Making shield on %v", m.System) } +func (m *MakeShieldState) PrintStatus(c *Connection) { + panic("not done") +} + type Shield struct { energy float64 } diff --git a/travel.go b/travel.go index 6ca5c27..4dfb6cc 100644 --- a/travel.go +++ b/travel.go @@ -67,6 +67,10 @@ func (t *TravelState) String() string { return fmt.Sprintf("Traveling from %v to %v", t.start, t.dest) } +func (t *TravelState) PrintStatus(c *Connection) { + panic("not done") +} + func (t *TravelState) progress(c *Connection, args ...string) { c.Printf("%v\n", t.travelled/t.dist) }