cleaning up enter travel text

master
Jordan Orelli 5 years ago
parent 2914275282
commit 8cdd7bdaa6

@ -3,6 +3,7 @@ package main
import (
"fmt"
"strings"
"text/template"
)
var commandRegistry map[string]*Command
@ -102,6 +103,27 @@ are farther away take longer to communicate with.
},
}
type status struct {
State string
Balance int
Bombs int
Kills int
Location string
Description string
}
var statusTemplate = template.Must(template.New("status").Parse(`
********************************************************************************
Current State: {{.State}}
Balance: {{.Balance}}
Bombs: {{.Bombs}}
Kills: {{.Kills}}
Location: {{.Location}}
{{.Description}}
********************************************************************************
`))
var statusCommand = Command{
name: "status",
help: "display your current status",

@ -2,6 +2,7 @@ package main
import (
"fmt"
"text/template"
"time"
)
@ -33,20 +34,35 @@ func NewTravel(c *Connection, start, dest *System) ConnectionState {
help: "displays estimated time of arrival",
arity: 0,
handler: func(c *Connection, args ...string) {
c.Printf("Remaining: %v\n", t.remaining())
c.Printf("Current time: %v\n", time.Now())
c.Printf("ETA: %v\n", t.eta())
c.Printf("%v\n", t.remaining())
},
},
}
return t
}
var enterTravelTemplate = template.Must(template.New("enter-travel").Parse(`
Departing: {{.Departing}}
Destination: {{.Destination}}
Total Trip Time: {{.Duration}}
Current Time: {{.Time}}
ETA: {{.ETA}}
`))
func (t *TravelState) Enter(c *Connection) {
c.Printf("Leaving %v, bound for %v.\n", t.start, t.dest)
c.Printf("Trip duration: %v\n", t.tripTime())
c.Printf("Current time: %v\n", time.Now())
c.Printf("ETA: %v\n", t.eta())
enterTravelTemplate.Execute(c, struct {
Departing *System
Destination *System
Duration time.Duration
Time time.Time
ETA time.Time
}{
t.start,
t.dest,
t.tripTime(),
time.Now(),
t.eta(),
})
t.start.Leave(c)
}
@ -68,7 +84,15 @@ func (t *TravelState) String() string {
}
func (t *TravelState) PrintStatus(c *Connection) {
panic("not done")
desc := fmt.Sprintf("Traveling from %v to %v", t.start, t.dest)
statusTemplate.Execute(c, status{
State: "In Transit",
Balance: c.money,
Bombs: c.bombs,
Kills: c.kills,
Location: fmt.Sprintf("%s -> %s", t.start, t.dest),
Description: desc,
})
}
func (t *TravelState) progress(c *Connection, args ...string) {

Loading…
Cancel
Save