Add channel, even though I need to figure out how to make them work

This commit is contained in:
Hamcha 2019-06-13 18:11:57 +02:00
parent 3eac6aaa61
commit 1bd0a11db0
Signed by: hamcha
GPG Key ID: A40413D21021EAEE
1 changed files with 14 additions and 3 deletions

17
pod.go
View File

@ -36,6 +36,9 @@ type Player struct {
// Pod the player is in
pod *Pod
// Channels for passing stuff around
newpack chan Pack
}
// MakePod creates a pod with a specified number of players and a given set of packs
@ -52,9 +55,10 @@ func MakePod(playerCount int, provider PackProvider) *Pod {
// Fill players
for i := range players {
players[i] = &Player{
Packs: provider(),
Picks: []Card{},
pod: pod,
Packs: provider(),
Picks: []Card{},
pod: pod,
newpack: make(chan Pack, playerCount-1),
}
}
// Second loop to fill nearby players
@ -118,5 +122,12 @@ func (p *Player) Pick(pick Card) error {
p.CurrentPack[id] = p.CurrentPack[len(p.CurrentPack)-1]
p.CurrentPack = p.CurrentPack[:len(p.CurrentPack)-1]
// Send pack to next player
if p.pod.Direction == PRClockwise {
p.left.newpack <- p.CurrentPack
} else {
p.right.newpack <- p.CurrentPack
}
return nil
}