cleanly close spectator if server dies

This commit is contained in:
Stephen McQuay 2014-05-13 00:23:14 -07:00
parent f06ccd2588
commit f6439cf41d
2 changed files with 6 additions and 2 deletions

View File

@ -47,7 +47,7 @@ func main() {
go func() {
if err := c.Play(); err != nil {
log.Fatal(err)
close(spectator.Die)
}
}()

View File

@ -22,6 +22,7 @@ type SimpleSpectator struct {
width, height float64
viewX, viewY int
update chan *server.Boardstate
Die chan struct{}
}
// NewSimpleSpectator simply returns a populated, usable *SimplePlayer
@ -30,6 +31,7 @@ func NewSimpleSpectator(width, height float64) *SimpleSpectator {
width: width,
height: height,
update: make(chan *server.Boardstate),
Die: make(chan struct{}),
}
}
@ -119,7 +121,7 @@ func (s *SimpleSpectator) Run() {
}
}
c := termbox.ColorWhite
if bot.Health < 0 {
if bot.Health <= 0 {
c = termbox.ColorBlack
}
termbox.SetCell(
@ -169,6 +171,8 @@ func (s *SimpleSpectator) Run() {
if err != nil {
log.Fatal(err)
}
case <-s.Die:
return
}
}
}()