38 lines
No EOL
1.1 KiB
C#
38 lines
No EOL
1.1 KiB
C#
public class Player
|
|
{
|
|
public string Name { get; set; }
|
|
public List<Item> Inventory { get; set; }
|
|
public int MaxHealth { get; set; }
|
|
public int CurrentHealth { get; set; }
|
|
public int MaxMPoints { get; set; }
|
|
public int CurrentMPoints { get; set; }
|
|
|
|
public Player(string name, List<Item> inventory, int maxhealth, int currenthealth, int maxmpoints, int currentmpoints)
|
|
{
|
|
Name = name;
|
|
Inventory = inventory;
|
|
MaxHealth = maxhealth;
|
|
CurrentHealth = currenthealth;
|
|
MaxMPoints = maxmpoints;
|
|
CurrentMPoints = currentmpoints;
|
|
}
|
|
|
|
//Returns the players inventory in a Dictionary.
|
|
public Dictionary<string, int> RetrieveInventory()
|
|
{
|
|
return Inventory
|
|
.GroupBy(item => item.Name)
|
|
.ToDictionary(group => group.Key, group => group.Count());
|
|
}
|
|
|
|
//For using a healing item. Doesn't allow you to overheal.
|
|
public void UseHealingItem(HealingItem item)
|
|
{
|
|
if ((CurrentHealth + item.HealingAmount) > MaxHealth)
|
|
{
|
|
CurrentHealth = MaxHealth;
|
|
} else {
|
|
CurrentHealth += item.HealingAmount;
|
|
}
|
|
}
|
|
} |