Exemple #1
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);
        }
Exemple #2
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);
        }