Add chan notifying when all picks have been done

This commit is contained in:
Hamcha 2019-06-17 18:08:17 +02:00
parent 1bd0a11db0
commit d5deca8993
Signed by: hamcha
GPG Key ID: A40413D21021EAEE
1 changed files with 15 additions and 0 deletions

15
pod.go
View File

@ -21,6 +21,8 @@ var (
type Pod struct {
Players []*Player
Direction PodDirection
NextRound chan bool
}
// Player is a single player partecipating in a pod
@ -94,6 +96,17 @@ func (p *Pod) flipDirection() {
}
}
func (p *Pod) checkRound() {
for _, player := range p.Players {
if len(player.newpack) < 1 {
// Someone still hasn't passed a pack
return
}
}
// Everyone has new packs to draft
p.NextRound <- true
}
// OpenPack opens the next pack the player has
func (p *Player) OpenPack() error {
if len(p.Packs) < 1 {
@ -129,5 +142,7 @@ func (p *Player) Pick(pick Card) error {
p.right.newpack <- p.CurrentPack
}
p.pod.checkRound()
return nil
}