示例#1
0
 public void UsePotion(ref Player player)
 {
     player.SetHealth(-50);
     player.DelItemInvenyory("Health Potion");
     if (player.GetHealth() > 100)
     {
         player.SetHealth(-(player.GetMaxHealth() - player.GetHealth()));
     }
 }
示例#2
0
文件: FightUI.cs 项目: RoyWemmers/tba
        public int ShowFightUI(ref Player player)
        {
            int damage;

            Program.HealthUI(player.GetName(), player.GetHealth(), player.GetMaxHealth(), player.GetStamina(), player.GetMaxStamina(), player.GetGold());
            damage = FightMenu(ref player);
            return(damage);
        }
示例#3
0
        static void Start(ref Map map, ref Player player)
        {
            List <string> menuItems = new List <string>();

            int    choice = 0;
            Random rdm    = new Random();


            // Refactored by Michiel and Alex
            do
            {
                Console.Clear();

                map.GetLocation().Description(ref map);
                if (menuItems.Count != 0)
                {
                    if (menuItems[choice].StartsWith(ACTION_DISCRIPTION_NORTH))
                    {
                        Program.PrintLine(100, map.GetLocation().GetBlockage(0).GetDiscription(ref map));
                    }
                    else if (menuItems[choice].StartsWith(ACTION_DISCRIPTION_EAST))
                    {
                        Program.PrintLine(100, map.GetLocation().GetBlockage(1).GetDiscription(ref map));
                    }
                    else if (menuItems[choice].StartsWith(ACTION_DISCRIPTION_SOUTH))
                    {
                        Program.PrintLine(100, map.GetLocation().GetBlockage(2).GetDiscription(ref map));
                    }
                    else if (menuItems[choice].StartsWith(ACTION_DISCRIPTION_WEST))
                    {
                        Program.PrintLine(100, map.GetLocation().GetBlockage(3).GetDiscription(ref map));
                    }
                }
                choice = ShowMenu(map, ref menuItems);

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

                    if (menuItems[choice].StartsWith(ACTION_INTERACT_NORTH))
                    {
                        map.GetLocation().GetBlockage(0).OnPlayerInteraction(ref player, ref map);
                    }
                    else if (menuItems[choice].StartsWith(ACTION_INTERACT_EAST))
                    {
                        map.GetLocation().GetBlockage(1).OnPlayerInteraction(ref player, ref map);
                    }
                    else if (menuItems[choice].StartsWith(ACTION_INTERACT_SOUTH))
                    {
                        map.GetLocation().GetBlockage(2).OnPlayerInteraction(ref player, ref map);
                    }
                    else if (menuItems[choice].StartsWith(ACTION_INTERACT_WEST))
                    {
                        map.GetLocation().GetBlockage(3).OnPlayerInteraction(ref player, ref map);
                    }

                    switch (menuItems[choice])
                    {
                    case ACTION_SEARCH:
                        foreach (Objects item in map.GetLocation().GetItems().Values)
                        {
                            player.PickupItem(item);
                        }

                        break;

                    case ACTION_FIGHT:
                        map.GetLocation().GetEnemy().TakeHit(rdm.Next(10, 20));
                        if (map.GetLocation().GetEnemy().GetHealth() > 0)
                        {
                            player.TakeHit(rdm.Next(5, 20));
                            if (player.GetHealth() <= 0)
                            {
                                Console.ReadLine();
                                Quit();
                            }
                        }
                        else
                        {
                            Program.PrintLine(100, "You have won from you enemy");
                            if (!map.GetLocation().GetItems().ContainsKey(map.GetLocation().GetEnemy().Loot().GetName()))
                            {
                                map.GetLocation().GetItems().Add(map.GetLocation().GetEnemy().Loot().GetName(), map.GetLocation().GetEnemy().Loot());
                            }

                            map.GetLocation().SetEnemy(null);
                        }

                        break;

                    case ACTION_RUN:
                        Program.PrintLine(100, "You shouldn't have runned away from your enemy");
                        Console.ReadLine();
                        Quit();
                        break;
                    }
                }
            }
            // When the choice is equal to the total item it means exit has been chosen.
            while (choice < menuItems.Count() - 1);
        }
示例#4
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);
        }