Exemplo n.º 1
0
        private void btnUsePotion_Click(object sender, EventArgs e)
        {
            //Get elixir
            Elixir potion = (Elixir)comboBoxPotions.SelectedItem;

            player.CurrentPoints = (player.CurrentPoints + potion.AmountToHeal);

            if (player.CurrentPoints > player.MaximumPoints)
            {
                player.CurrentPoints = player.MaximumPoints;
            }

            //Remove elixir inventory
            foreach (Inventory item in player.Inventory)
            {
                if (item.Item.ID == potion.ID)
                {
                    item.Quantity--;
                    break;
                }
            }

            //Display message
            rtbMessages.Text += "You drink a " + potion.Name + Environment.NewLine;

            //Gremlin attacks

            int damageToPlayer = RandomNumGenerator.NumberBetween(0, currentMonster.MaximumDamage);

            rtbMessages.Text += "The " + currentMonster.Name + " did " + damageToPlayer.ToString() + " points of damage." + Environment.NewLine;

            player.CurrentPoints -= damageToPlayer;

            if (player.CurrentPoints <= 0)
            {
                rtbMessages.Text += "The " + currentMonster.Name + " killed you." + Environment.NewLine;

                //Move player back home
                MoveTo(Swamp.LocationByID(Swamp.LOCATION_ID_HOME));
            }

            //Refresh data
            lblPoints.Text = player.CurrentPoints.ToString();
            UpdateInventoryListInUI();
            UpdatePotionListInUI();
        }
Exemplo n.º 2
0
        private void btnUseWeapon_Click(object sender, EventArgs e)
        {
            Weapon currentWeapon   = (Weapon)comboBoxWeapons.SelectedItem;
            int    damageToMonster = RandomNumGenerator.NumberBetween(currentWeapon.MinimumDamage, currentWeapon.MaximumDamage);

            currentMonster.CurrentPoints -= damageToMonster;
            rtbMessages.Text             += "You hit the " + currentMonster.Name + " for " + damageToMonster.ToString() + " points." + Environment.NewLine;

            if (currentMonster.CurrentPoints <= 0)
            {
                //Gremlin is dead
                rtbMessages.Text += Environment.NewLine;
                rtbMessages.Text += "You defeated the " + currentMonster.Name + Environment.NewLine;

                player.ExperiencePoints += currentMonster.RewardExperiencePoints;
                rtbMessages.Text        += "You receive " + currentMonster.RewardExperiencePoints.ToString() + " experience points" + Environment.NewLine;

                player.Gold      += currentMonster.RewardGold;
                rtbMessages.Text += "You receive " + currentMonster.RewardGold.ToString() + " gold" + Environment.NewLine;

                List <Inventory> lootedItems = new List <Inventory>();

                //Add items to the lootedItems list, comparing a random number to the drop percentage
                foreach (Treasure lootItem in currentMonster.TreasureChest)
                {
                    if (RandomNumGenerator.NumberBetween(1, 100) <= lootItem.DropPercentage)
                    {
                        lootedItems.Add(new Inventory(lootItem.Item, 1));
                    }
                }

                //If no items were randomly selected, then add the default loot item(s).
                if (lootedItems.Count == 0)
                {
                    foreach (Treasure lootItem in currentMonster.TreasureChest)
                    {
                        if (lootItem.IsDefaultItem)
                        {
                            lootedItems.Add(new Inventory(lootItem.Item, 1));
                        }
                    }
                }

                // Add the looted items to the player's inventory
                foreach (Inventory inventoryItem in lootedItems)
                {
                    player.AddItemToInventory(inventoryItem.Item);

                    if (inventoryItem.Quantity == 1)
                    {
                        rtbMessages.Text += "You loot " + inventoryItem.Quantity.ToString() + " " + inventoryItem.Item.Name + Environment.NewLine;
                    }
                    else
                    {
                        rtbMessages.Text += "You loot " + inventoryItem.Quantity.ToString() + " " + inventoryItem.Item.NamePlural + Environment.NewLine;
                    }
                }

                // Refresh player information and inventory controls
                lblPoints.Text     = player.CurrentPoints.ToString();
                lblGold.Text       = player.Gold.ToString();
                lblExperience.Text = player.ExperiencePoints.ToString();
                lblLevel.Text      = player.Level.ToString();

                UpdateInventoryListInUI();
                UpdateWeaponListInUI();
                UpdatePotionListInUI();

                // Add a blank line to the messages box, just for appearance.
                rtbMessages.Text += Environment.NewLine;

                //Move player to current location (to heal player and create a new monster to fight)
                MoveTo(player.CurrentLocation);
            }
            else
            {
                // Monster is still alive

                // Determine the amount of damage the monster does to the player
                int damageToPlayer = RandomNumGenerator.NumberBetween(0, currentMonster.MaximumDamage);

                // Display message
                rtbMessages.Text += "The " + currentMonster.Name + " did " + damageToPlayer.ToString() + " points of damage." + Environment.NewLine;

                // Subtract damage from player
                player.CurrentPoints -= damageToPlayer;

                // Refresh player data in UI
                lblPoints.Text = player.CurrentPoints.ToString();

                if (player.CurrentPoints <= 0)
                {
                    // Display message
                    rtbMessages.Text += "The " + currentMonster.Name + " killed you." + Environment.NewLine;

                    // Move player to "Home"
                    MoveTo(Swamp.LocationByID(Swamp.LOCATION_ID_HOME));
                }
            }
        }