Example #1
0
        public void PlayerShowCards(CurrentTrickState currentTrickState)
        {
            string lastestPlayer = currentTrickState.LatestPlayerShowedCard();

            if (PlayersProxy[lastestPlayer] != null)
            {
                this.CurrentTrickState.ShowedCards[lastestPlayer] = currentTrickState.ShowedCards[lastestPlayer];
                string cardsString = "";
                foreach (var card in this.CurrentTrickState.ShowedCards[lastestPlayer])
                {
                    cardsString += card.ToString() + " ";
                }
                log.Debug("Player " + lastestPlayer + " showed cards: " + cardsString);
                //更新每个用户手中的牌在SERVER
                foreach (int card in this.CurrentTrickState.ShowedCards[lastestPlayer])
                {
                    this.CurrentHandState.PlayerHoldingCards[lastestPlayer].RemoveCard(card);
                }
                //回合结束
                if (this.CurrentTrickState.AllPlayedShowedCards())
                {
                    this.CurrentTrickState.Winner = TractorRules.GetWinner(this.CurrentTrickState);
                    if (!string.IsNullOrEmpty(this.CurrentTrickState.Winner))
                    {
                        if (
                            !this.CurrentGameState.ArePlayersInSameTeam(CurrentHandState.Starter,
                                                                        this.CurrentTrickState.Winner))
                        {
                            CurrentHandState.Score += currentTrickState.Points;
                            UpdatePlayersCurrentHandState();
                        }


                        log.Debug("Winner: " + this.CurrentTrickState.Winner);
                    }

                    UpdatePlayerCurrentTrickState();

                    CurrentHandState.LeftCardsCount -= currentTrickState.ShowedCards[lastestPlayer].Count;

                    //开始新的回合
                    if (this.CurrentHandState.LeftCardsCount > 0)
                    {
                        BeginNewTrick(this.CurrentTrickState.Winner);
                    }
                    else //所有牌都出完了
                    {
                        //扣底
                        CalculatePointsFromDiscarded8Cards();
                        Thread.Sleep(2000);
                        this.CurrentHandState.CurrentHandStep = HandStep.Ending;
                        UpdatePlayersCurrentHandState();

                        Thread.Sleep(5000);
                        var starter = this.CurrentGameState.NextRank(this.CurrentHandState, this.CurrentTrickState);

                        Thread.Sleep(5000);
                        StartNextHand(starter);
                    }
                }
                else
                {
                    UpdatePlayerCurrentTrickState();
                }
            }
        }
        public void LatestPlayerShowedCardTest()
        {
            CurrentTrickState trickState = new CurrentTrickState();

            trickState.Trump             = Suit.Club;
            trickState.Rank              = 0;
            trickState.Learder           = "p1";
            trickState.ShowedCards["p1"] = new List <int> {
            };
            trickState.ShowedCards["p2"] = new List <int> {
            };
            trickState.ShowedCards["p3"] = new List <int> {
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };

            Assert.AreEqual("", trickState.LatestPlayerShowedCard());

            trickState.ShowedCards["p1"] = new List <int> {
                1
            };
            trickState.ShowedCards["p2"] = new List <int> {
            };
            trickState.ShowedCards["p3"] = new List <int> {
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p1", trickState.LatestPlayerShowedCard());



            trickState.ShowedCards["p1"] = new List <int> {
                1
            };
            trickState.ShowedCards["p2"] = new List <int> {
                2
            };
            trickState.ShowedCards["p3"] = new List <int> {
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p2", trickState.LatestPlayerShowedCard());


            trickState.ShowedCards["p1"] = new List <int> {
                1
            };
            trickState.ShowedCards["p2"] = new List <int> {
                2
            };
            trickState.ShowedCards["p3"] = new List <int> {
                3
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p3", trickState.LatestPlayerShowedCard());

            trickState.ShowedCards["p1"] = new List <int> {
                1
            };
            trickState.ShowedCards["p2"] = new List <int> {
                2
            };
            trickState.ShowedCards["p3"] = new List <int> {
                3
            };
            trickState.ShowedCards["p4"] = new List <int> {
                4
            };
            Assert.AreEqual("p4", trickState.LatestPlayerShowedCard());

            trickState.Learder           = "p2";
            trickState.ShowedCards["p1"] = new List <int> {
            };
            trickState.ShowedCards["p2"] = new List <int> {
                1
            };
            trickState.ShowedCards["p3"] = new List <int> {
            };
            trickState.ShowedCards["p4"] = new List <int> {
            };
            Assert.AreEqual("p2", trickState.LatestPlayerShowedCard());
        }