Ejemplo n.º 1
0
        private void btnUsePotion_Click(object sender, EventArgs e)
        {
            // Get the currently selected potion from the combobox
            HealingPotion potion = (HealingPotion)cboPotions.SelectedItem;

            // Add healing amount to the player's current Meat Left
            _player.CurrentMeatLeft = (_player.CurrentMeatLeft + potion.AmountToHeal);

            // CurrentMeatLeft cannot exceed player's MaximumMeatLeft
            if (_player.CurrentMeatLeft > _player.MaximumMeatLeft)
            {
                _player.CurrentMeatLeft = _player.MaximumMeatLeft;
            }

            // Remove the potion from the player's inventory
            foreach (InventoryItem ii in _player.Inventory)
            {
                if (ii.Details.ID == potion.ID)
                {
                    ii.Quantity--;
                    break;
                }
            }

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

            // Monster gets their turn to attack

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

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

            // Substract damage from player
            _player.CurrentMeatLeft -= damageToPlayer;

            if (_player.CurrentMeatLeft <= 0)
            {
                // Display message
                rtbMessages.Text += "The " + _currentMonster.Name + " killed you " + Environment.NewLine;

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

            //Refresh player data in UI
            lblMeatLeft.Text = _player.CurrentMeatLeft.ToString();
            UpdateInventoryListUI();
            UpdatePotionListUI();
        }
Ejemplo n.º 2
0
        public Adventure()
        {
            InitializeComponent();
            _player = new Player(10, 10, 20, 0, 1);
            MoveTo(World.LocationByID(World.LOCATION_ID_HOME));
            _player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_RUSTY_SWORD), 1));

            lblHitPoints.Text  = _player.CurrHitPoints.ToString();
            lblGold.Text       = _player.Gold.ToString();
            lblExperience.Text = _player.XpPoints.ToString();
            lblLevel.Text      = _player.Level.ToString();
        }
Ejemplo n.º 3
0
        public Adventure()
        {
            InitializeComponent();

            _player = new Player(10, 10, 20, 0, 1);
            MoveTo(World.LocationByID(World.LOCATION_ID_HOME));
            _player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_RUSTY_SWORD), 1));

            lblMeatLeft.Text = _player.CurrentMeatLeft.ToString();
            lblCoins.Text    = _player.Coins.ToString();
            lblEXP.Text      = _player.EXPPoints.ToString();
            lblLevel.Text    = _player.Level.ToString();
        }
Ejemplo n.º 4
0
        private void btnUsePotion_Click(object sender, EventArgs e)
        {
            HealingPotion potion = (HealingPotion)cbPotions.SelectedItem;

            _player.CurrHitPoints = (_player.CurrHitPoints + potion.AmountToHeal);

            if (_player.CurrHitPoints > _player.MaxHitPoints)
            {
                _player.CurrHitPoints = _player.MaxHitPoints;
            }

            foreach (InventoryItem inventoryItem in _player.Inventory)
            {
                if (inventoryItem.Details.ID == potion.ID)
                {
                    inventoryItem.Amount--;
                    break;
                }
            }

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

            int damageToPlayer = RandomGenerator.NumberBetween(0, _currentMonster.MaxDamage);

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

            _player.CurrHitPoints -= damageToPlayer;

            lblHitPoints.Text = _player.CurrHitPoints.ToString();

            if (_player.CurrHitPoints <= 0)
            {
                rtbMessages.Text += "The " + _currentMonster.Name + " killed you." + Environment.NewLine;
                MoveTo(World.LocationByID(World.LOCATION_ID_HOME));
            }

            lblHitPoints.Text = _player.CurrHitPoints.ToString();

            UpdateInventoryListInUI();
            UpdatePotionListInUI();
        }
