Ejemplo n.º 1
0
        /// <summary>
        /// Open New Room.
        /// </summary>
        public void OpenRoom()
        {
            if (!CanOpenRoom())
            {
                return;
            }

            OpenedRooms++;

            // Choose Room Type.
            var number = Random.Next(100);

            if (number < 40)
            {
                if (number < 10 && DungeonLevel >= 5)
                {
                    RoomType = RoomType.Dragon;
                }
                else
                {
                    RoomType = RoomType.Loot;
                }
            }
            else if (number < 90)
            {
                RoomType = RoomType.Trap;
            }
            else
            {
                RoomType = RoomType.Empty;
            }

            Enemy.Items.Clear();
            Enemy.Money = 0;

            switch (RoomType)
            {
            case RoomType.Loot:
                Enemy.Money = Random.Next(30, 60);
                var lootItems = LootGenerator.Generate(Random.Next(2, Enemy.InventorySize));
                Enemy.Items      = lootItems.ToList();
                RoomDescription  = "Loot! Lucky :). Take anything you want, as long as you have space for it or need of it!";
                ExperienceGained = Random.Next(15, 30) * DungeonLevel;
                break;

            case RoomType.Trap:
                var healthLost = Random.Next((int)Math.Floor((double)Player.MaxHealth / 5)) + (5 * DungeonLevel);
                if (Player.Health - healthLost <= 0)
                {
                    Player.Money  = Player.Money - healthLost < 0 ? 0 : Player.Money - healthLost;
                    Player.Health = Player.MaxHealth;
                    ChangeLocation(GameLocation.Village);

                    throw new Exception($"You Fainted in the Dungeon! Thankfully, another Adventurer saved you, at the small cost of {healthLost}");
                }
                Player.Health   -= healthLost;
                RoomDescription  = $"a Trap! Ouch! Be wary of these dungeons, Hero, they can be treacherous! You Lost {healthLost} Health!";
                ExperienceGained = Random.Next(25, 40) * DungeonLevel;
                break;

            case RoomType.Dragon:
                GoalAchieved    = true;
                RoomDescription = "You found the Dragon!";
                ChangeLocation(GameLocation.Village);
                return;

            case RoomType.Empty:
                RoomDescription  = "an Empty Space... Sorry! Hopefully you will find more in the next room!";
                ExperienceGained = Random.Next(5, 15) * DungeonLevel;
                break;
            }

            Player.Experience += ExperienceGained;
        }