From c944be15f93a0209f783eee80639c2e26e0fe8c4 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Mon, 10 Nov 2014 17:22:13 -0500 Subject: [PATCH] define a game object --- game.go | 22 +++++++++++++++++++++- main.go | 10 +++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/game.go b/game.go index 8e3bd52..30a96fa 100644 --- a/game.go +++ b/game.go @@ -14,7 +14,7 @@ type Game struct { func gamesTable() { stmnt := `create table if not exists games ( id integer not null primary key autoincrement, - start text, + start text not null, end text, winner text, win_method text @@ -23,3 +23,23 @@ func gamesTable() { 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 +} diff --git a/main.go b/main.go index 92096c5..6f26e4c 100644 --- a/main.go +++ b/main.go @@ -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{}) { @@ -97,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 {