Ejemplo n.º 1
0
        //add a card to the table based on the play type and player Id
        public void AddCard(int playerId, Settings.CardPlayType type, Card card)
        {
            if (card == null)
            {
                return;
            }

            if (playerId >= PlayerSections.Length)
            {
                Debug.LogError("Player Id " + playerId + " is not valid, selection size is " + PlayerSections.Length);
                return;
            }

            CardPool.Add(card);

            switch (type)
            {
            case Settings.CardPlayType.BATTLE:
                card.transform.SetParent(PlayerSections[playerId].BattleHolder, false);
                card.ShowFront();
                card.transform.SetAsLastSibling();

                break;

            case Settings.CardPlayType.WAR_BATTLE:
                card.transform.SetParent(PlayerSections[playerId].WarBattleHolder, false);
                card.ShowFront();
                card.transform.SetAsLastSibling();
                break;

            default:
                Debug.LogError("Unhandled type passed in");
                break;
            }
        }
Ejemplo n.º 2
0
Archivo: Game.cs Proyecto: wallmat/War
        int War(Settings.CardPlayType type = Settings.CardPlayType.BATTLE)
        {
            //save the player numbers to read easier (hard coded for two players)
            int Player1 = 0;
            int Player2 = 1;

            //get a card if possible from each player
            var Player1Card = Players[Player1].GetCard();
            var Player2Card = Players[Player2].GetCard();

            //add any cards to the table
            if (Player1Card)
            {
                MyTable.AddCard(Player1, type, Player1Card);
            }

            if (Player2Card)
            {
                MyTable.AddCard(Player2, type, Player2Card);
            }

            //if the player didnt have a card the game is over bail out
            if (Player1Card == null || Player2Card == null)
            {
                //Debug.LogError("null card");
                return(-1);
            }

            //Debug.Log(Player1Card.CValue + " of " + Player1Card.CSuit + " vs " + Player2Card.CValue + " of " + Player2Card.CSuit);

            //return the player that wins
            if (Player1Card.CValue > Player2Card.CValue)
            {
                //Debug.Log("Player 1 wins");
                return(0);
            }
            //player 2 wins
            else if (Player2Card.CValue > Player1Card.CValue)
            {
                //Debug.Log("Player 2 wins");
                return(1);
            }
            //Tie WAR
            else
            {
                //TIME FOR WAR
                //get the num cards for war from each player
                var Player1Cards = Players[Player1].GetCards(Settings.NumCardsForWar);
                var Player2Cards = Players[Player2].GetCards(Settings.NumCardsForWar);

                //add any cards to the table
                MyTable.AddWarCards(Player1, Player1Cards);
                MyTable.AddWarCards(Player2, Player2Cards);

                //check for lose condition
                if (Player1Cards.Count != Settings.NumCardsForWar || Player2Cards.Count != Settings.NumCardsForWar)
                {
                    //Debug.LogError("not enough cards for war");
                    return(-1);
                }

                //now add the war battle cards and evaluate like normal
                return(War(Settings.CardPlayType.WAR_BATTLE));
            }
        }