Ejemplo n.º 1
0
        public override void Use(Player player, Game game, Command command)
        {
            string direction    = command.getThirdWord();
            Room   ToBeUnlocked = player.currentRoom.getExit(direction);

            Console.WriteLine(direction);

            if (!command.hasThirdWord())
            {
                Console.WriteLine("Use the key in which direction?");
            }

            if (ToBeUnlocked == null)
            {
                Console.WriteLine("Can't find a door in that direction!");
            }
            else
            {
                if (!ToBeUnlocked.isLocked)
                {
                    Console.WriteLine("That door doesn't seem to be locked");
                }
                else
                {
                    ToBeUnlocked.isLocked = false;
                    Console.WriteLine("Unlocked door!");
                }
            }
        }
Ejemplo n.º 2
0
        private void Unlock(Command command)
        {
            if (!command.hasSecondWord())
            {
                // if there is no second word, we don't know where to go...
                Console.WriteLine("Which room do you want to unlock?");
                Console.WriteLine("Use the command like this 'Unlock' 'exit' 'the item that is a key'.");
                return;
            }
            if (!command.hasThirdWord())
            {
                // if there is no second word, we don't know where to go...
                Console.WriteLine("Which key do you want to use?");
                return;
            }

            string door = command.getSecondWord();
            string key  = command.getThirdWord();
            Room   toOpen;
            Key    toUse;

            // Try to leave current room.
            if (door == null)
            {
                Console.WriteLine("There is no door with this name: " + door + "!");
            }
            toOpen = player.GetCurrentRoom().getExit(door);
            if (player.GetInventory().GetItem(key) is Key)
            {
                toUse = (Key)player.GetInventory().GetItem(key);
                if (player.IsAlive())
                {
                    if (player.GetCurrentRoom().GetTier() > toUse.GetTier())
                    {
                        Console.WriteLine("That Key is not strong enough for this door");
                    }
                    else
                    {
                        player.GetInventory().UseKey(player, toUse, toOpen);
                    }
                }
                else
                {
                    Console.WriteLine("you died " + player.GetCurrentRoom().getLongDescription());
                }
            }
            else
            {
                if (player.IsAlive())
                {
                    Console.WriteLine("That's not a key");
                }
                else
                {
                    Console.WriteLine("you died " + player.GetCurrentRoom().getLongDescription());
                }
            }
        }
Ejemplo n.º 3
0
        public void UnlockDoor(Command command, Item item)
        {
            string direction = command.getThirdWord();

            if (!command.hasThirdWord())
            {
                Console.WriteLine("On which direction should the key be used?");
            }
            else
            {
            }
        }
Ejemplo n.º 4
0
        // implementations of user commands:
        private void use(Command command)
        {
            Item i = null;

            if (command.hasSecondWord())
            {
                for (int e = player.Inventory.List.Count - 1; e >= 0; e--)
                {
                    if (command.getSecondWord() == player.Inventory.List[e].name)
                    {
                        i = player.Inventory.List[e];
                    }
                }

                if (command.hasThirdWord())
                {
                    Room roomToUnlock = player.Currentroom.getExit(command.getThirdWord());

                    if (roomToUnlock == null)
                    {
                        Console.WriteLine("There is no door to unlock in that direction!");
                        return;
                    }
                    else
                    {
                        if (i == null)
                        {
                            Console.WriteLine("This item does not exist in your inventory!");
                            return;
                        }
                        else
                        {
                            i.use(roomToUnlock);
                            return;
                        }
                    }
                }

                if (i == null)
                {
                    Console.WriteLine("The item you're trying to use does not exist!");
                }
                else
                {
                    i.use(player);
                }
            }
            else
            {
                Console.WriteLine("Please specify an item to use!");
            }
        }
