From 1bd0a11db045670785419350e521bef1b0dcefb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=AEittaG=20ordnasselA?= Date: Thu, 13 Jun 2019 18:11:57 +0200 Subject: [PATCH] Add channel, even though I need to figure out how to make them work --- pod.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pod.go b/pod.go index 322fb8c..f955d9a 100644 --- a/pod.go +++ b/pod.go @@ -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 }