remove game from player struct
This commit is contained in:
parent
64477f5e47
commit
3e805d3da7
4
game.go
4
game.go
@ -55,6 +55,7 @@ func (g *game) run() {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-g.kill:
|
case <-g.kill:
|
||||||
|
log.Printf("%s: received kill signal, dying gracefully", g.id)
|
||||||
return
|
return
|
||||||
case p := <-g.register:
|
case p := <-g.register:
|
||||||
g.players[p] = true
|
g.players[p] = true
|
||||||
@ -77,6 +78,7 @@ func (g *game) run() {
|
|||||||
log.Printf("Explosions: %v", len(g.splosions))
|
log.Printf("Explosions: %v", len(g.splosions))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: making one of these every iteration seems wasteful
|
||||||
payload := bot.NewBoardstate(g.turn)
|
payload := bot.NewBoardstate(g.turn)
|
||||||
|
|
||||||
robots_remaining := 0
|
robots_remaining := 0
|
||||||
@ -84,7 +86,7 @@ func (g *game) run() {
|
|||||||
for p := range g.players {
|
for p := range g.players {
|
||||||
if p.Robot.Health > 0 {
|
if p.Robot.Health > 0 {
|
||||||
robots_remaining++
|
robots_remaining++
|
||||||
p.scan()
|
p.scan(g.players)
|
||||||
p.nudge()
|
p.nudge()
|
||||||
// XXX: change to pointer, check for pointer as (0, 0) is valid target
|
// XXX: change to pointer, check for pointer as (0, 0) is valid target
|
||||||
if p.Robot.FireAt != nil {
|
if p.Robot.FireAt != nil {
|
||||||
|
1
http.go
1
http.go
@ -76,7 +76,6 @@ func addPlayer(ws *websocket.Conn) {
|
|||||||
Scanners: make([]bot.Scanner, 0)},
|
Scanners: make([]bot.Scanner, 0)},
|
||||||
send: make(chan *bot.Boardstate),
|
send: make(chan *bot.Boardstate),
|
||||||
ws: ws,
|
ws: ws,
|
||||||
game: game,
|
|
||||||
}
|
}
|
||||||
p.reset()
|
p.reset()
|
||||||
log.Printf("game: %+v", game)
|
log.Printf("game: %+v", game)
|
||||||
|
12
player.go
12
player.go
@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
type player struct {
|
type player struct {
|
||||||
ws *websocket.Conn
|
ws *websocket.Conn
|
||||||
game *game
|
|
||||||
Robot bot.Robot
|
Robot bot.Robot
|
||||||
send chan *bot.Boardstate
|
send chan *bot.Boardstate
|
||||||
Instruction instruction
|
Instruction instruction
|
||||||
@ -61,9 +60,10 @@ func (p *player) nudge() {
|
|||||||
p.Robot.Position.Y = newPos.Y
|
p.Robot.Position.Y = newPos.Y
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) scan() {
|
func (p *player) scan(players map[*player]bool) {
|
||||||
|
// TODO: perhaps keep the same one around?
|
||||||
p.Robot.Scanners = make([]bot.Scanner, 0)
|
p.Robot.Scanners = make([]bot.Scanner, 0)
|
||||||
for player := range p.game.players {
|
for player, _ := range players {
|
||||||
if player.Robot.Id == p.Robot.Id || player.Robot.Health <= 0 {
|
if player.Robot.Id == p.Robot.Id || player.Robot.Health <= 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -80,8 +80,10 @@ func (p *player) scan() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) fire() *bot.Projectile {
|
func (p *player) fire(projectiles map[*bot.Projectile]bool) *bot.Projectile {
|
||||||
for proj := range p.game.projectiles {
|
// XXX: is this to prevent us from having multiple projectiles from the
|
||||||
|
// same bot?
|
||||||
|
for proj := range projectiles {
|
||||||
if proj.Id == p.Robot.Id {
|
if proj.Id == p.Robot.Id {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user