Ejemplo n.º 5
0
        private void useItem(Command command)
        {
            if (!command.hasSecondWord())
            {
                // if there is no second word, we don't know where to go...
                Console.WriteLine("Use what?");
                return;
            }
            string item = command.getSecondWord();

            if (!command.hasThirdWord() && item is "key")
            {
                // if there is no second word, we don't know where to go...
                Console.WriteLine("Which room?");
                return;
            }

            if (player.inventory.getPlayerItems().ContainsKey(item)) //Checkt of item in inv zit.
            {
                if (item is "key")
                {
                    string direction = command.getThirdWord();
                    Room   r         = player.currentRoom.getExit(direction);
                    key.Use(r);
                }

                Item useThis = player.inventory.getPlayerItems()[command.getSecondWord()];

                if (item is "key")
                {
                }
                else
                {
                    Console.WriteLine("You used: " + item);
                    player.inventory.OutInv(item);
                    player.usedItem(useThis);
                    player.playerWeightMin(useThis);
                }
                Console.ForegroundColor = ConsoleColor.DarkRed;
                if (useThis.damage > 0)
                {
                    Console.WriteLine("You took: " + useThis.damage + " Damage.");
                }
                Console.ForegroundColor = ConsoleColor.White;
            }
            else
            {
                Console.WriteLine("The item you are describing is non existant.");
            }
        }
Ejemplo n.º 6
0
        public void useItem(Command command)
        {
            Item i = null;

            if (command.hasSecondWord())
            {
                for (int y = player.PlayerInventory.Items.Count - 1; y >= 0; y--)
                {
                    if (command.getSecondWord() == player.PlayerInventory.Items[y].name)
                    {
                        i = player.PlayerInventory.Items[y];
                    }
                }
            }
            if (command.hasThirdWord())
            {
                Room unlockableRoom = player.CurrentRoom.getExit(command.getThirdWord());
                if (unlockableRoom == null)
                {
                    Console.WriteLine("this room might be already unlocked or it doesn't exist. Feels bad man");
                }
                else
                {
                    if (i == null)
                    {
                        Console.WriteLine("I don't think you have that item");
                        return;
                    }
                    else
                    {
                        i.use(unlockableRoom);
                        return;
                    }
                }
            }

            else
            {
                Console.WriteLine("I think you don't have that item. Can't help you sorry!");
            }
        }
