示例#1
0
        private static Territory ChooseAttacker()
        {
            var territory = new Territory();
            var confirmed = false;

            while (confirmed == false)
            {
                var player = GameBoard.GetBoard().CurrentPlayer;
                Console.Clear();
                Colour.SouthAmericaRed("\t     **** Risk! ****\n");
                Console.WriteLine("\t====================================");
                Console.Write("\tCurrently ");
                Colour.PrintPlayer(player.Colour, player.Name + "'s");
                Console.Write(" turn.");
                Console.Write("\n\tPlease select the territory you want to  ");
                Colour.SouthAmericaRed("attack with.\n");

                MapBuilder.ShowEntireWorld();
                Console.WriteLine("\n\tEnter 43 to return to menu.");
                var option = GameEngine.UserInputTest("\t(1-43)>", "\tInvalid input, please try again!", 1, 43);

                if (option != 43)
                {
                    territory = BoardPopulator.FindTerritory(option);
                    if (territory.Occupant != player.Name)
                    {
                        Console.WriteLine("\tTerritory is occupied by another player.");
                        Console.WriteLine("\tPress any key to retry....");
                        Console.ReadKey();
                    }
                    else if (territory.Armies < 2)
                    {
                        Console.WriteLine("\tTerritory must have at least 2 armies to attack with.");
                        Console.WriteLine("\tPress any key to retry....");
                        Console.ReadKey();
                    }
                    else
                    {
                        confirmed = true;
                    }
                }
                else
                {
                    confirmed = true;
                }
            }
            return(territory);
        }
示例#2
0
        private static Territory ChooseDefender(Territory attacker)
        {
            var territory = new Territory();
            var confirmed = false;

            while (confirmed == false)
            {
                Console.Clear();
                var player = GameBoard.GetBoard().CurrentPlayer;
                Colour.SouthAmericaRed("\t     **** Risk! ****\n");
                Console.WriteLine("\t====================================");
                Console.Write("\tCurrently ");
                Colour.PrintPlayer(player.Colour, player.Name + "'s");
                Console.Write(" turn.");
                Console.Write("\n\tPlease select the territory you want to  ");
                Colour.SouthAmericaRed("Attack.\n");

                var numberMap = MapBuilder.ShowTerritoriesNeighbours(attacker);
                var highest   = numberMap.Count + 1;
                Console.WriteLine("\tTo return to the main menu, enter " + highest);

                var prompt = "\n\t(1-" + highest + ")>";
                var option = GameEngine.UserInputTest(prompt, "\tInvalid input, please try again!", 1, highest);

                if (option == highest)
                {
                    confirmed = true;
                }
                else
                {
                    int result;
                    numberMap.TryGetValue(option, out result);
                    territory = BoardPopulator.FindTerritory(result);
                    if (territory != null && territory.Occupant != player.Name)
                    {
                        confirmed = true;
                    }
                    else
                    {
                        Console.WriteLine("\tCannot attack a territory which you occupy!");
                        Console.WriteLine("\tPress any key to continue....");
                        Console.ReadKey();
                    }
                }
            }
            return(territory);
        }
示例#3
0
        private static Territory PickSupplerTerritory()
        {
            var territory = new Territory();
            var confirmed = false;

            while (confirmed == false)
            {
                var player = GameBoard.GetBoard().CurrentPlayer;
                Console.Clear();
                Colour.SouthAmericaRed("\t     **** Risk! ****\n");
                Console.WriteLine("\t====================================");
                Console.Write("\tCurrently ");
                Colour.PrintPlayer(player.Colour, player.Name + "'s");
                Console.Write(" turn.");
                Console.Write("\n\tPlease select the territory you want to  ");
                Colour.SouthAmericaRed("Move Troops From.\n");

                MapBuilder.ShowEntireWorld();
                var option = GameEngine.UserInputTest("\n\t(1-42)>", "\tInvalid input, please try again!", 1, 42);

                territory = BoardPopulator.FindTerritory(option);
                if (territory.Occupant != player.Name)
                {
                    Console.WriteLine("\tTerritory is occupied by another player.");
                    Console.WriteLine("\tPress any key to retry....");
                    Console.ReadKey();
                }
                else if (territory.Armies == 1)
                {
                    Console.WriteLine("\tTerritory must have more than 1 army.");
                    Console.WriteLine("\tPress any key to retry....");
                    Console.ReadKey();
                }
                else
                {
                    confirmed = true;
                }
            }
            return(territory);
        }
示例#4
0
        public static void DeployTroops(Player player)
        {
            while (player.Armies > 0)
            {
                Console.Clear();
                Colour.SouthAmericaRed("\t     **** Risk! ****\n");
                Console.WriteLine("\t====================================");
                Colour.PrintPlayer(player.Colour, "\t" + player.Name);
                Console.WriteLine(" , add one or more army units to a territory you occupy");
                Console.Write("\tYou have ");
                Colour.PrintPlayer(player.Colour, player.Armies.ToString());
                Console.Write(" armies left to deploy");

                MapBuilder.ShowEntireWorld();

                var isPlayersTerritory = false;
                while (isPlayersTerritory == false)
                {
                    var selection = GameEngine.UserInputTest("\n\tEnter territory number (1-42)>",
                                                             "\tInvalid selection!", 1, 42);
                    var country = BoardPopulator.FindTerritory(selection);
                    if (country.Occupant == player.Name)
                    {
                        var troops = GameEngine.UserInputTest("\n\tEnter number of units you wish to send (1-" + player.Armies + ")>",
                                                              "\tInvalid selection!", 1, player.Armies);

                        country.Armies    += troops;
                        player.Armies     -= troops;
                        isPlayersTerritory = true;
                    }
                    else
                    {
                        Console.WriteLine("\tYou have selected a territory that is occupied by another player!\n");
                    }
                }
            }
        }
示例#5
0
        private static Territory PickReceiverTerritory(Territory supplier)
        {
            var territory = new Territory();
            var confirmed = false;

            while (confirmed == false)
            {
                Console.Clear();
                var player = GameBoard.GetBoard().CurrentPlayer;
                Colour.SouthAmericaRed("\t     **** Risk! ****\n");
                Console.WriteLine("\t====================================");
                Console.Write("\tCurrently ");
                Colour.PrintPlayer(player.Colour, player.Name + "'s");
                Console.Write(" turn.");
                Console.Write("\n\tPlease select the territory you want to  ");
                Colour.SouthAmericaRed("Fortify.\n");

                var numberMap = MapBuilder.ShowTerritoriesNeighbours(supplier);
                var option    = GameEngine.UserInputTest("\n\t(Territory number)>", "\tInvalid input, please try again!", 1,
                                                         numberMap.Count);
                int result;
                numberMap.TryGetValue(option, out result);

                territory = BoardPopulator.FindTerritory(result);
                if (territory != null && territory.Occupant == player.Name)
                {
                    confirmed = true;
                }
                else
                {
                    Console.WriteLine("\tCannot move troops into enemy territory!");
                    Console.WriteLine("\tPress any key to continue....");
                    Console.ReadKey();
                }
            }
            return(territory);
        }