예제 #1
0
        private static bool Attack(Adventurer adventurer, Universe universe, Slime slime)
        {
            Random random    = new Random();
            int    damage    = adventurer.Damage;
            bool   blocking  = false;
            bool   tOb       = true;
            string attackMsg = "You slap the slime, YEAH F*** THAT GUY. WOOOOOOOOOOOOOOOOOO";

            if ((adventurer.PlayerWeapon == Adventurer.Weapon.BroadSword) || (adventurer.PlayerWeapon == Adventurer.Weapon.Sword))
            {
                attackMsg = "You swing your " + adventurer.PlayerWeapon + " at the slime";
            }
            else if ((adventurer.PlayerWeapon == Adventurer.Weapon.Dagger))
            {
                attackMsg = "You stabb the slime with your " + adventurer.PlayerWeapon;
            }
            else if ((adventurer.PlayerWeapon == Adventurer.Weapon.Bow))
            {
                attackMsg = "You shoot the slime with an arrow";
            }
            else if ((adventurer.PlayerWeapon == Adventurer.Weapon.Mace))
            {
                attackMsg = "You hit the slime with your " + adventurer.PlayerWeapon;
            }
            else if ((adventurer.PlayerWeapon == Adventurer.Weapon.Staff))
            {
                attackMsg = "You cast a fire spell on the slime.";
            }
            //
            // PLAYER MENU
            //


            //New method for handling

            TextBoxViews.DisplayCustom(universe, new string[4] {
                " Attack", " Throw a Rock : " + adventurer.ItemsDictionary[Item.Items.Stone], " Block", "Use a potion : " + adventurer.ItemsDictionary[Item.Items.HealthPotion]
            });

            TextBoxViews.ReWriteToMessageBox(universe, "Please choose an action...", true);

            while (tOb)
            {
                ConsoleKeyInfo key = Console.ReadKey();
                switch (key.Key)
                {
                case ConsoleKey.D1:
                    TextBoxViews.ReWriteToMessageBox(universe, attackMsg + " You dealt " + damage + " damage.");
                    slime.Health -= damage;
                    tOb           = false;
                    break;

                case ConsoleKey.D2:
                    if (adventurer.ItemsDictionary[Item.Items.Stone] >= 1)
                    {
                        adventurer.ItemsDictionary[Item.Items.Stone]--;
                        damage = 2;
                        TextBoxViews.ReWriteToMessageBox(universe, "You throw a stone at the slime and deal " + damage.ToString() + " damage.");
                        slime.Health -= damage;
                        tOb           = false;
                    }
                    else
                    {
                        TextBoxViews.ReWriteToMessageBox(universe, "You dont have any rocks to throw", true);
                    }
                    break;

                case ConsoleKey.D3:
                    TextBoxViews.ReWriteToMessageBox(universe, "You get ready to block the slime's next attack.");
                    blocking = true;
                    tOb      = false;
                    break;

                case ConsoleKey.D4:
                    if (adventurer.ItemsDictionary[Item.Items.HealthPotion] > 0)
                    {
                        adventurer.ItemsDictionary[Item.Items.HealthPotion]--;
                        Adventurer.PlayerPotionHeal(adventurer, universe);
                        tOb = false;
                    }
                    else
                    {
                        TextBoxViews.WriteToMessageBox(universe, "You don't have any health potions left");
                    }
                    break;



                case ConsoleKey.NumPad1:
                    TextBoxViews.ReWriteToMessageBox(universe, attackMsg + " You dealt " + damage + " damage.");
                    tOb = false;
                    break;

                case ConsoleKey.NumPad2:
                    if (adventurer.ItemsDictionary[Item.Items.Stone] > 0)
                    {
                        adventurer.ItemsDictionary[Item.Items.Stone]--;
                        damage = 2;
                        TextBoxViews.ReWriteToMessageBox(universe, "You throw a stone at the slime and deal " + damage.ToString() + " damage.");
                        slime.Health -= damage;
                        tOb           = false;
                    }
                    else
                    {
                        TextBoxViews.ReWriteToMessageBox(universe, "You dont have any stones to throw!");
                    }
                    break;

                case ConsoleKey.NumPad3:
                    TextBoxViews.ReWriteToMessageBox(universe, "You get ready to block the slime's next attack.");
                    blocking = true;
                    tOb      = false;
                    break;

                case ConsoleKey.NumPad4:
                    if (adventurer.ItemsDictionary[Item.Items.HealthPotion] > 0)
                    {
                        adventurer.ItemsDictionary[Item.Items.HealthPotion]--;
                        Adventurer.PlayerPotionHeal(adventurer, universe);
                        tOb = false;
                    }
                    else
                    {
                        TextBoxViews.WriteToMessageBox(universe, "You don't have any health potions left");
                    }
                    break;


                default:
                    TextBoxViews.ReWriteToMessageBox(universe, "Please Choose an attack using the numbers on your keyboard.", true);
                    break;
                }
            }
            return(blocking);
        }
