Exemplo n.º 1
0
 public FightAction getPlayerWeapon()
 {
     while (true)
     {
         Optionhandler ohCategory = new Optionhandler("Choose your next Action");
         ohCategory.AddOption(new GenericOption("Weapons"));
         ohCategory.AddOption(new GenericOption("Potion"));
         ohCategory.AddOption(new GenericOption("Spell"));//todo: check if items are in the option beforehand
         GenericOption selectedCategory = (GenericOption)ohCategory.selectOption();
         List <Option> optionsInTheCategory;
         if (selectedCategory.name == "Spell")
         {
             optionsInTheCategory = Player.getInstance().getAllSpells().Cast <Option>().ToList();
         }
         else
         {
             optionsInTheCategory = Player.getInstance().inventory.GetAllItems(selectedCategory.name).Cast <Option>().ToList();
         }
         Optionhandler ohItem = new Optionhandler("choose your " + selectedCategory.name, true);
         ohItem.AddOptions(optionsInTheCategory);
         Option selected = ohItem.selectOption();
         if (selected != Optionhandler.Exit)
         {
             return((FightAction)selected);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Open a user dialog which allows th user navigate through the NPCs Inventory and take Items
        /// </summary>
        public void loot()
        {
            if (!this.inventory.ContainsAnyItems())
            {
                CIO.Print(this.name + "'s inventory is empty");
                return;
            }
            GenericOption takeAllOption  = new GenericOption("take all");
            Optionhandler oh             = new Optionhandler(this.name + "'s inventory ", true);
            Option        selectedOption = null;

            //the user stays inside the inventory until all items are gon or he picks exit
            while (selectedOption != Optionhandler.Exit && this.inventory.ContainsAnyItems())
            {
                List <Item> allitems = this.inventory.GetAllItems();
                oh.ClearOptions();
                oh.AddOptions(Optionhandler.ItemToOption(allitems));
                oh.AddOption(takeAllOption);
                selectedOption = oh.selectOption();
                if (selectedOption == takeAllOption)
                {
                    foreach (Item i in allitems)
                    {
                        Inventory.transferItem(this.inventory, Player.getInstance().inventory, i);
                    }
                }
                else
                {
                    Inventory.transferItem(this.inventory, Player.getInstance().inventory, (Item)selectedOption);
                }
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            player = Player.getInstance();

            createStartRoom();
            CIO.Initialize();
            currentRoom = Room.AllRooms[typeof(GameContent.Rooms.Forest_start)];
            GlobalCommands.GiveSword();
            player.LearnSpell(Spell.Flames);


            while (true)
            {
                Console.WriteLine("#########################");
                Room r = currentRoom;
                if (r.OnEnter())
                {
                    Room nextroom = null;
                    while (nextroom == null)
                    {
                        Optionhandler h;
                        if (r.ActivitiesInRoom != null)//print activities if there are any
                        {
                            h = new Optionhandler(r.name + ". Activities:");
                            h.AddOptions(r.ActivitiesInRoom);
                            h.AddHeading("Next Rooms:");
                        }
                        else
                        {
                            h = new Optionhandler(r.name + ". next room?");
                        }
                        h.AddOptions(Optionhandler.RoomsToOption(r.nextRooms));
                        Option selectedOpt = h.selectOption();
                        if (selectedOpt.GetType().IsSubclassOf(typeof(Room)))
                        {
                            nextroom = (Room)selectedOpt;
                        }
                    }
                    CIO.Clear();
                    currentRoom.OnExit();
                    currentRoom = nextroom;
                }
                else
                {
                    CIO.Clear();
                    r.OnExit();
                }
            }
        }