Exemple #1
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);
                }
            }
        }
Exemple #2
0
        public override Boolean OnEnter()
        {
            base.OnEnter();
            AddRoom(typeof(Forest_start));

            Optionhandler threat = new Optionhandler("A Bandit appears between the trees. He points a saber at you");
            GenericOption opt;

            opt = new GenericOption("flee");
            opt.AddExecutionAction(() => tryflee());
            threat.AddOption(opt);

            opt = new GenericOption("Attack");
            opt.AddExecutionAction(() => attack());
            threat.AddOption(opt);


            threat.selectOption();

            if (!bandit.isAlive())
            {
                Optionhandler oh = new Optionhandler("next move?", true);
                opt = new GenericOption("Loot");
                oh.AddOption(opt);
                opt.AddExecutionAction(() => this.bandit.loot());

                oh.selectOption().Select();
            }
            return(true);
        }
Exemple #3
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);
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// Open the Inventory for a category to navigate within it and execute Actions on the Items.
        /// <para>
        /// getsCommand is a function which takes an Item and returns wether the Item should receive a/many Command/s or not
        /// </para>
        /// <para>onItemSelection is an Action which  is executed with the selected Item</para>
        /// <para>isAvailable is a FUnc which determines wether the item is available or not. It is appended to each Option</para>
        /// <para>UnavailableMessage is a Func which retruns the string to be printed when the Optionw as selected & unavailable</para>
        /// <para>if allowItemActions = false, no Item Actions are allowed</para>
        /// </summary>
        void NavigateItems(string category, Func <Item, bool> getsCommand, Action <Item> onItemSelection, Func <Item, bool> isAvailable, Func <Item, string> UnavailableMessage, bool allowItemActions)
        {
            Option selected = null;

            while (selected != Optionhandler.Exit)
            {
                List <Item> Items = this.GetAllItems(category);
                if (Items.Count == 0)
                {
                    return;
                }
                printHeader();
                Optionhandler OH = new Optionhandler(true);
                OH.setName("Inventory.Item");
                foreach (Item i in Items)
                {
                    if (allowItemActions == false)
                    {
                        if (getsCommand(i))
                        {
                            //Options which are available on the Item are defined on the Item and wrapped by the GenericItemOption
                            GenericItemOption opt = new GenericItemOption(i);
                            if (isAvailable != null)
                            {
                                Func <bool> f = () => isAvailable(i);
                                opt.SetAvailable(f);
                            }
                            if (UnavailableMessage != null)
                            {
                                Func <string> ff = () => UnavailableMessage(i);
                                opt.setNotAvailable(ff);
                            }
                            OH.AddOption(opt);
                        }
                        else
                        {
                            CIO.Print(i.getDescription());
                        }
                    }
                    else
                    {
                        GenericItemOption opt = new GenericItemOption(i);
                        OH.AddOption(opt);
                    }
                }
                selected = OH.selectOption(false);
                if (selected.GetType() == typeof(GenericItemOption))
                {
                    onItemSelection(((GenericItemOption)selected).getItem());
                }
            }
        }
Exemple #5
0
        public static void gameOver()
        {
            Optionhandler d = new Optionhandler("and now?");
            GenericOption o = new GenericOption("Exit", true);

            o.AddExecutionAction(() => Environment.Exit(0));
            d.AddOption(o);

            o = new GenericOption("Restart", true);
            o.AddExecutionAction(() => restart());
            d.AddOption(o);
            d.selectOption();
        }
Exemple #6
0
        protected Option PickCategory()
        {
            printHeader();
            Optionhandler OH = new Optionhandler("pick a category", true);

            OH.setName("Spellbook.Types");

            foreach (SpellType i in this.getSpellTypes())
            {
                OH.AddOption(i);
            }
            return(OH.selectOption(false));
        }
Exemple #7
0
        private void friend()
        {
            Optionhandler d;

            d = new Optionhandler("Creature is barking: Hey hooman. Just need someone to talk. Nice to meet you. Byebye.");
            d.AddOption(new GenericOption("Petting the Dog-Ghost"));
            GenericOption opt = new GenericOption("Flee");

            d.AddOption(opt);

            opt.AddExecutionAction(() => flee());
            d.selectOption();
        }
