Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public enum AttributeType
- {
- Strength,
- Agility,
- Defense,
- Vitality,
- Intellect,
- Wisdom,
- Spirit
- }
- public class PointBuySystem
- {
- private const int MaxAttributeValue = 10;
- private const int TotalPoints = 21;
- private Dictionary<AttributeType, int> attributes = new Dictionary<AttributeType, int>()
- {
- { AttributeType.Strength, 1 },
- { AttributeType.Agility, 1 },
- { AttributeType.Defense, 1 },
- { AttributeType.Vitality, 1 },
- { AttributeType.Intellect, 1 },
- { AttributeType.Wisdom, 1 },
- { AttributeType.Spirit, 1 }
- };
- private int availablePoints = TotalPoints;
- public int GetAttributeValue(AttributeType attribute)
- {
- return attributes[attribute];
- }
- public int AvailablePoints { get { return availablePoints; } }
- public bool CanBuy(AttributeType attribute)
- {
- return availablePoints > 0 && attributes[attribute] < MaxAttributeValue;
- }
- public bool BuyAttribute(AttributeType attribute)
- {
- if (!CanBuy(attribute))
- {
- return false;
- }
- if (availablePoints >= (MaxAttributeValue - attributes[attribute]))
- {
- availablePoints -= (MaxAttributeValue - attributes[attribute]);
- attributes[attribute] = MaxAttributeValue;
- }
- else
- {
- attributes[attribute] += availablePoints;
- availablePoints = 0;
- }
- return true;
- }
- public bool SellAttribute(AttributeType attribute)
- {
- if (attributes[attribute] <= 1)
- {
- return false;
- }
- attributes[attribute]--;
- availablePoints += (MaxAttributeValue - attributes[attribute] + 1);
- return true;
- }
- public void Reset()
- {
- foreach (AttributeType attribute in Enum.GetValues(typeof(AttributeType)))
- {
- attributes[attribute] = 1;
- }
- availablePoints = TotalPoints;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement