adding a status command for every player state

master
Jordan Orelli 6 years ago
parent 50128a64a6
commit 2914275282

@ -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))
}

@ -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")
}

@ -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{

@ -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)

@ -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")
}

@ -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")
}

@ -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")
}

@ -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",

@ -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")
}

@ -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
}

@ -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)
}

Loading…
Cancel
Save