Exemple #8
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();
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Open the Inventory to pick a category.
        /// </summary>
        protected GenericOption PickCategory()
        {
            printHeader();
            Optionhandler OH = new Optionhandler("pick a category", true);

            OH.setName("Inventory.Category");

            foreach (string i in this.GetCategories())
            {
                GenericOption GO = new GenericOption(i);
                OH.AddOption(GO);
            }
            GenericOption selected = (GenericOption)OH.selectOption(false);

            return(selected);
        }
Exemple #10
0
        /// <summary>
        /// Opens a Dialog for the user to trade with the merchant. The user can choose between selling and buying
        /// </summary>
        public void trade()
        {
            Option        selectedOption = null;
            Optionhandler oh             = new Optionhandler("trade with " + this.name, true);
            GenericOption opt            = new GenericOption("Buy");

            opt.AddExecutionAction(this.OpenInventoryForTrade);
            oh.AddOption(opt);
            opt = new GenericOption("Sell");
            opt.AddExecutionAction(() => Player.getInstance().OpenInventoryForTrade(this));
            oh.AddOption(opt);

            while (selectedOption != Optionhandler.Exit)
            {
                selectedOption = oh.selectOption();
            }
        }
Exemple #11
0
        void NavigateItems(SpellType type)
        {
            Option selected = null;

            while (selected != Optionhandler.Exit)
            {
                List <Spell> Spells = this.getSpells(type);
                if (Spells.Count == 0)
                {
                    return;
                }
                printHeader();
                Optionhandler OH = new Optionhandler(true);
                OH.setName("Spellbook.Spell");
                foreach (Spell i in Spells)
                {
                    OH.AddOption(i);
                }
                selected = OH.selectOption(false);
            }
        }
Exemple #12
0
        private void levelUp()
        {
            this.level++;
            CIO.Print("Reached level " + level);
            this.health += (int)Math.Floor(health * 0.02);
            GenericOption oStrength     = new GenericOption("Strength");
            GenericOption oIntelligence = new GenericOption("Intelligence");
            Optionhandler oh            = new Optionhandler("Choose an Attribute to upgrade ");

            oh.AddOption(oStrength);
            oh.AddOption(oIntelligence);
            Option result = (Option)oh.selectOption();

            if (result == oStrength)
            {
                this.IncreaseStrength(1);
            }
            else if (result == oIntelligence)
            {
                this.IncreaseIntelligence(1);
            }
        }
Exemple #13
0
        public override Boolean OnEnter()
        {
            if (!unlocked)
            {
                CIO.Print("You try to enter " + this.name);
                CIO.PrintStory("A guard approaches you");
                Optionhandler d = new Optionhandler("'No Place for you here peasant'");
                d.AddOption(new Bribe(200, () => this.unlocked = true, 0.2f));

                d.AddOption(new GenericOption("Leave", true));
                d.selectOption();


                if (!unlocked)
                {
                    Program.currentRoom = this.LastRoom;
                    return(false);
                }
            }
            base.OnEnter();
            this.AddRoom(LastRoom);
            return(true);
        }
Exemple #14
0
        public override bool OnEnter()
        {
            base.OnEnter();
            //CIO.PrintStory("The cave is as dark as night and an unsettling static lies in the air. Your Lucifer creates but a dim light that bareley reaches your feet." );
            Optionhandler d = new Optionhandler("The cave is it dark and scary, to have some you grab your lucifer. You hear a creepy noise just several meters infront of you. A white, dusty creation apperas in front of you, moving her mouth without sound Seconds later echoing from the walls 'Greetings traveler' ");

            d.AddOption(new GenericOption("Attack"));
            GenericOption opt = new GenericOption("Hello spooky creature? How can I help you?");

            d.AddOption(opt);
            opt.AddExecutionAction(() => friend());
            d.selectOption();

            if (thrownToNewRoom)
            {
                return(false);
            }
            AddRoom(typeof(Forest_start));



            return(true);
        }
Exemple #15
0
 public Context(Optionhandler currentOptionhandler, string name)
 {
     this.myOptionhandler = currentOptionhandler;
     this.name            = name;
 }
Exemple #16
0
 public Context(Optionhandler currentOptionhandler)
 {
     this.myOptionhandler = currentOptionhandler;
 }