Ejemplo n.º 1
0
 public CampaignProgression(FactionArmies attackers, FactionArmies defenders, IEnumerable <BattleSite> sites)
 {
     Attackers      = attackers;
     Defenders      = defenders;
     RemainingSites = sites;
     CurrentSite    = sites.First();
     PreBattle      = new BattlePreparation(Attackers, Defenders, CurrentSite);
     Battle         = GetBattle();
     Outcome        = Battle.Outcome;
 }
Ejemplo n.º 2
0
    public Battle(BattleState startingState)
    {
        List <BattleState> states       = new List <BattleState>();
        BattleState        currentState = startingState;

        while (currentState.Outcome == WarOutcome.Ongoing && states.Count < BattleTurnLimit)
        {
            states.Add(currentState);
            currentState = currentState.GetNextState();
        }
        States  = states.AsReadOnly();
        Outcome = states.Count < BattleTurnLimit ? currentState.Outcome : WarOutcome.Draw;
    }
Ejemplo n.º 3
0
        //Main action-method of the program
        //Both player and computer request a card
        //If they can both draw, they compare their cards
        //If either cannot draw, the other wins, and returns to Program.cs
        //If both cannot draw, the game is a draw, and returns to Program.cs
        //If turboMode is set to True, run TakeTurn without waiting for user input (as fast as possible)
        public bool TakeTurn(bool turboMode)
        {
            WarOutcome outcome = WarOutcome.NONE;

            do
            {
                //if the player and computer are currently in war, wait for enter to be pressed for each round of the war
                if (outcome == WarOutcome.WAR)
                {
                    Console.WriteLine("WAR! You're at war with the computer, whoever draws higher takes home all the cards in the war.");
                    if (!turboMode)
                    {
                        char controlChar = '0';
                        try
                        {
                            controlChar = Console.ReadLine().ToLower()[0];
                        }
                        catch (Exception ex)
                        {
                            controlChar = '0';
                        }
                        while (controlChar != ' ')
                        {
                            Console.WriteLine("Press space to draw, and 's' to check stats. Press 'x' to exit the game");
                            controlChar = Console.ReadLine().ToLower()[0];
                            if (controlChar == 's')
                            {
                                PrintPlayerStats();
                            }
                            else if (controlChar == 'x')
                            {
                                Console.WriteLine("----------------------------");
                                Console.WriteLine("Player forfeits the game.");
                                Console.WriteLine("----------------------------");
                                return(false);
                            }
                            else if (controlChar != ' ')
                            {
                                Console.WriteLine("I couldn't understand that command.");
                            }
                        }
                    }
                }
                CardModel playerCard   = null;
                CardModel computerCard = null;

                //Request a card from Player and Computer decks
                bool canPlayerDraw   = PlayerDeck.TryDrawCard(out playerCard, PlayerClaims);
                bool canComputerDraw = ComputerDeck.TryDrawCard(out computerCard, ComputerClaims);

                if (canPlayerDraw && !canComputerDraw)
                {
                    //player has cards, but computer does not, player wins!
                    Console.WriteLine("----------------------------");
                    Console.WriteLine("Player wins the game!");
                    Console.WriteLine("----------------------------");
                    return(false);
                }
                else if (!canPlayerDraw && canComputerDraw)
                {
                    //player does't have cards, but computer does, so the computer wins
                    Console.WriteLine("----------------------------");
                    Console.WriteLine("Computer wins the game!");
                    Console.WriteLine("----------------------------");
                    return(false);
                }
                else if (!canPlayerDraw && !canComputerDraw)
                {
                    //nobody has cards, so it's a draw.
                    Console.WriteLine("----------------------------");
                    Console.WriteLine("Nobody wins; it's a draw.");
                    Console.WriteLine("----------------------------");
                    return(false);
                }

                Console.WriteLine("Computer Card: " + computerCard.CardId + " || Your Card: " + playerCard.CardId);

                outcome = CompareController.Instance.CompareCards(playerCard, computerCard);
            } while (outcome == WarOutcome.WAR);

            //Check the outcome of the round, and award the cards in the round history to the player or computer
            switch (outcome)
            {
            case WarOutcome.WIN:
            {
                Console.WriteLine("Player takes the cards home.");
                //get the winnings
                var claims = CompareController.Instance.HistoryToDeck();
                //clear history on card comparer
                CompareController.Instance.ClearHistory();
                //award the winnings to the player
                PlayerClaims.AddCards(claims);

                break;
            }

            case WarOutcome.LOSE:
            {
                Console.WriteLine("Computer takes the cards home.");
                //get the winnings
                var claims = CompareController.Instance.HistoryToDeck();
                //clear history on card comparer
                CompareController.Instance.ClearHistory();
                //award the winnings to the computer
                ComputerClaims.AddCards(claims);

                break;
            }
            }

            //no win condition has been reached, return true to continue playing the game
            return(true);
        }
Ejemplo n.º 4
0
 public BattleState(IEnumerable <BattleStateForces> attackers, IEnumerable <BattleStateForces> defenders)
 {
     Attackers = attackers;
     Defenders = defenders;
     Outcome   = GetOutcome();
 }