From 5a2651d0ddae5b16ac3c6f3d8bcce7404f1b1299 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Sat, 16 Nov 2013 19:57:13 -0800 Subject: [PATCH] allow object specification --- control.go | 13 ++++++++----- game.go | 4 ++-- protocol.go | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/control.go b/control.go index 7a00c1d..a0276aa 100644 --- a/control.go +++ b/control.go @@ -23,6 +23,7 @@ func startGame(w http.ResponseWriter, req *http.Request) { requested_game_name := idg.Hash() width, height := float32(conf.Width), float32(conf.Height) + obstacles := 0 tick := conf.Tick // here we determine if we are going to run with defaults or pick them off @@ -34,10 +35,11 @@ func startGame(w http.ResponseWriter, req *http.Request) { } req.Body.Close() cfg := struct { - Width float32 `json:"width"` - Height float32 `json:"height"` - Name string `json:"name"` - Tick int `json:"tick"` + Width float32 `json:"width"` + Height float32 `json:"height"` + Name string `json:"name"` + Obstacles int `json:"obstacles"` + Tick int `json:"tick"` }{} err = json.Unmarshal(body, &cfg) if err != nil { @@ -49,6 +51,7 @@ func startGame(w http.ResponseWriter, req *http.Request) { requested_game_name = cfg.Name width = cfg.Width height = cfg.Height + obstacles = cfg.Obstacles tick = cfg.Tick } @@ -56,7 +59,7 @@ func startGame(w http.ResponseWriter, req *http.Request) { g := games.get(requested_game_name) if g == nil { log.Printf("Game '%s' non-existant; making it now", requested_game_name) - g = NewGame(requested_game_name, width, height, tick) + g = NewGame(requested_game_name, width, height, obstacles, tick) go g.run() games.add(g) } else { diff --git a/game.go b/game.go index 7cf264f..623b277 100644 --- a/game.go +++ b/game.go @@ -66,14 +66,14 @@ type game struct { winners WinnerMap } -func NewGame(id string, width, height float32, tick int) *game { +func NewGame(id string, width, height float32, obstacles, tick int) *game { g := &game{ id: id, register: make(chan *player), unregister: make(chan *player, maxPlayer), projectiles: make(map[*Projectile]bool), splosions: make(map[*Splosion]bool), - obstacles: GenerateObstacles(conf.Obstacles, width, height), + obstacles: GenerateObstacles(obstacles, width, height), players: make(map[*player]bool), turn: 0, width: width, diff --git a/protocol.go b/protocol.go index 091c089..57e8eb1 100644 --- a/protocol.go +++ b/protocol.go @@ -165,6 +165,7 @@ func addPlayer(ws *websocket.Conn) { gid.Id, float32(conf.Width), float32(conf.Height), + conf.Obstacles, conf.Tick, ) go game.run()