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); }
/// <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); }