예제 #1
0
        public void LootMonster(Monster deadMonster)
        {
            if (deadMonster == null)
            {
                throw new ArgumentNullException("Monster cannot be null");
            }
            if (deadMonster.Health > 0)
            {
                throw new ArgumentException("Cannot loot a live monster!");
            }

            Bag.AddRange(deadMonster.DropLoot());
        }
예제 #2
0
        private static void Fight(Player player, bool monsterStarts)
        {
            Actor opponent      = Program.theWorld[player.Locale].Resident;
            bool  stillFighting = true;

            if (monsterStarts)
            {
                opponent.Attack(player);
                WriteLine($"The {opponent.Name} {opponent.Weapon.AttackFlavor} with their {opponent.Weapon}! You now have {player.Health} health points.");
                if (player.Health <= 0)
                {
                    stillFighting = false;
                    WriteLine("\nOh no! You are mortally wounded!  You are dead...");
                }
            }

            while (stillFighting)
            {
                player.Attack(opponent);
                WriteLine($"{player.Name} {player.Weapon.AttackFlavor} the {opponent.Name} with {player.Weapon}! The {opponent.Name} now has {opponent.Health} health points.");
                if (opponent.Health == 0)
                {
                    WriteLine();
                    WriteLine("YOU ARE VICTORIOUS!!!");
                    if (opponent is Monster)
                    {
                        Monster     monster = (Monster)opponent;
                        List <Item> myLoot  = monster.DropLoot();
                        foreach (Item item in myLoot)
                        {
                            player.AddItem(item);
                            WriteLine($"You find a {item} on the monster's body and you add it to your bag.");
                        }
                    }
                    if (opponent.Weapon.Damage > player.Weapon.Damage)
                    {
                        WriteLine($"You take the {opponent.Name}'s {opponent.Weapon} and equip it");
                        player.Equip(opponent.Weapon);
                        opponent.Equip(GameItems.Hands);
                    }
                    stillFighting = false;
                }

                if (stillFighting)
                {
                    opponent.Attack(player);
                    WriteLine($"The {opponent.Name} attacks you with their {opponent.Weapon}! You now have {player.Health} health points.");
                    if (player.Health == 0)
                    {
                        WriteLine("\nOh no! You are mortally wounded! You are dead...");
                        stillFighting = false;
                    }
                }

                WriteLine();
                if (stillFighting)
                {
                    string continueFight = "";
                    bool   validResponse = false;
                    while (!validResponse)
                    {
                        Write("Do you wish to continue fighting (y/n)? ");
                        continueFight = ReadLine();
                        if (continueFight == "")
                        {
                            continue;
                        }
                        if (Char.ToLower(continueFight[0]) == 'n')
                        {
                            stillFighting = false;
                            validResponse = true;
                            WriteLine("You beat a hasty retreat and live to fight another day.");
                        }
                        else if (Char.ToLower(continueFight[0]) == 'y')
                        {
                            validResponse = true;
                        }
                    }
                }
            }
        }