|
|
|
@ -25,6 +25,7 @@ func startGame(w http.ResponseWriter, req *http.Request) {
|
|
|
|
|
width, height := float32(conf.Width), float32(conf.Height)
|
|
|
|
|
obstacles := 0
|
|
|
|
|
tick := conf.Tick
|
|
|
|
|
maxPoints := conf.MaxPoints
|
|
|
|
|
|
|
|
|
|
// here we determine if we are going to run with defaults or pick them off
|
|
|
|
|
// a posted json blob
|
|
|
|
@ -35,11 +36,8 @@ 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"`
|
|
|
|
|
Obstacles int `json:"obstacles"`
|
|
|
|
|
Tick int `json:"tick"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Config
|
|
|
|
|
}{}
|
|
|
|
|
err = json.Unmarshal(body, &cfg)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -49,21 +47,24 @@ func startGame(w http.ResponseWriter, req *http.Request) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
requested_game_name = cfg.Name
|
|
|
|
|
width = cfg.Width
|
|
|
|
|
height = cfg.Height
|
|
|
|
|
width = float32(cfg.Width)
|
|
|
|
|
height = float32(cfg.Height)
|
|
|
|
|
obstacles = cfg.Obstacles
|
|
|
|
|
tick = cfg.Tick
|
|
|
|
|
maxPoints = cfg.MaxPoints
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Printf("game info: %v %v %v %v", requested_game_name, width, height, tick)
|
|
|
|
|
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, obstacles, tick)
|
|
|
|
|
g = NewGame(requested_game_name, width, height, obstacles, tick, maxPoints)
|
|
|
|
|
go g.run()
|
|
|
|
|
games.add(g)
|
|
|
|
|
} else {
|
|
|
|
|
log.Printf("Game '%s' found: %p", requested_game_name, g)
|
|
|
|
|
log.Printf("Game '%s' already exists: %p", requested_game_name, g)
|
|
|
|
|
b, _ := json.Marshal(NewFailure("game already exists"))
|
|
|
|
|
http.Error(w, string(b), http.StatusConflict)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
game_json := struct {
|
|
|
|
|