diff --git a/config.go b/config.go index 6497160..01e999b 100644 --- a/config.go +++ b/config.go @@ -18,15 +18,17 @@ type Config struct { Height int `json:"height"` Obstacles int `json:"obstacles"` MaxPoints int `json:"max_points"` + Mode string `json:"mode"` } const ( - TICK = 60 - TIMESCALE = 1.0 - WIDTH = 800 - HEIGHT = 550 - OBSTACLES = 5 - MAX_POINTS = 500 // allowing for 50 pts in every category + TICK = 60 + TIMESCALE = 1.0 + WIDTH = 800 + HEIGHT = 550 + OBSTACLES = 5 + MAX_POINTS = 500 // allowing for 50 pts in every category + DEFAULT_MODE = "deathmatch" ) func loadConfig(filename string) (Config, error) { @@ -37,6 +39,7 @@ func loadConfig(filename string) (Config, error) { Height: HEIGHT, Obstacles: OBSTACLES, MaxPoints: MAX_POINTS, + Mode: DEFAULT_MODE, } u, err := user.Current() if err != nil { diff --git a/control.go b/control.go index fde3957..05a9287 100644 --- a/control.go +++ b/control.go @@ -24,8 +24,8 @@ 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 maxPoints := conf.MaxPoints + mode := "deathmatch" // here we determine if we are going to run with defaults or pick them off // a posted json blob @@ -50,14 +50,14 @@ func startGame(w http.ResponseWriter, req *http.Request) { width = float32(cfg.Width) height = float32(cfg.Height) obstacles = cfg.Obstacles - tick = cfg.Tick maxPoints = cfg.MaxPoints + mode = cfg.Mode } 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, maxPoints) + g = NewGame(requested_game_name, width, height, obstacles, conf.Tick, maxPoints, mode) go g.run() games.add(g) } else { diff --git a/game.go b/game.go index 2602cce..7af2b66 100644 --- a/game.go +++ b/game.go @@ -75,7 +75,7 @@ type GameMode interface { gameOver(gg *game) (bool, *GameOver) } -func NewGame(id string, width, height float32, obstacles, tick, maxPoints int) *game { +func NewGame(id string, width, height float32, obstacles, tick, maxPoints int, mode string) *game { g := &game{ id: id, register: make(chan *player), @@ -98,7 +98,12 @@ func NewGame(id string, width, height float32, obstacles, tick, maxPoints int) * tick_duration: tick, players_remaining: 2, winners: WinnerMap{m: make(map[string]int)}, - mode: &melee{respawn: make(map[*Robot]float64)}, + } + + if mode == "melee" { + g.mode = &melee{respawn: make(map[*Robot]float64)} + } else { + g.mode = &deathmatch{} } g.mode.setup(g) diff --git a/protocol.go b/protocol.go index fd3393d..d028241 100644 --- a/protocol.go +++ b/protocol.go @@ -167,6 +167,7 @@ func addPlayer(ws *websocket.Conn) { conf.Obstacles, conf.Tick, conf.MaxPoints, + "", ) go game.run() games.add(game)