Ejemplo n.º 7
0
        /**
         * Equips an item to a player equip slot so these can later be used for certain actions
         */

        private void equipItem(Command command)
        {
            int num;

            if (command.hasSecondWord())
            {
                if (command.hasThirdWord())
                {
                    if (int.TryParse(command.getSecondWord(), out num))
                    {
                        num++;

                        if (num > 0 && num < player.Inventory.Items.Count)
                        {
                            Item i = player.Inventory.Items[num];

                            switch (command.getThirdWord())
                            {
                            case "hand":

                                if (i is Armor || i is Special)
                                {
                                    Console.WriteLine("You cannot equip armor or special items to your hand!");
                                }
                                else
                                {
                                    if (player.FirstHand == null)
                                    {
                                        player.Inventory.Items.RemoveAt(num);
                                        player.FirstHand = i;
                                        Console.WriteLine("Equipped: " + i.Name + " to hand.");
                                    }
                                    else
                                    {
                                        Item ii = player.FirstHand;
                                        player.Inventory.Items.RemoveAt(num);
                                        player.Inventory.addItem(ii);
                                        player.FirstHand = i;
                                        Console.WriteLine("Unequiped: " + ii.Name + " from hand.");
                                        Console.WriteLine("Equipped: " + i.Name + " to hand.");
                                    }
                                }

                                break;

                            case "offhand":

                                if (i is Armor || i is Special)
                                {
                                    Console.WriteLine("You cannot equip armor or special items to your second hand!");
                                }
                                else
                                {
                                    if (player.SecondHand == null)
                                    {
                                        player.Inventory.Items.RemoveAt(num);
                                        player.SecondHand = i;
                                        Console.WriteLine("Equipped: " + i.Name + " to second hand.");
                                    }
                                    else
                                    {
                                        Item ii = player.SecondHand;
                                        player.Inventory.Items.RemoveAt(num);
                                        player.Inventory.addItem(ii);
                                        player.SecondHand = i;
                                        Console.WriteLine("Unequiped: " + ii.Name + " from second hand.");
                                        Console.WriteLine("Equipped: " + i.Name + " to second hand.");
                                    }
                                }

                                break;

                            case "armor":

                                if (i is Armor)
                                {
                                    if (player.Armor == null)
                                    {
                                        player.Inventory.Items.RemoveAt(num);
                                        player.Armor = i;
                                        Console.WriteLine("Equipped: " + i.Name + " to armor slot.");
                                    }
                                    else
                                    {
                                        Item ii = player.Armor;
                                        player.Inventory.Items.RemoveAt(num);
                                        player.Inventory.addItem(ii);
                                        player.Armor = i;
                                        Console.WriteLine("Unequiped: " + ii.Name + " from armor slot.");
                                        Console.WriteLine("Equipped: " + i.Name + " to armor slot.");
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("You cannot equip anything but armors to the armor slot.");
                                }

                                break;

                            case "special":

                                if (i is Special)
                                {
                                    if (player.Special == null)
                                    {
                                        player.Inventory.Items.RemoveAt(num);
                                        player.Special = i;
                                        Console.WriteLine("Equipped: " + i.Name + " to special slot.");
                                    }
                                    else
                                    {
                                        Item ii = player.Special;
                                        player.Inventory.Items.RemoveAt(num);
                                        player.Inventory.addItem(ii);
                                        player.Special = i;
                                        Console.WriteLine("Unequiped: " + ii.Name + " from special slot.");
                                        Console.WriteLine("Equipped: " + i.Name + " to special slot.");
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("You can only equip specials to this slot");
                                }

                                break;

                            default:
                                Console.WriteLine("That is not an equip slot.");
                                break;
                            }
                        }
                    }
                    else
                    {
                        bool completed = false;
                        for (int i = player.Inventory.Items.Count - 1; i >= 0; i--)
                        {
                            if (completed)
                            {
                                break;
                            }

                            Item ii = player.Inventory.Items[i];

                            if (ii.Name == command.getSecondWord())
                            {
                                switch (command.getThirdWord())
                                {
                                case "hand":

                                    if (ii is Armor || ii is Special)
                                    {
                                        Console.WriteLine("You cannot equip armor or special items to your hand!");
                                    }
                                    else
                                    {
                                        if (player.FirstHand == null)
                                        {
                                            player.Inventory.Items.RemoveAt(i);
                                            player.FirstHand = ii;
                                            Console.WriteLine("Equipped: " + ii.Name + " to hand.");
                                            completed = true;
                                        }
                                        else
                                        {
                                            Item ir = player.FirstHand;
                                            player.Inventory.Items.RemoveAt(i);
                                            player.Inventory.addItem(ir);
                                            player.FirstHand = ii;
                                            Console.WriteLine("Unequiped: " + ir.Name + " from hand.");
                                            Console.WriteLine("Equipped: " + ii.Name + " to hand.");
                                            completed = true;
                                        }
                                    }

                                    break;

                                case "offhand":

                                    if (ii is Armor || ii is Special)
                                    {
                                        Console.WriteLine("You cannot equip armor or special items to your second hand!");
                                    }
                                    else
                                    {
                                        if (player.SecondHand == null)
                                        {
                                            player.Inventory.Items.RemoveAt(i);
                                            player.SecondHand = ii;
                                            Console.WriteLine("Equipped: " + ii.Name + " to second hand.");
                                            completed = true;
                                        }
                                        else
                                        {
                                            Item ir = player.SecondHand;
                                            player.Inventory.Items.RemoveAt(i);
                                            player.Inventory.addItem(ir);
                                            player.SecondHand = ii;
                                            Console.WriteLine("Unequiped: " + ir.Name + " from second hand.");
                                            Console.WriteLine("Equipped: " + ir.Name + " to second hand.");
                                            completed = true;
                                        }
                                    }

                                    break;

                                case "armor":

                                    if (ii is Armor)
                                    {
                                        if (player.Armor == null)
                                        {
                                            player.Inventory.Items.RemoveAt(i);
                                            player.Special = ii;
                                            Console.WriteLine("Equipped: " + ii.Name + " to armor slot.");
                                            completed = true;
                                        }
                                        else
                                        {
                                            Item ir = player.Armor;
                                            player.Inventory.Items.RemoveAt(i);
                                            player.Inventory.addItem(ir);
                                            player.Special = ii;
                                            Console.WriteLine("Unequiped: " + ir.Name + " from armor slot.");
                                            Console.WriteLine("Equipped: " + ir.Name + " to armor slot.");
                                            completed = true;
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("You cannot equip anything but armors to the armor slot.");
                                    }

                                    break;

                                case "special":

                                    if (ii is Special)
                                    {
                                        if (player.Special == null)
                                        {
                                            player.Inventory.Items.RemoveAt(i);
                                            player.Armor = ii;
                                            Console.WriteLine("Equipped: " + ii.Name + " to special slot.");
                                            completed = true;
                                        }
                                        else
                                        {
                                            Item ir = player.Special;
                                            player.Inventory.Items.RemoveAt(i);
                                            player.Inventory.addItem(ir);
                                            player.Armor = ii;
                                            Console.WriteLine("Unequiped: " + ir.Name + " from special slot.");
                                            Console.WriteLine("Equipped: " + ir.Name + " to special slot.");
                                            completed = true;
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("You can only equip specials to this slot");
                                    }

                                    break;

                                default:
                                    Console.WriteLine("That is not an equip slot.");
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    for (int i = player.Inventory.Items.Count - 1; i >= 0; i--)
                    {
                        Item ii = player.Inventory.Items[i];

                        if (ii.Name == command.getSecondWord())
                        {
                            if (ii is Armor || ii is Special)
                            {
                                Console.WriteLine("You cannot equip armor or special items to your hand!");
                            }
                            else
                            {
                                if (player.FirstHand == null)
                                {
                                    player.Inventory.Items.RemoveAt(i);
                                    player.FirstHand = ii;
                                    Console.WriteLine("Equipped: " + ii.Name + " to hand.");
                                }
                                else
                                {
                                    Item ir = player.FirstHand;
                                    player.Inventory.Items.RemoveAt(i);
                                    player.Inventory.addItem(ir);
                                    player.FirstHand = ii;
                                    Console.WriteLine("Unequiped: " + ir.Name + " from hand.");
                                    Console.WriteLine("Equipped: " + ii.Name + " to hand.");
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("No item to equip given.");
            }
        }
Ejemplo n.º 8
0
        /**
         * Use an item can have a lto of different targets and a can take an item index or and equip slot for the item to use
         */

        private void useItem(Command command)
        {
            Item i = null;

            switch (command.getSecondWord())
            {
            case "hand":
                i = player.FirstHand;
                break;

            case "offhand":
                i = player.SecondHand;
                break;

            default:
                int num;
                if (int.TryParse(command.getSecondWord(), out num))
                {
                    if (num > 0 && num < player.Inventory.Items.Count - 1)
                    {
                        i = player.Inventory.Items[num];
                    }
                }
                else
                {
                    for (int ii = player.Inventory.Items.Count - 1; ii >= 0; ii--)
                    {
                        if (player.Inventory.Items[ii].Name == command.getSecondWord())
                        {
                            i = player.Inventory.Items[ii];
                            break;
                        }
                    }
                }
                break;
            }

            if (i == null)
            {
                Console.WriteLine("No item found on index, name or slot!");
                return;
            }

            else
            {
                if (command.hasThirdWord())
                {
                    if (player.CurrentRoom.getExit(command.getThirdWord()) != null)
                    {
                        if (i.use(player.CurrentRoom.getExit(command.getThirdWord())))
                        {
                            destroyItem(command.getSecondWord());
                        }
                    }
                    else
                    {
                        Console.WriteLine(GeneralDataLibrary.Note() + "That exit doesn't exist!");
                    }
                }
                else
                {
                    if (i.use(player))
                    {
                        destroyItem(command.getSecondWord());
                    }
                }
            }
        }