cleanly close spectator if server dies
This commit is contained in:
parent
f06ccd2588
commit
f6439cf41d
@ -47,7 +47,7 @@ func main() {
|
||||
|
||||
go func() {
|
||||
if err := c.Play(); err != nil {
|
||||
log.Fatal(err)
|
||||
close(spectator.Die)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
Loading…
Reference in New Issue
Block a user