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

17
pod.go
View file

@ -36,6 +36,9 @@ type Player struct {
// Pod the player is in // Pod the player is in
pod *Pod 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 // 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 // Fill players
for i := range players { for i := range players {
players[i] = &Player{ players[i] = &Player{
Packs: provider(), Packs: provider(),
Picks: []Card{}, Picks: []Card{},
pod: pod, pod: pod,
newpack: make(chan Pack, playerCount-1),
} }
} }
// Second loop to fill nearby players // 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[id] = p.CurrentPack[len(p.CurrentPack)-1]
p.CurrentPack = 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 return nil
} }