diff --git a/botspectate/main.go b/botspectate/main.go index be01f5e..6ad1212 100644 --- a/botspectate/main.go +++ b/botspectate/main.go @@ -47,7 +47,7 @@ func main() { go func() { if err := c.Play(); err != nil { - log.Fatal(err) + close(spectator.Die) } }() diff --git a/spectator.go b/spectator.go index 71465e0..5c4d4c8 100644 --- a/spectator.go +++ b/spectator.go @@ -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 } } }()