Ejemplo n.º 5
0
        private void btnUseWeapon_Click(object sender, EventArgs e)
        {
            Weapon currentWeapon = (Weapon)cboWeapons.SelectedItem;

            int damageToMonster = RandomNumberGenerator.NumberBetween(currentWeapon.MinimumDamage,
                                                                      currentWeapon.MaximumDamage);

            _currentMonster.CurrentMeatLeft -= damageToMonster;

            // Display message
            rtbMessages.Text += "You hit the " + _currentMonster.Name + " for " + damageToMonster.ToString()
                                + " points." + Environment.NewLine;

            // Check if the monster is dead
            if (_currentMonster.CurrentMeatLeft <= 0)
            {
                // Monster is Dead
                rtbMessages.Text += Environment.NewLine;
                rtbMessages.Text += "You defeated the" + _currentMonster.Name + Environment.NewLine;

                // Gve player experience points for killing the monster
                _player.EXPPoints += _currentMonster.RewardEXPPoints;
                rtbMessages.Text  += "You receive " + _currentMonster.RewardEXPPoints.ToString() +
                                     " experience points" + Environment.NewLine;

                // Give player coins for killing the monster
                _player.Coins    += _currentMonster.RewardCoins;
                rtbMessages.Text += "You receive" + _currentMonster.RewardCoins.ToString() +
                                    " coins." + Environment.NewLine;

                // Get random loot item from the monster
                List <InventoryItem> lootedItems = new List <InventoryItem>();

                // Add items to the lootedItems list, comparing a random number to the drop percentage
                foreach (LootItem lootItem in _currentMonster.LootTable)
                {
                    if (RandomNumberGenerator.NumberBetween(1, 100) <= lootItem.DropPercentage)
                    {
                        lootedItems.Add(new InventoryItem(lootItem.Details, 1));
                    }
                }

                // If no items were randomly selected, then add the default loot item(s).
                if (lootedItems.Count == 0)
                {
                    foreach (LootItem lootItem in _currentMonster.LootTable)
                    {
                        if (lootItem.IsDefaultItem)
                        {
                            lootedItems.Add(new InventoryItem(lootItem.Details, 1));
                        }
                    }
                }

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

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

                // Refresh player information and inventory controls
                lblMeatLeft.Text = _player.CurrentMeatLeft.ToString();
                lblCoins.Text    = _player.Coins.ToString();
                lblEXP.Text      = _player.EXPPoints.ToString();
                lblLevel.Text    = _player.Level.ToString();

                UpdateInventoryListUI();
                UpdatePotionListUI();
                UpdateWeaponListUI();

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

                // Move plaer 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 = RandomNumberGenerator.NumberBetween(0, _currentMonster.MaximumDamage);

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

                // Substract damage from player
                _player.CurrentMeatLeft -= damageToPlayer;

                // Refresh player data in UI
                lblMeatLeft.Text = _player.CurrentMeatLeft.ToString();

                if (_player.CurrentMeatLeft <= 0)
                {
                    // Display message
                    rtbMessages.Text += "The " + _currentMonster.Name + " killed you " + Environment.NewLine;

                    // Move player to "Home"
                    MoveTo(World.LocationByID(World.LOCATION_ID_HOME));
                }
            }
        }
Ejemplo n.º 6
0
        private void btnUseWeapon_Click(object sender, EventArgs e)
        {
            Weapon currentWeapon = (Weapon)cbWeapons.SelectedItem;

            int damageToMonster = RandomGenerator.NumberBetween(currentWeapon.MinDamage, currentWeapon.MaxDamage);

            _currentMonster.CurrHitPoints -= damageToMonster;

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

            if (_currentMonster.CurrHitPoints <= 0)
            {
                rtbMessages.Text += Environment.NewLine;
                rtbMessages.Text += "You defeated the " + _currentMonster.Name + Environment.NewLine;

                _player.XpPoints += _currentMonster.RewardXp;
                rtbMessages.Text += "You receive " + _currentMonster.RewardXp.ToString() + " experience points" +
                                    Environment.NewLine;

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

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

                foreach (LootItem lootItem in _currentMonster.LootTable)
                {
                    if (RandomGenerator.NumberBetween(1, 100) <= lootItem.DropPercentage)
                    {
                        lootedItems.Add(new InventoryItem(lootItem.Details, 1));
                    }
                }

                if (lootedItems.Count == 0)
                {
                    foreach (LootItem lootItem in _currentMonster.LootTable)
                    {
                        if (lootItem.isDefaultItem)
                        {
                            lootedItems.Add(new InventoryItem(lootItem.Details, 1));
                        }
                    }
                }

                foreach (InventoryItem inventoryItem in lootedItems)
                {
                    _player.AddItemToInventory(inventoryItem.Details);

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

                lblHitPoints.Text  = _player.CurrHitPoints.ToString();
                lblGold.Text       = _player.Gold.ToString();
                lblExperience.Text = _player.XpPoints.ToString();
                lblLevel.Text      = _player.Level.ToString();

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

                rtbMessages.Text += Environment.NewLine;

                MoveTo(_player.CurrentLocation);
            }
            else
            {
                int damageToPlayer = RandomGenerator.NumberBetween(0, _currentMonster.MaxDamage);

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

                _player.CurrHitPoints -= damageToPlayer;

                lblHitPoints.Text = _player.CurrHitPoints.ToString();

                if (_player.CurrHitPoints <= 0)
                {
                    rtbMessages.Text += "The " + _currentMonster.Name + " killed you." + Environment.NewLine;
                    MoveTo(World.LocationByID(World.LOCATION_ID_HOME));
                }
            }
        }