allow object specification

This commit is contained in:
Stephen McQuay 2013-11-16 19:57:13 -08:00
parent f6b3027ded
commit 5a2651d0dd
3 changed files with 11 additions and 7 deletions

View File

@ -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 {

View File

@ -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,

View File

@ -165,6 +165,7 @@ func addPlayer(ws *websocket.Conn) {
gid.Id,
float32(conf.Width),
float32(conf.Height),
conf.Obstacles,
conf.Tick,
)
go game.run()