Esempio n. 1
0
        static void Main(string[] args)
        {
            //create an instance of the sword class
            Sword sword = new Sword("Sword of Destiny");

            //equip the sword
            sword.Equip();
            //sell the sword
            sword.Sell();
            //durability takes damage of 20
            sword.Damage(20);

            Console.WriteLine();

            //create an instance of the axe class
            Axe axe = new Axe("Axe of Wonders");

            //equip the axe
            axe.Equip();
            //sell the axe
            axe.Sell();
            //durability takes damage of 10
            axe.Damage(10);

            Console.WriteLine();

            //create an Inventory so that you turn in items
            //this is an "array" of items
            Iitem[] inventory = new Iitem[2];
            inventory[0] = sword;
            inventory[1] = axe;

            //loop through and turn in all quest items
            //create an index and set it to 0 which is less than the number of items in the inventory and increment the index
            for (int index = 0; index < inventory.Length; index++)
            {
                //check items to turn in from the inventory
                IPartOfQuest Items = inventory[index] as IPartOfQuest;
                //make sure the inventory is not empty and has an item in it.
                if (Items != null)
                {
                    Items.TurnIn();
                }
            }
            //await user input
            Console.ReadKey();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Sword sword = new Sword("Sword of Destiny");

            sword.Equip();
            sword.TakeDamage(20);
            sword.Sell();
            sword.TurnIn();
            Console.WriteLine();
            Axe axe = new Axe("Axe of fury");

            axe.Equip();
            axe.TakeDamage(10);
            axe.Sell();

            //Create an Inventory
            IItem[] inventory = new IItem[2];
            inventory[0] = sword;
            inventory[1] = axe;
            Console.WriteLine();

            //Loop through and turn in all quest items
            //You have to case IPartOfQuest using the "as" keyword

            for (int i = 0; i < inventory.Length; i++)
            {
                IPartOfQuest questItem = inventory[i] as IPartOfQuest;

                if (questItem != null)
                {
                    questItem.TurnIn();
                }
            }

            Console.ReadKey();
        }