private async Task PayCasualty() { if (Deck.Count > 0) { Deck[0].FaceUP = true; Casualties.Add(Deck[0]); Log += $"You lost {Deck[0].GetValueStringLog()} as a casualty\n"; Deck.RemoveAt(0); OnPropertyChanged("CasualtyCard"); } await Task.Delay(2000); if (OpponentDeck.Count > 0) { OpponentDeck[0].FaceUP = true; Casualties.Add(OpponentDeck[0]); Log += $"Opponent lost {OpponentDeck[0].GetValueStringLog()} as a casualty\n"; OpponentDeck.RemoveAt(0); OnPropertyChanged("CasualtyCard"); } OnPropertyChanged("DeckCount"); OnPropertyChanged("OpponentDeckCount"); }
private void SetBattleField() { //start laying out normal for player if (Deck.Count >= 6) { for (int i = 0; i < 6; i++) { BattlefieldLayout[i] = Deck[0]; Deck.RemoveAt(0); } OnPropertyChanged("BattlefieldLayout"); } else { //near end of game for (int i = 0; i < 3; i++) { if (Deck.Count > 0) { BattlefieldLayout[i + 3] = Deck[0]; Deck.RemoveAt(0); } else { BattlefieldLayout[i + 3] = null; } if (Deck.Count > 0) { BattlefieldLayout[i] = Deck[0]; Deck.RemoveAt(0); } else { BattlefieldLayout[i] = null; } } OnPropertyChanged("BattlefieldLayout"); } //Layout battlefield of oppenent if (OpponentDeck.Count >= 6) { for (int i = 0; i < 6; i++) { OpponentBattlefield[i] = OpponentDeck[0]; OpponentDeck.RemoveAt(0); } OnPropertyChanged("OpponentBattlefield"); } else { //near end of game for (int i = 0; i < 3; i++) { if (OpponentDeck.Count > 0) { OpponentBattlefield[i + 3] = OpponentDeck[0]; OpponentDeck.RemoveAt(0); } else { OpponentBattlefield[i + 3] = null; } if (OpponentDeck.Count > 0) { OpponentBattlefield[i] = OpponentDeck[0]; OpponentDeck.RemoveAt(0); } else { OpponentBattlefield[i] = null; } } OnPropertyChanged("OpponentBattlefield"); } Log += "Battlefields have been laid down.\n"; OnPropertyChanged("DeckCount"); OnPropertyChanged("OpponentDeckCount"); }
private void TakeSpoils(bool playerWon, int column, bool playerAttack, bool opponentAttack, List <Card> BattleCards, List <Card> OpponentBattleCards, int aceCount) { if (playerWon) { foreach (Card c in BattleCards) { c.FaceUP = false; Deck.Add(c); } foreach (Card c in OpponentBattleCards) { c.FaceUP = false; Deck.Add(c); } BattleCards.Clear(); OpponentBattleCards.Clear(); if (Pot.Count > 0) { foreach (Card c in Pot) { c.FaceUP = false; Deck.Add(c); } if (BattlefieldLayout.Contains(Pot[0])) { BattlefieldLayout[PotColumn] = null; BattlefieldLayout[PotColumn + 3] = null; OpponentBattlefield[PotColumn] = null; OpponentBattlefield[PotColumn + 3] = null; } Pot.Clear(); } BattlefieldLayout[column] = null; BattlefieldLayout[column + 3] = null; OpponentBattlefield[column] = null; OpponentBattlefield[column + 3] = null; Reinforcement = null; OpponentReinforcement = null; OnPropertyChanged("BattleFieldLayout"); OnPropertyChanged("OpponentBattlefield"); int spoils = 0; spoils += (playerAttack ? 1 : 0) + (opponentAttack ? 1 : 0); if (aceCount > 0) { Log += $"Additional {aceCount} spoils for Aces\n"; spoils += aceCount; } if (playerAttack) { for (int i = 0; i < spoils; i++) { if (OpponentDeck.Count > 0) { Deck.Add(OpponentDeck[0]); Log += $"Oppenent lost {OpponentDeck[0].GetValueStringLog()} as a spoil\n"; OpponentDeck.RemoveAt(0); } } } } else { foreach (Card c in BattleCards) { c.FaceUP = false; OpponentDeck.Add(c); } foreach (Card c in OpponentBattleCards) { c.FaceUP = false; OpponentDeck.Add(c); } BattleCards.Clear(); OpponentBattleCards.Clear(); if (Pot.Count > 0) { foreach (Card c in Pot) { c.FaceUP = false; OpponentDeck.Add(c); } if (BattlefieldLayout.Contains(Pot[0])) { BattlefieldLayout[PotColumn] = null; BattlefieldLayout[PotColumn + 3] = null; OpponentBattlefield[PotColumn] = null; OpponentBattlefield[PotColumn + 3] = null; } Pot.Clear(); } BattlefieldLayout[column] = null; BattlefieldLayout[column + 3] = null; OpponentBattlefield[column] = null; OpponentBattlefield[column + 3] = null; Reinforcement = null; OpponentReinforcement = null; //OnPropertyChanged("Reinforcement"); //OnPropertyChanged("OpponentReinforcement"); OnPropertyChanged("BattlefieldLayout"); OnPropertyChanged("OpponentBattlefield"); int spoils = 0; spoils += (playerAttack ? 1 : 0) + (opponentAttack ? 1 : 0); if (aceCount > 0) { Log += $"Additional {aceCount} spoils for Aces\n"; spoils += aceCount; } if (opponentAttack) { for (int i = 0; i < spoils; i++) { if (Deck.Count > 0) { OpponentDeck.Add(Deck[0]); Log += $"You lost {Deck[0].GetValueStringLog()} as a spoil\n"; Deck.RemoveAt(0); } } } } OnPropertyChanged("DeckCount"); OnPropertyChanged("OpponentDeckCount"); }
private async Task DoBattle(bool playerAttack, bool opponentAttack, int column) { List <Card> BattleCards = new List <Card>(); List <Card> OpponentBattleCards = new List <Card>(); int aceCount = 0; string order = playerAttack ? "attack" : "defend"; Log += $"You order to {order}\n"; order = opponentAttack ? "attack" : "defend"; Log += $"Opponent orders to {order}\n"; if (!playerAttack && !opponentAttack) { //no battle, cards go into pot Log += "Both defend so current cards go into spoils\n"; //Pot.Clear(); await FlipCards(column); Pot.Add(BattlefieldLayout[column]); Pot.Add(BattlefieldLayout[column + 3]); Pot.Add(OpponentBattlefield[column]); Pot.Add(OpponentBattlefield[column + 3]); PotColumn = column; } else { await FlipCards(column); int PlayerTotal = 0; int OpponentTotal = 0; //manage reinforcements and jokers with the battlecards if (BattlefieldLayout[column] != null) { BattleCards.Add(BattlefieldLayout[column]); } if (BattlefieldLayout[column + 3] != null) { BattleCards.Add(BattlefieldLayout[column + 3]); } if (OpponentBattlefield[column] != null) { OpponentBattleCards.Add(OpponentBattlefield[column]); } if (OpponentBattlefield[column + 3] != null) { OpponentBattleCards.Add(OpponentBattlefield[column + 3]); } EvaluateJoker(BattleCards, OpponentBattleCards, out PlayerTotal, out OpponentTotal, out aceCount); Log += $"{PlayerTotal} vs {OpponentTotal}\n"; if (PlayerTotal > OpponentTotal) { //player win Log += "You won the Battle!\n"; TakeSpoils(true, column, playerAttack, opponentAttack, BattleCards, OpponentBattleCards, aceCount); } else if (OpponentTotal > PlayerTotal) { //Opponent win Log += "Opponent won the Battle!\n"; TakeSpoils(false, column, playerAttack, opponentAttack, BattleCards, OpponentBattleCards, aceCount); } else { //Ties will result in reinforcement while (PlayerTotal == OpponentTotal) { Log += "Tie\n"; if (Deck.Count > 0) { Reinforcement = Deck[0]; Deck.RemoveAt(0); Reinforcement.FaceUP = true; BattleCards.Add(Reinforcement); PlayerTotal += Reinforcement.GetValue(); Log += $"You reinforced with {Reinforcement.GetValueStringLog()}\n"; await Task.Delay(1000); } if (OpponentDeck.Count > 0) { OpponentReinforcement = OpponentDeck[0]; OpponentDeck.RemoveAt(0); OpponentReinforcement.FaceUP = true; OpponentBattleCards.Add(OpponentReinforcement); OpponentTotal += OpponentReinforcement.GetValue(); Log += $"Opponent reinforced with {OpponentReinforcement.GetValueStringLog()}\n"; await Task.Delay(1000); } EvaluateJoker(BattleCards, OpponentBattleCards, out PlayerTotal, out OpponentTotal, out aceCount); } if (PlayerTotal > OpponentTotal) { Log += "You won with the reinforcement!\n"; TakeSpoils(true, column, playerAttack, opponentAttack, BattleCards, OpponentBattleCards, aceCount); } else { Log += "Opponent won with the reinforcement!\n"; TakeSpoils(false, column, playerAttack, opponentAttack, BattleCards, OpponentBattleCards, aceCount); } OpponentReinforcement = null; Reinforcement = null; } } }