allow object specification
This commit is contained in:
+8
-5
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user