public CardRules(GameContext context) { _gctx = context; }
private void InitGame() { gCtx = new GameContext(); PlayerBoxes = new List<PlayerBox>(gCtx.players.Count); foreach (var player in gCtx.players) { var pb = new PlayerBox(player); pb.Click += PlayerSelect; pb.lbCards.SelectedIndexChanged += CardSelect; PlayerBoxes.Add(pb); } flowLayoutPanel1.Controls.AddRange(PlayerBoxes.ToArray()); gCtx.OnBeginPrepareCards += InvokeSynchronize; gCtx.OnEndPrepareCards += InvokeSynchronize; gCtx.OnBeginGetCards += delegate { InvokeAddMessage($"玩家{gCtx.currentPlayer.name}摸{gCtx.currentPlayer.CardCountToGet}张牌"); }; gCtx.OnEndGetCards += InvokeSynchronize; gCtx.OnBeginSelectOneCard += delegate { this.Invoke(new Action(() => { panelDealCard.Show(); lblSelectCard.Show(); currentLbCards.SelectionMode = SelectionMode.One; AddMessage($"轮到玩家{gCtx.currentPlayer.name}出牌"); })); }; gCtx.OnEndSelectOneCard += delegate { this.Invoke(new Action(() => { lblSelectCard.Hide(); currentLbCards.SelectionMode = SelectionMode.None; AddMessage($"玩家{gCtx.currentPlayer.name}选择了牌{string.Join(",", gCtx.cardDress.ActualCards)}"); })); }; gCtx.OnCannotSelectThisCard += delegate { InvokeAddMessage($"玩家{gCtx.currentPlayer.name}出一次酸或碱之后就不能再出了"); }; gCtx.OnBeginSetTarget += delegate { this.Invoke(new Action(() => { lblSelectTarget.Show(); AddMessage($"玩家{gCtx.currentPlayer.name}正在选择目标……"); })); }; gCtx.OnEndSetTarget += delegate { this.Invoke(new Action(() => { lblSelectTarget.Hide(); AddMessage($"玩家{gCtx.currentPlayer.name}选择了目标{gCtx.targets.First().name}"); })); }; gCtx.OnBeginDealCard += delegate { this.Invoke(new Action(() => { btnDealCard.Show(); btnDealCard.Enabled = true; })); }; gCtx.OnEndDealCard += delegate { this.Invoke(new Action(() => { AddMessage($"玩家{gCtx.currentPlayer.name}对玩家{string.Join(",", gCtx.targets.Select(t => t.name))}出牌{string.Join(",", gCtx.cardDress.ActualCards)}"); panelDealCard.Hide(); Synchronize(); })); }; gCtx.OnDealCardsFinish += delegate { this.Invoke(new Action(() => { AddMessage($"玩家{gCtx.currentPlayer.name}出牌结束"); panelDealCard.Hide(); })); }; gCtx.OnBeginDropCard += delegate { this.Invoke(new Action(() => { panelDrop.Show(); currentLbCards.SelectionMode = SelectionMode.MultiSimple; AddMessage($"玩家{gCtx.currentPlayer.name}请弃掉{gCtx.CardsCountToDrop}张牌"); })); }; gCtx.OnEndDropCard += delegate { this.Invoke(new Action(() => { AddMessage($"玩家{gCtx.currentPlayer.name}弃牌结束"); panelDrop.Hide(); currentLbCards.SelectionMode = SelectionMode.None; Synchronize(); })); }; gCtx.OnCardsDropped += delegate { this.Invoke(new Action(() => { AddMessage($"玩家{gCtx.currentPlayer.name}弃牌"); Synchronize(); })); }; gCtx.OnGameOver += delegate { this.Invoke(new Action(() => { AddMessage($"游戏结束"); panelDealCard.Hide(); Synchronize(); })); }; gCtx.Rules.OnBeginDefend += delegate { this.Invoke(new Action(() => { panelRespond.Show(); currentTargetListBox.SelectionMode = SelectionMode.One; AddMessage($"玩家{gCtx.Rules.currentTarget.name}准备出牌应对"); })); }; gCtx.Rules.OnEndDefend += InvokeSynchronize; gCtx.Rules.OnEndDefend += delegate { this.Invoke(new Action(() => { panelRespond.Hide(); })); }; gCtx.Rules.OnDefendResult += delegate { InvokeAddMessage($"玩家{gCtx.Rules.currentTarget.name}回应了牌{gCtx.Rules.defenderCard}"); }; gCtx.Rules.OnTolerateResult += delegate { InvokeAddMessage($"玩家{gCtx.Rules.currentTarget.name}没有应对"); }; gCtx.Rules.OnDropBlood += delegate { InvokeAddMessage($"玩家{gCtx.Rules.currentTarget.name}掉血了"); }; gCtx.Rules.OnWrongCard += delegate { this.Invoke(new Action(() => { MessageBox.Show("当前不能出这张牌"); })); }; }