add a games table

slack
Jordan Orelli 10 years ago
parent 18893f6489
commit 42fb45fac8

@ -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,25 @@
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,
end text,
winner text,
win_method text
);`
if _, err := db.Exec(stmnt); err != nil {
log_error("couldn't create games table: %v", err)
}
}

@ -49,7 +49,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 +58,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)

Loading…
Cancel
Save