Merge branch 'master' of github.com:jayson/exo

pull/5/head
JPaul 10 years ago
commit bcae376dd0

@ -231,6 +231,14 @@ var colonizeCommand = &Command{
},
}
var winCommand = &Command{
name: "win",
help: "win the game.",
handler: func(conn *Connection, args ...string) {
conn.Win()
},
}
func move(conn *Connection, to *System) {
start := conn.System()
start.Leave(conn)
@ -344,4 +352,5 @@ func init() {
registerCommand(nearbyCommand)
registerCommand(scanCommand)
registerCommand(mkBombCommand)
registerCommand(winCommand)
}

@ -68,6 +68,7 @@ func setupDb() {
planetsData()
edgesTable()
playersTable()
gamesTable()
fillEdges()
}

@ -0,0 +1,45 @@
package main
import (
"time"
)
type Game struct {
start time.Time
end time.Time
winner string
winMethod string
}
func gamesTable() {
stmnt := `create table if not exists games (
id integer not null primary key autoincrement,
start text not null,
end text,
winner text,
win_method text
);`
if _, err := db.Exec(stmnt); err != nil {
log_error("couldn't create games table: %v", err)
}
}
func NewGame() *Game {
game := &Game{
start: time.Now(),
}
if err := game.Create(); err != nil {
log_error("%v", err)
}
return game
}
func (g *Game) Create() error {
_, err := db.Exec(`
insert into games
(start)
values
(?)
;`, g.start)
return err
}

@ -12,9 +12,10 @@ import (
)
var (
dataPath = "/projects/exo/expl.speck"
info_log *log.Logger
error_log *log.Logger
dataPath = "/projects/exo/expl.speck"
info_log *log.Logger
error_log *log.Logger
currentGame *Game
)
func log_error(template string, args ...interface{}) {
@ -49,7 +50,6 @@ func handleConnection(conn *Connection) {
} else {
fmt.Fprintf(conn, "you are in the system %s. There are %d planets here.\n", system.name, system.planets)
}
READING:
for {
line, err := conn.ReadString('\n')
switch err {
@ -59,8 +59,7 @@ READING:
break
default:
log_error("failed to read line from player %s: %v", conn.PlayerName(), err)
time.Sleep(time.Second)
continue READING
return
}
line = strings.TrimSpace(line)
@ -99,6 +98,9 @@ func main() {
bail(E_No_Port, "unable to start server: %v", err)
}
go RunQueue()
currentGame = NewGame()
for {
conn, err := listener.Accept()
if err != nil {

Loading…
Cancel
Save