mining stuff

slack
Jordan Orelli 10 years ago
parent 44663f02cd
commit 0ccc2f91b5

@ -208,14 +208,6 @@ var commandsCommand = Command{
// },
// }
// var mineCommand = &Command{
// name: "mine",
// help: "mines the current system for resources",
// handler: func(conn *Connection, args ...string) {
// conn.Mine()
// },
// }
// var colonizeCommand = &Command{
// name: "colonize",
// help: "establishes a mining colony on the current system",

@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net"
"sort"
"strings"
"time"
)
@ -90,10 +91,18 @@ func (c *Connection) RunCommand(name string, args ...string) {
}()
switch name {
case "commands":
c.Line()
commands := c.Commands()
for _, command := range commands {
c.Printf("%s\n", command.name)
names := make([]string, len(commands))
for i := range commands {
names[i] = commands[i].name
}
sort.Strings(names)
for _, name := range names {
cmd := c.GetCommand(name)
c.Printf("%-20s%s\n", name, cmd.help)
}
c.Line()
return
}
@ -157,6 +166,10 @@ func (c *Connection) ReadLines(out chan []string) {
}
}
func (c *Connection) Line() {
c.Printf("--------------------------------------------------------------------------------\n")
}
func (c *Connection) Printf(template string, args ...interface{}) (int, error) {
return fmt.Fprintf(c, template, args...)
}

@ -7,6 +7,8 @@ import (
type IdleState struct {
CommandSuite
NopEnter
NopExit
*System
}
@ -35,6 +37,18 @@ func Idle(sys *System) ConnectionState {
arity: 1,
handler: i.bomb,
},
Command{
name: "mine",
help: "mine the current system for resources",
arity: 0,
handler: i.mine,
},
Command{
name: "info",
help: "gives you information about the current star system",
arity: 0,
handler: i.info,
},
}
return i
}
@ -43,18 +57,10 @@ func (i *IdleState) String() string {
return fmt.Sprintf("idle on %v", i.System)
}
func (i *IdleState) Enter(c *Connection) {
c.Printf("You have landed on %v.\n", i.System)
}
func (i *IdleState) Tick(c *Connection, frame int64) ConnectionState {
return i
}
func (i *IdleState) Exit(c *Connection) {
c.Printf("Now leaving %v.\n", i.System)
}
func (i *IdleState) travelTo(c *Connection, args ...string) {
dest, err := GetSystem(args[0])
if err != nil {
@ -101,3 +107,11 @@ func (i *IdleState) bomb(c *Connection, args ...string) {
bomb := NewBomb(c, i.System, target)
currentGame.Register(bomb)
}
func (i *IdleState) mine(c *Connection, args ...string) {
c.SetState(Mine(i.System))
}
func (i *IdleState) info(c *Connection, args ...string) {
c.Printf("Currently idle on system %v\n", i.System)
}

@ -6,38 +6,66 @@ import (
type MiningState struct {
CommandSuite
sys *System
*System
mined int
}
func Mine(sys *System) ConnectionState {
return &MiningState{sys: sys}
m := &MiningState{System: sys}
m.CommandSuite = CommandSet{
balCommand,
helpCommand,
playersCommand,
Command{
name: "stop",
help: "stops mining",
arity: 0,
handler: m.stop,
},
Command{
name: "info",
help: "gives you information about the current mining operation",
arity: 0,
handler: m.info,
},
}
return m
}
func (m *MiningState) Enter(c *Connection) {
c.Printf("Mining %v. %v space duckets remaining.\n", m.sys, m.sys.money)
c.Printf("Mining %v. %v space duckets remaining.\n", m.System, m.money)
}
func (m *MiningState) Tick(c *Connection, frame int64) ConnectionState {
if m.sys.money <= 0 {
c.Printf("system %s is all out of space duckets.\n", m.sys)
return Idle(m.sys)
if m.money <= 0 {
c.Printf("system %s is all out of space duckets.\n", m.System)
return Idle(m.System)
} else {
c.Deposit(1)
m.mined += 1
m.sys.money -= 1
m.money -= 1
return m
}
}
func (m *MiningState) Exit(c *Connection) {
if m.sys.money == 0 {
c.Printf("Done mining %v. Mined %v space duckets total. %v space duckets remain on %v, and it can be mined again.", m.sys, m.mined, m.sys.money, m.sys)
if m.money == 0 {
c.Printf("Done mining %v.\nMined %v space duckets total.\nNo space duckets remain on %v, and it can't be mined again.\n", m.System, m.mined, m.System)
} else {
c.Printf("Done mining %v. Mined %v space duckets total. No space duckets remain on %v, and it can't be mined again.", m.sys, m.mined, m.sys)
c.Printf("Done mining %v.\nMined %v space duckets total.\n%v space duckets remain on %v, and it can be mined again.\n", m.System, m.mined, m.money, m.System)
}
}
func (m *MiningState) String() string {
return fmt.Sprintf("mining %v", m.sys)
return fmt.Sprintf("mining %v", m.System)
}
func (m *MiningState) stop(c *Connection, args ...string) {
c.SetState(Idle(m.System))
}
func (m *MiningState) info(c *Connection, args ...string) {
c.Printf("Currently mining system %v\n", m.System)
c.Printf("Mined so far: %v\n", m.mined)
c.Printf("Remaining space duckets on %v: %v\n", m.System, m.money)
}

Loading…
Cancel
Save