allow the control interface to specify game type
This commit is contained in:
parent
9583de2ffa
commit
90b7731865
@ -18,6 +18,7 @@ type Config struct {
|
|||||||
Height int `json:"height"`
|
Height int `json:"height"`
|
||||||
Obstacles int `json:"obstacles"`
|
Obstacles int `json:"obstacles"`
|
||||||
MaxPoints int `json:"max_points"`
|
MaxPoints int `json:"max_points"`
|
||||||
|
Mode string `json:"mode"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -27,6 +28,7 @@ const (
|
|||||||
HEIGHT = 550
|
HEIGHT = 550
|
||||||
OBSTACLES = 5
|
OBSTACLES = 5
|
||||||
MAX_POINTS = 500 // allowing for 50 pts in every category
|
MAX_POINTS = 500 // allowing for 50 pts in every category
|
||||||
|
DEFAULT_MODE = "deathmatch"
|
||||||
)
|
)
|
||||||
|
|
||||||
func loadConfig(filename string) (Config, error) {
|
func loadConfig(filename string) (Config, error) {
|
||||||
@ -37,6 +39,7 @@ func loadConfig(filename string) (Config, error) {
|
|||||||
Height: HEIGHT,
|
Height: HEIGHT,
|
||||||
Obstacles: OBSTACLES,
|
Obstacles: OBSTACLES,
|
||||||
MaxPoints: MAX_POINTS,
|
MaxPoints: MAX_POINTS,
|
||||||
|
Mode: DEFAULT_MODE,
|
||||||
}
|
}
|
||||||
u, err := user.Current()
|
u, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -24,8 +24,8 @@ func startGame(w http.ResponseWriter, req *http.Request) {
|
|||||||
requested_game_name := idg.Hash()
|
requested_game_name := idg.Hash()
|
||||||
width, height := float32(conf.Width), float32(conf.Height)
|
width, height := float32(conf.Width), float32(conf.Height)
|
||||||
obstacles := 0
|
obstacles := 0
|
||||||
tick := conf.Tick
|
|
||||||
maxPoints := conf.MaxPoints
|
maxPoints := conf.MaxPoints
|
||||||
|
mode := "deathmatch"
|
||||||
|
|
||||||
// here we determine if we are going to run with defaults or pick them off
|
// here we determine if we are going to run with defaults or pick them off
|
||||||
// a posted json blob
|
// a posted json blob
|
||||||
@ -50,14 +50,14 @@ func startGame(w http.ResponseWriter, req *http.Request) {
|
|||||||
width = float32(cfg.Width)
|
width = float32(cfg.Width)
|
||||||
height = float32(cfg.Height)
|
height = float32(cfg.Height)
|
||||||
obstacles = cfg.Obstacles
|
obstacles = cfg.Obstacles
|
||||||
tick = cfg.Tick
|
|
||||||
maxPoints = cfg.MaxPoints
|
maxPoints = cfg.MaxPoints
|
||||||
|
mode = cfg.Mode
|
||||||
}
|
}
|
||||||
|
|
||||||
g := games.get(requested_game_name)
|
g := games.get(requested_game_name)
|
||||||
if g == nil {
|
if g == nil {
|
||||||
log.Printf("Game '%s' non-existant; making it now", requested_game_name)
|
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()
|
go g.run()
|
||||||
games.add(g)
|
games.add(g)
|
||||||
} else {
|
} else {
|
||||||
|
9
game.go
9
game.go
@ -75,7 +75,7 @@ type GameMode interface {
|
|||||||
gameOver(gg *game) (bool, *GameOver)
|
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{
|
g := &game{
|
||||||
id: id,
|
id: id,
|
||||||
register: make(chan *player),
|
register: make(chan *player),
|
||||||
@ -98,7 +98,12 @@ func NewGame(id string, width, height float32, obstacles, tick, maxPoints int) *
|
|||||||
tick_duration: tick,
|
tick_duration: tick,
|
||||||
players_remaining: 2,
|
players_remaining: 2,
|
||||||
winners: WinnerMap{m: make(map[string]int)},
|
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)
|
g.mode.setup(g)
|
||||||
|
@ -167,6 +167,7 @@ func addPlayer(ws *websocket.Conn) {
|
|||||||
conf.Obstacles,
|
conf.Obstacles,
|
||||||
conf.Tick,
|
conf.Tick,
|
||||||
conf.MaxPoints,
|
conf.MaxPoints,
|
||||||
|
"",
|
||||||
)
|
)
|
||||||
go game.run()
|
go game.run()
|
||||||
games.add(game)
|
games.add(game)
|
||||||
|
Loading…
Reference in New Issue
Block a user