public virtual CardInGame PlayCard(Game game, int playerIndex, int cardToBePlayed)
        {
            if (game.IndexOfPlayerWhoPlayTheTurn != playerIndex)
            {
                throw new LogicExecutionException("Igrač nije na potezu");
            }
            PlayerInGame player = game.Players[playerIndex];

            if (!player.DoesPlayerOwnCard(cardToBePlayed, out PossibleCardPlace place) || place != PossibleCardPlace.HAND)
            {
                throw new LogicExecutionException("Data karta nije u igračevoj ruci");
            }
            if (!player.Cards.TryGetValue(PossibleCardPlace.FIELD, out LinkedList <CardInGame> field) || field.Count >= GameConfig.FIELD_SIZE)
            {
                throw new LogicExecutionException("Nema više mesta na terenu");
            }
            player.GetCard(cardToBePlayed, out CardInGame cardInGame);
            if (player.Mana < cardInGame.Cost)
            {
                throw new LogicExecutionException("Igrač nema dovoljno mane da bi igrao kartu");
            }
            player.Mana -= cardInGame.Cost;
            player.MoveCard(cardToBePlayed, PossibleCardPlace.FIELD);
            cardInGame.LastAttackingTurn = game.AccumulativeTurn;
            return(cardInGame);
        }
 private void Die(PlayerInGame owner, CardInGame card)
 {
     card.Health = card.Card.Health;
     card.Cost   = card.Card.Cost;
     card.Attack = card.Card.Attack;
     owner.MoveCard(card.InGameId, PossibleCardPlace.GRAVEYARD);
 }
Exemple #3
0
 public Game(int numberOfPlayers, int startingHealth, int deckSize)
 {
     if (numberOfPlayers < 1)
     {
         throw new ArgumentException("Number of players must be positive number");
     }
     if (deckSize < 1)
     {
         throw new ArgumentException("Deck size must be positive number");
     }
     if (startingHealth < 1)
     {
         throw new ArgumentException("Starting health must be positive number");
     }
     Players = new PlayerInGame[numberOfPlayers];
     for (int i = 0; i < numberOfPlayers; i++)
     {
         Players[i] = new PlayerInGame();
     }
     m_deckSize       = deckSize;
     m_startingHealth = startingHealth;
     m_cardInGamePool = new ObjectPool <CardInGame>(() => new CardInGame(), m_deckSize * 30);
 }
        /// <returns>Whether attacked player dies</returns>
        public bool AttackPlayer(Game game, int playerIndex, int cardThatAttacks, int playerIndexToBeAttacked,
                                 out int attackerRemainingHealth, out int targetRemainingHealth)
        {
            if (playerIndex > game.Players.Length || playerIndexToBeAttacked > game.Players.Length)
            {
                throw new LogicExecutionException("Bar jedan od igrača je nevalidan");
            }

            if (playerIndex == playerIndexToBeAttacked)
            {
                throw new LogicExecutionException("Igrač ne moze napasti samog sebe");
            }
            PlayerInGame attacker = game.Players[playerIndex];
            PlayerInGame attacked = game.Players[playerIndexToBeAttacked];

            if (!attacker.DoesPlayerOwnCard(cardThatAttacks, out PossibleCardPlace place) ||
                place != PossibleCardPlace.FIELD)
            {
                throw new LogicExecutionException("Karta nije na igračevom terenu");
            }

            attacker.GetCard(cardThatAttacks, out CardInGame card);

            if (card.LastAttackingTurn >= game.AccumulativeTurn)
            {
                throw new LogicExecutionException("Karta ne može da napada u ovom potezu");
            }

            attacked.Health -= card.Attack;

            attackerRemainingHealth = card.Health;
            targetRemainingHealth   = Math.Max(0, attacked.Health);

            card.LastAttackingTurn = game.AccumulativeTurn;

            return(attacked.Health <= 0);
        }