示例#1
0
文件: Program.cs 项目: RoyWemmers/tba
        // This Method builds the menu
        static int ShowMenu(Map map, ref List <string> menu, ref Player player, ref BloodDrake drake, ref AngryMan angryman)
        {
            int    choice;
            string input;

            menu.Clear();
            ShowDirections(map, ref menu);

            if (map.GetLocation().CheckForItems())
            {
                bool acquirableitems = false;
                Dictionary <string, Objects> list = map.GetLocation().GetItems();
                Objects[] obj = list.Values.ToArray();
                for (int i = 0; i < obj.Count(); i++)
                {
                    if (obj[i].GetAcquirable())
                    {
                        acquirableitems = true;
                    }
                }
                if (acquirableitems)
                {
                    menu.Add(ACTION_SEARCH);
                }
            }
            if ((map.GetYPosition() == 5 && map.GetXPosition() == 1) && drake.IsAlive(drake.GetHealth()))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("On one of the pillars of the bridge is a smalle Blood Drake…");
                Console.WriteLine("The Blood Drake growls at you…");
                Console.WriteLine("It isn’t going to let you pass the bridge…");
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Gray;

                menu.Add("Fight the Blood Drake");
                menu.Add("Go via the side of the bridge");
            }

            if ((map.GetYPosition() == 3 && map.GetXPosition() == 2) && angryman.IsAlive(angryman.GetHealth()))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("When you knock on the door you hear heavy footsteps walking towards the door");
                Console.WriteLine("An angry man opens the door, and screams:");
                Console.WriteLine("If you don't stop bothering me I will kick your teeth in!");
                Console.WriteLine("As you look inside the house you can see a bag of gold.");
                Console.WriteLine("Do you want to fight the man, and take his gold, or will you leave the man.");
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Gray;

                menu.Add("Fight the man");
            }

            if (map.GetYPosition() == 7 && map.GetXPosition() == 1)
            {
                menu.Add("Climb over the wall");
                menu.Remove("Go North");
            }

            if (map.GetYPosition() == 9 && map.GetXPosition() == 1)
            {
                menu.Add("Fight the Boss");
            }

            menu.Add(ACTION_QUIT);
            menu.Add(ACTION_SHOP);
            menu.Add(ACTION_SHOWINVENTORY);

            if (player.HasObject("Health Potion"))
            {
                menu.Add(ACTION_USEHEALTHPOTION);
            }

            do
            {
                for (int i = 0; i < menu.Count(); i++)
                {
                    Console.WriteLine("{0} - {1}", i + 1, menu[i]);
                }
                Console.WriteLine("Please enter your choice: 1 - {0}", menu.Count());
                HealthUI(player.GetName(), player.GetHealth(), player.GetMaxHealth(), player.GetStamina(), player.GetMaxStamina(), player.GetGold());
                input = Console.ReadLine();
                Console.Clear();
                map.GetLocation().Description();
            } while (!int.TryParse(input, out choice) || (choice > menu.Count() || choice < 0));

            //return choice;
            return(choice - 1);
        }
示例#2
0
文件: Program.cs 项目: RoyWemmers/tba
        static void Start(ref Map map, ref Player player)
        {
            Rik           rik        = new Rik("Rik", 10000, 10000);
            BloodDrake    blooddrake = new BloodDrake("Blood Drake", 50, 10);
            AngryMan      angryman   = new AngryMan("Angry Man", 70, 10);
            CastleBoss    boss       = new CastleBoss("Castle Boss", 250, 10);
            List <string> menuItems  = new List <string>();
            int           choice;

            rik.EncounterRik();

            // Refactored by Michiel and Alex
            do
            {
                Console.Clear();
                map.GetLocation().Description();
                choice = ShowMenu(map, ref menuItems, ref player, ref blooddrake, ref angryman);

                if (choice != menuItems.Count())
                {
                    if (validDirections.Contains(menuItems[choice]))
                    {
                        map.Move(menuItems[choice]);
                    }

                    switch (menuItems[choice])
                    {
                    case ACTION_SEARCH:
                        // Add code to perform an item pickup
                        break;

                    case ACTION_FIGHT:
                        // Add code for fighting here
                        break;

                    case ACTION_RUN:
                        // Add code for running here
                        break;

                    case ACTION_SHOWINVENTORY:
                        player.ShowInventory();
                        Console.ReadLine();
                        choice = 0;
                        break;

                    case ACTION_SHOP:
                        Shop shop = new Shop();
                        shop.ShowShop(ref player);
                        choice = 0;
                        Console.ReadLine();
                        break;

                    case "Fight the Blood Drake":
                        Console.Clear();
                        blooddrake.StartEncouter(ref player, ref map);
                        Console.ReadLine();
                        map.Move("Go North");
                        break;

                    case "Go via the side of the bridge":
                        Console.Clear();
                        player.ClimbBridge(ref player);
                        Console.ReadLine();
                        map.Move("Go North");
                        break;

                    case ACTION_USEHEALTHPOTION:
                        HealthPotion hp = new HealthPotion("Health Potion", true);
                        hp.UsePotion(ref player);
                        choice = 0;
                        break;

                    case "Fight the man":
                        Console.Clear();
                        angryman.StartEncounter(ref player, ref map);
                        Console.ReadLine();
                        break;

                    case "Leave the man":
                        Console.Clear();
                        map.Move("Go West");
                        Console.ReadLine();
                        break;

                    case "Climb over the wall":
                        map.Move("Go North");
                        break;

                    case "Fight the Boss":
                        Console.Clear();
                        boss.StartEncounter(ref player);
                        Console.ReadLine();
                        break;
                    }
                }
            }
            // When the choice is equal to the total item it means exit has been chosen.
            while (choice < menuItems.Count() - 1);
        }