Ejemplo n.º 1
0
        /// <summary>
        /// Makes move on the table, and flips the active player. A Move can be created using GetMove(command).
        /// </summary>
        public void MakeMove(Move move)
        {
            _moveNo++;
            if (move == null)
            {
                throw new NullReferenceException();
            }
            currentMove = move;
            switch (move.MoveType)
            {
            case MoveTypes.Throwaway:
                GetActivePlayer().RemoveCard(move.CardPlayed);
                CardsOnTable.Add(move.CardPlayed);
                break;

            case MoveTypes.Pickup:
                GetActivePlayer().RemoveCard(move.CardPlayed);
                GetActivePlayer().AddCardsToLocalDeck(move.CardsPickedUp.Concat(new List <byte> {
                    move.CardPlayed
                }).ToList());
                CardsOnTable.RemoveAll(x => move.CardsPickedUp.Contains(x));
                break;

            case MoveTypes.Build: break;

            case MoveTypes.Capture: break;

            default: throw new Exception(Errorstr.NoMove());
            }
            FlipActivePlayer();
        }
Ejemplo n.º 2
0
    /// <summary>
    /// Places a card in the game scene
    /// </summary>
    /// <param name="xcoord">X coordinate of the card object</param>
    /// <param name="ycoord">Y coordinate of the card object</param>
    /// <param name="card">The card information to be set on the created object</param>
    /// <param name="sips">Number of sips associated with flipping the card. 0 for cards that have other functions</param>
    /// <param name="type">The type of action there is to be taken which flipping the card</param>
    private void PlaceCard(float xcoord, float ycoord, Card card, int sips, CardType type)
    {
        var cardObj    = Instantiate(Resources.Load("CardTemplate") as GameObject, new Vector3(xcoord, ycoord), Quaternion.identity) as GameObject;
        var cardObjTop = cardObj.GetComponent <CardObject>();

        cardObjTop.SetCardInfo(card, sips, type);
        CardsOnTable.Add(cardObj);
    }
Ejemplo n.º 3
0
 public void OnHitMade(ServiceCard movedCard, int gameId, int playerId)
 {
     if (_gameId == gameId)
     {
         Card c = serviseCardToCard(movedCard);
         referToView(c);
         MoveNr += 1;
         CardsOnTable.Add(c);
         setPlayerActionColor();
     }
 }
Ejemplo n.º 4
0
        public Card PopCard()
        {
            if (CardsOnTable.Count == 0)
            {
                return(null);
            }

            var card = CardsOnTable[0];

            CardsOnTable.RemoveAt(0);
            return(card);
        }
Ejemplo n.º 5
0
 public void OnNotifyMove_UI(ServiceCard movedCard, int gameId, long playerId, long nextHit)
 {
     if (_gameId == gameId)
     {
         Card c = serviseCardToCard(movedCard);
         referToView(c);
         MoveNr += 1;
         CardsOnTable.Add(c);
         HitIndex = nextHit;
         setPlayerActionColor();
     }
 }
Ejemplo n.º 6
0
 public void OnHitMade_UI(ServiceCard movedCard, int gameId, long playerId)
 {
     Trace.WriteLine("VIEW: OnHitMade called()");
     if (_gameId == gameId)
     {
         Card c = serviseCardToCard(movedCard);
         referToView(c);
         MoveNr += 1;
         CardsOnTable.Add(c);
         setPlayerActionColor();
     }
 }
Ejemplo n.º 7
0
            protected override void SetResultOfRound()
            {
                // CHECK IF A RECURSIVE GAME SHOULD HAPPEN

                // If both players have at least as many cards remaining
                // in their deck as the value of the card they just drew,
                // the winner of the round is determined by playing a new game of Recursive Combat.
                Player playerWon;

                bool playSubgame = Players.All(p => p.NrOfCards >= p.PlayedCard);

                if (playSubgame)
                {
                    if (PRINT)
                    {
                        Console.WriteLine("Playing a sub-game to determine the winner...");
                    }

                    var playersWithNewCards = Players.Select(p => new Player(p.Name, p.Cards.ToList().Take(p.PlayedCard).ToList())).ToList();
                    SubGame++;
                    var newGame = new RecursiveCombat(playersWithNewCards, SubGame);
                    var playerWonRecursiceGame = newGame.PlayGame();
                    playerWon = Players.FirstOrDefault(p => p.Name == playerWonRecursiceGame.Name);
                    var otherPlayer = Players.FirstOrDefault(p => p.Name != playerWonRecursiceGame.Name);
                    // note that the winner's card might be the lower-valued of the two cards
                    playerWon.WonCards(playerWon.PlayedCard, otherPlayer.PlayedCard);

                    if (PRINT)
                    {
                        Console.WriteLine($"...anyway, back to game {GameNr}.");
                    }
                }
                else
                {
                    // find player with the highest card!
                    playerWon = Players.OrderBy(p => p.PlayedCard).Reverse().FirstOrDefault();

                    CardsOnTable.Sort();
                    CardsOnTable.Reverse();
                    playerWon.WonCards(CardsOnTable);
                }

                if (PRINT)
                {
                    Console.WriteLine($"{playerWon.Name} wins round {Round} of game {GameNr}!");
                }

                // reset round!
                Players.ForEach(p => p.ResetRound());
                CardsOnTable = new List <int>();
            }
Ejemplo n.º 8
0
        /// <summary>
        /// выдать следуюшую карту на стол
        /// </summary>
        public void GetNextCardOnTable()
        {
            if (CardsOnTable.Count < 5)
            {
                Random r = new Random();

                int index = r.Next(0, Deck.Cards.Count);
                CardsOnTable.Add(Deck.Cards[index]);
                Deck.DropCard(index);
            }
            else
            {
                throw new Exception();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// поставит на стол 3 карты
        /// </summary>
        public void GetFlop()
        {
            Random r = new Random();

            int index = r.Next(0, Deck.Cards.Count);

            CardsOnTable.Add(Deck.Cards[index]);
            Deck.DropCard(index);

            index = r.Next(0, Deck.Cards.Count);
            CardsOnTable.Add(Deck.Cards[index]);
            Deck.DropCard(index);

            index = r.Next(0, Deck.Cards.Count);
            CardsOnTable.Add(Deck.Cards[index]);
            Deck.DropCard(index);
        }
Ejemplo n.º 10
0
        public void HandOutCards()
        {
            const int cardsToGiveOut = 5; // Everyone gets this certain amount of cards.

            // randomize the list
            CardsOnTable = CardsOnTable.OrderBy(item => random.Next()).ToList();

            foreach (var player in PlayersConnected)
            {
                Card[] cards = new Card[cardsToGiveOut];

                for (int i = 0; i < cardsToGiveOut; i++)
                {
                    cards[i] = PopCard();
                }

                player.AddCards(cards);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Распределение выгрещей
        /// </summary>
        /// <param name="users"></param>
        public void DistributionOfWinnings(List <User> users)
        {
            Bank.CalculationComission();
            int sumWinnings = Convert.ToInt32((Convert.ToDouble(Bank.Coins - Bank.Comission)) / Convert.ToDouble(users.Count));

            foreach (User user in users)
            {
                user.AddCoinsOnTable(sumWinnings);
            }
            Bank.CleardCoins();
            foreach (var playUser in PlayUsers)
            {
                playUser.Stake = 0;
                playUser.CardsInHand.Clear();
            }
            CardsOnTable.Clear();
            Rates.Clear();
            MaxStake    = 0;
            Deck        = new Deck();
            StatusPause = true;
        }