Esempio n. 1
0
        /// <summary>
        /// 王罚分
        /// </summary>
        /// <param name="self"></param>
        private static void JokerScore(this GameController self)
        {
            var room = self.GetParent <Room>();

            foreach (Player player in room.Players)
            {
                var cards = player.GetComponent <HandCardsComponent>().Cards;
                if (cards.Count == 0)
                {
                    continue;
                }

                List <AnalyseResult> analyseResults = AnalyseResult.Analyse(cards);

                // 一旦存在炸弹,就不需要罚王了。
                if (analyseResults.Any(f => f.Count >= 4 && !CardsHelper.IsJoker(f.Weight)))
                {
                    continue;
                }

                int jokerCount = analyseResults.GetJokerCount();

                // joker数量为4不需要罚王,算做9炸分.
                if (jokerCount == 4)
                {
                    continue;
                }

                // 罚分
                self.SetScore(player, -(jokerCount * 3));
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 显示手牌
 /// </summary>
 public void Reflush()
 {
     // 展开
     CardsHelper.ComputerCardPos(this.View.transform.childCount, 25, (i, x, y) =>
     {
         var rect = this.View.transform.GetChild(i).GetComponent <RectTransform>();
         rect.SetSiblingIndex(i);
         rect.anchoredPosition = new Vector2(x, y);
     });
 }
Esempio n. 3
0
        /// <summary>
        /// 游戏开始
        /// </summary>
        /// <param name="self"></param>
        public static void GameStart(this GameController self)
        {
            Room room     = self.GetParent <Room>();
            var  gameInfo = room.GetComponent <GameInfo>();

            // 局数+1
            ++gameInfo.Count;

            // 重置
            for (int i = 0; i < room.Players.Length; i++)
            {
                var item = room.Players[i];
                item.GetComponent <HandCardsComponent>().Cards.Clear();
                item.LastPlayCards = null;
                item.Action        = PlayerAction.None;
                item.IsReady       = false;
            }

            // 先锁定房间
            room.Lock();

            // 初始化两幅牌
            gameInfo.Cards.Clear();
            CardsHelper.Spawn(gameInfo.Cards);
            CardsHelper.Spawn(gameInfo.Cards);

            // 洗牌
            CardsHelper.Shuffle1(gameInfo.Cards, 3);

            // 发牌
            self.Deal();

            // 初始化队伍以及确定先手玩家
            self.InitFristPlayer();
            self.InitTeam();

            // 同步队伍、手牌
            self.SyncTeam();
            self.SyncHandCard();
            self.SyncGameStart();

            // 摊牌了,不用开始游戏直接结束这局。
            if (self.CheckTanCard())
            {
                self.OnRoundEnd(true);
            }
            else
            {
                self.Continue(false);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 获取Joker的数量
        /// </summary>
        /// <param name="analyseResults"></param>
        /// <returns></returns>
        public static int GetJokerCount(this List <AnalyseResult> analyseResults)
        {
            int jokerCount = analyseResults.Sum(f =>
            {
                if (CardsHelper.IsJoker(f.Weight))
                {
                    return(f.Count);
                }

                return(0);
            });

            return(jokerCount);
        }
Esempio n. 5
0
        /// <summary>
        /// 出牌
        /// </summary>
        /// <param name="self"></param>
        /// <param name="player"></param>
        /// <param name="cards"></param>
        public static bool Pop(this GameController self, Player player, List <Card> cards)
        {
            // 不该此玩家操作
            if (self.CurrentSeat != player.SeatIndex)
            {
                return(false);
            }

            // 没有牌
            if (cards == null || cards.Count == 0)
            {
                return(false);
            }

            // 验证出牌是否符合
            if (!cards.TryGetCardType(out CardType type))
            {
                // 出牌失败,牌型不对.
                return(false);
            }

            // 特殊排序
            if (type == CardType.ThreeAndTwo || type == CardType.TripleStraight)
            {
                // 权重排序
                CardsHelper.WeightSort(cards);
            }

            // 接牌,自己上次出牌没人接牌以及,自己能接上次别人出的牌,就轮转。
            // self.LastPopCardSeat == self.CurrentPopSeat 是自己的牌最大,都没有人要。
            // 一般来说都得同牌型,但炸弹能接所有牌型。
            if (self.DeskSeat != self.CurrentSeat && !PopCardHelper.Pop(new PopCheckInfo
            {
                DesktopCards = self.DeskCards,
                DesktopCardType = self.DeskCardType,
                HandCards = player.GetComponent <HandCardsComponent>().Cards.Count,
                PopCards = cards,
                PopCardType = type
            }))
            {
                return(false);
            }

            // 接牌成功
            self.DeskCards    = cards;
            self.DeskCardType = type;
            self.DeskSeat     = player.SeatIndex;
            self.LastOpSeat   = player.SeatIndex;

            // 从玩家手牌中移除牌
            var handCards = player.GetComponent <HandCardsComponent>();

            handCards.Remove(cards);

            // 记录Player最后一次的操作,断线重连后需要恢复每个玩家的最近的操作。
            player.Action        = PlayerAction.Play;
            player.LastPlayCards = cards.ToList();

            // 下一个人出牌
            self.Continue();

            // 玩家出完牌
            if (handCards.Cards.Count == 0)
            {
                self.Win.Enqueue(player.SeatIndex);
                if (self.Win.Count == 2) // 一局结束
                {
                    Room room     = self.GetParent <Room>();
                    var  gameInfo = room.GetComponent <GameInfo>();

                    // 判定是否双扣
                    int a = self.Win.Dequeue();
                    gameInfo.IsDoubleEnd = room.Players[a].GetComponent <TeamComponent>().Team == player.GetComponent <TeamComponent>().Team;
                    OnRoundEnd(self);
                }
            }

            return(true);
        }
Esempio n. 6
0
 /// <summary>
 /// 筛选炸弹
 /// </summary>
 /// <param name="analyseResults"></param>
 /// <returns></returns>
 public static List <AnalyseResult> GetBooms(this List <AnalyseResult> analyseResults)
 {
     return(analyseResults.Where(f => f.Count > 3 && !CardsHelper.IsJoker(f.Weight)).ToList());
 }