remove game from player struct

This commit is contained in:
Stephen McQuay 2013-09-04 00:07:47 -07:00
parent 64477f5e47
commit 3e805d3da7
3 changed files with 10 additions and 7 deletions

View File

@ -55,6 +55,7 @@ func (g *game) run() {
for {
select {
case <-g.kill:
log.Printf("%s: received kill signal, dying gracefully", g.id)
return
case p := <-g.register:
g.players[p] = true
@ -77,6 +78,7 @@ func (g *game) run() {
log.Printf("Explosions: %v", len(g.splosions))
}
// TODO: making one of these every iteration seems wasteful
payload := bot.NewBoardstate(g.turn)
robots_remaining := 0
@ -84,7 +86,7 @@ func (g *game) run() {
for p := range g.players {
if p.Robot.Health > 0 {
robots_remaining++
p.scan()
p.scan(g.players)
p.nudge()
// XXX: change to pointer, check for pointer as (0, 0) is valid target
if p.Robot.FireAt != nil {

View File

@ -76,7 +76,6 @@ func addPlayer(ws *websocket.Conn) {
Scanners: make([]bot.Scanner, 0)},
send: make(chan *bot.Boardstate),
ws: ws,
game: game,
}
p.reset()
log.Printf("game: %+v", game)

View File

@ -10,7 +10,6 @@ import (
type player struct {
ws *websocket.Conn
game *game
Robot bot.Robot
send chan *bot.Boardstate
Instruction instruction
@ -61,9 +60,10 @@ func (p *player) nudge() {
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)
for player := range p.game.players {
for player, _ := range players {
if player.Robot.Id == p.Robot.Id || player.Robot.Health <= 0 {
continue
}
@ -80,8 +80,10 @@ func (p *player) scan() {
}
}
func (p *player) fire() *bot.Projectile {
for proj := range p.game.projectiles {
func (p *player) fire(projectiles map[*bot.Projectile]bool) *bot.Projectile {
// XXX: is this to prevent us from having multiple projectiles from the
// same bot?
for proj := range projectiles {
if proj.Id == p.Robot.Id {
return nil
}