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 hit points _player.CurrentHP = (_player.CurrentHP + potion.AmountToHeal); // CurrentHitPoints cannot exceed player's MaximumHitPoints if (_player.CurrentHP > _player.MaxHP) { _player.CurrentHP = _player.MaxHP; } // Remove the potion from the player's inventory foreach (InventoryItems 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.MaxDamage); // Display message rtbMessages.Text += "The " + _currentMonster.Name + " did " + damageToPlayer.ToString() + " points of damage." + Environment.NewLine; // Subtract damage from player _player.CurrentHP -= damageToPlayer; if (_player.CurrentHP <= 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 lblHitPoints.Text = _player.CurrentHP.ToString(); UpdateInventoryListInUI(); UpdatePotionListInUI(); }
private void btnPotion_Click(object sender, System.EventArgs e) { HealingPotion potion = (HealingPotion)cboPotions.SelectedItem; _player.CurrentHitPoints = (_player.CurrentHitPoints + potion.AmountToHeal); if (_player.CurrentHitPoints > _player.MaximumHitPoints) { _player.CurrentHitPoints = _player.MaximumHitPoints; } foreach (InventoryItem ii in _player.Inventory) { if (ii.Details.ID == potion.ID) { ii.Quantity--; break; } } rtbMessages.Text += $"You drink a {potion.Name} {Environment.NewLine}"; int damageToPlayer = RandomNumberGenerator.NumberBetween(0, _currentMonster.MaximumDamage); rtbMessages.Text += $"The {_currentMonster.Name} did {damageToPlayer} points of damage to you! {Environment.NewLine}"; _player.CurrentHitPoints -= damageToPlayer; if (_player.CurrentHitPoints <= 0) { rtbMessages.Text += $"The {_currentMonster.Name} killed you! {Environment.NewLine}"; MoveTo(World.LocationById(World.LOCATION_ID_HOME)); } LblHitPoints.Text = _player.CurrentHitPoints.ToString(); UpdateInventoryListInUI(); UpdatePotionListInUI(); }