예제 #2
0
        /// <summary>
        /// Sets up an inventory to display in the Menu
        /// </summary>
        /// <param name="adventurer"></param>
        public static void InventoryManagment(Adventurer adventurer, Universe universe)
        {
            bool           usingInventory = true;
            ConsoleKeyInfo key;
            Dictionary <Item.Items, int> itemList = new Dictionary <Item.Items, int>();

            Item.Items[] itemarray = new Item.Items[10];
            int          i         = 0;

            foreach (var item in adventurer.ItemsDictionary)
            {
                itemList.Add(item.Key, item.Value);
                itemarray[i] = item.Key;

                i++;
            }

            Item.Items itemToUse = Item.Items.Nothing;

            while (usingInventory)
            {
                TextBoxViews.RemoveContent(universe, 3);
                TextBoxViews.DisplayInventory(itemList);
                bool error = false;
                key = Console.ReadKey();
                try
                {
                    //remove use item from temp inventory
                    switch (key.Key)
                    {
                    case ConsoleKey.D1:
                        itemList[itemarray[0]] -= 1;
                        itemToUse = itemarray[0];
                        break;

                    case ConsoleKey.D2:
                        itemList[itemarray[1]] -= 1;
                        itemToUse = itemarray[1];
                        break;

                    case ConsoleKey.D3:
                        itemList[itemarray[2]] -= 1;
                        itemToUse = itemarray[2];
                        break;

                    case ConsoleKey.D4:
                        itemList[itemarray[3]] -= 1;
                        itemToUse = itemarray[3];
                        break;

                    case ConsoleKey.D5:
                        itemList[itemarray[4]] -= 1;
                        itemToUse = itemarray[4];
                        break;

                    case ConsoleKey.D6:
                        itemList[itemarray[5]] -= 1;
                        itemToUse = itemarray[5];
                        break;

                    case ConsoleKey.D7:
                        itemList[itemarray[6]] -= 1;
                        itemToUse = itemarray[6];
                        break;

                    case ConsoleKey.D8:
                        itemList[itemarray[7]] -= 1;
                        itemToUse = itemarray[7];
                        break;

                    case ConsoleKey.D9:
                        usingInventory = false;
                        break;

                    case ConsoleKey.NumPad1:
                        itemList[itemarray[0]] -= 1;
                        itemToUse = itemarray[0];
                        break;

                    case ConsoleKey.NumPad2:
                        itemList[itemarray[1]] -= 1;
                        itemToUse = itemarray[1];
                        break;

                    case ConsoleKey.NumPad3:
                        itemList[itemarray[2]] -= 1;
                        itemToUse = itemarray[2];
                        break;

                    case ConsoleKey.NumPad4:
                        itemList[itemarray[3]] -= 1;
                        itemToUse = itemarray[3];
                        break;

                    case ConsoleKey.NumPad5:
                        itemList[itemarray[4]] -= 1;
                        itemToUse = itemarray[4];
                        break;

                    case ConsoleKey.NumPad6:
                        itemList[itemarray[5]] -= 1;
                        itemToUse = itemarray[5];
                        break;

                    case ConsoleKey.NumPad7:
                        itemList[itemarray[6]] -= 1;
                        itemToUse = itemarray[6];
                        break;

                    case ConsoleKey.NumPad8:
                        itemList[itemarray[7]] -= 1;
                        itemToUse = itemarray[7];
                        break;

                    case ConsoleKey.NumPad9:
                        usingInventory = false;
                        break;


                    case ConsoleKey.LeftArrow:
                        usingInventory = false;
                        break;

                    case ConsoleKey.RightArrow:
                        usingInventory = false;
                        break;

                    case ConsoleKey.UpArrow:
                        usingInventory = false;
                        break;

                    case ConsoleKey.DownArrow:
                        usingInventory = false;
                        break;



                    default:
                        break;
                    }
                }
                catch (Exception)
                {
                    error = true;
                    //No throwing in here
                }
                finally
                {
                    //I decided im not dealing with the program deciding to add to nothing. tOb can keep trying though
                    try
                    {
                        if (!error && !(key.Key == ConsoleKey.D9 || key.Key == ConsoleKey.NumPad9) && !(adventurer.ItemsDictionary[itemToUse] <= 0))
                        {
                            switch (itemToUse)
                            {
                            case Item.Items.HealthPotion:
                                Adventurer.PlayerPotionHeal(adventurer, universe);
                                adventurer.ItemsDictionary[itemToUse] = itemList[itemToUse];
                                break;

                            case Item.Items.ManaPotion:
                                TextBoxViews.WriteToMessageBox(universe, "You feel all tingly inside");
                                adventurer.ItemsDictionary[itemToUse] = itemList[itemToUse];
                                break;

                            case Item.Items.Stone:
                                TextBoxViews.WriteToMessageBox(universe, "You throw the stone and it vanishes into the distance...");
                                adventurer.ItemsDictionary[itemToUse] = itemList[itemToUse];
                                break;

                            case Item.Items.SlimeGel:
                                TextBoxViews.WriteToMessageBox(universe, "You cannot use slime...");
                                itemList[itemToUse]++;
                                break;

                            case Item.Items.Parcel:
                                TextBoxViews.WriteToMessageBox(universe, "You cannot use the parcel you are delivering!");
                                itemList[itemToUse]++;
                                break;

                            case Item.Items.Nothing:
                                TextBoxViews.WriteToMessageBox(universe, "There is nothing there");
                                break;

                            default:
                                break;
                            }
                        }

                        else if (!(key.Key == ConsoleKey.D9 || key.Key == ConsoleKey.NumPad9) && (itemList[itemToUse] < 0))
                        {
                            TextBoxViews.WriteToMessageBox(universe, "You dont have that item");

                            itemList[itemToUse]++;
                        }
                        else if (!(key.Key == ConsoleKey.D9 || key.Key == ConsoleKey.NumPad9))
                        {
                            TextBoxViews.WriteToMessageBox(universe, "You dont have that item");
                        }
                    }
                    catch (Exception)
                    {
                    } //End try catch inventory navigation
                }     //end finally
            }         //end using inventory while


            TextBoxViews.DisplayMenu(universe);
        }