Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace Attribute_System
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public int AvailablePoints = 35;
- public int DefaultAttributeValue = 8;
- public int MaximumAttributeValue = 18;
- public MainWindow()
- {
- InitializeComponent();
- Reset();
- }
- public int CalculateNextCost(int currentValue)
- {
- switch (currentValue)
- {
- case 7:
- case 8:
- case 9:
- case 10:
- case 11:
- case 12:
- case 13:
- return 1;
- case 14:
- case 15:
- return 2;
- case 16:
- case 17:
- case 18:
- return 3;
- default:
- throw new Exception("No value for : " + currentValue);
- }
- }
- public int CalculatePreviousCost(int currentValue)
- {
- return CalculateNextCost(currentValue - 1);
- }
- public void Reset()
- {
- AvailablePointsDisplayTextBox.Text = AvailablePoints.ToString();
- StrengthDisplayTextBox.Text = DefaultAttributeValue.ToString();
- AgilityDisplayTextBox.Text = DefaultAttributeValue.ToString();
- DefenseDisplayTextBox.Text = DefaultAttributeValue.ToString();
- StaminaDisplayTextBox.Text = DefaultAttributeValue.ToString();
- IntellectDisplayTextBox.Text = DefaultAttributeValue.ToString();
- WisdomDisplayTextBox.Text = DefaultAttributeValue.ToString();
- LuckDisplayTextBox.Text = DefaultAttributeValue.ToString();
- }
- public int GetAvailablePoints()
- {
- return Int32.Parse(AvailablePointsDisplayTextBox.Text);
- }
- public void DecrementAttribute(TextBox textBox)
- {
- /**
- * Perform Minimum Validation Check
- */
- int currentAttributeScore = Int32.Parse(textBox.Text);
- int availablePoints = GetAvailablePoints();
- int cost = CalculatePreviousCost(currentAttributeScore);
- if (currentAttributeScore <= DefaultAttributeValue)
- {
- return;
- }
- this.AvailablePointsDisplayTextBox.Text = (availablePoints + cost).ToString();
- textBox.Text = (currentAttributeScore - 1).ToString();
- }
- public void IncrementAttribute(TextBox textBox)
- {
- /**
- * Perform Maximum Validation Check
- */
- int currentAttributeScore = Int32.Parse(textBox.Text);
- int availablePoints = GetAvailablePoints();
- int cost = CalculateNextCost(currentAttributeScore);
- if (currentAttributeScore == MaximumAttributeValue)
- {
- return;
- }
- /**
- * Perform sanity check
- */
- if (cost > availablePoints)
- {
- return;
- }
- this.AvailablePointsDisplayTextBox.Text = (availablePoints - cost).ToString();
- textBox.Text = (currentAttributeScore + 1).ToString();
- }
- private void Reset_ButtonClick(object sender, RoutedEventArgs e)
- {
- Reset();
- }
- private void Strength_Minus_ButtonClick(object sender, RoutedEventArgs e)
- {
- DecrementAttribute(StrengthDisplayTextBox);
- }
- private void Strength_Plus_ButtonClick(object sender, RoutedEventArgs e)
- {
- IncrementAttribute(StrengthDisplayTextBox);
- }
- private void Agility_Minus_ButtonClick(object sender, RoutedEventArgs e)
- {
- DecrementAttribute(AgilityDisplayTextBox);
- }
- private void Agility_Plus_ButtonClick(object sender, RoutedEventArgs e)
- {
- IncrementAttribute(AgilityDisplayTextBox);
- }
- private void Defense_Minus_ButtonClick(object sender, RoutedEventArgs e)
- {
- DecrementAttribute(DefenseDisplayTextBox);
- }
- private void Defense_Plus_ButtonClick(object sender, RoutedEventArgs e)
- {
- IncrementAttribute(DefenseDisplayTextBox);
- }
- private void Stamina_Minus_ButtonClick(object sender, RoutedEventArgs e)
- {
- DecrementAttribute(StaminaDisplayTextBox);
- }
- private void Stamina_Plus_ButtonClick(object sender, RoutedEventArgs e)
- {
- IncrementAttribute(StaminaDisplayTextBox);
- }
- private void Intellect_Minus_ButtonClick(object sender, RoutedEventArgs e)
- {
- DecrementAttribute(IntellectDisplayTextBox);
- }
- private void Intellect_Plus_ButtonClick(object sender, RoutedEventArgs e)
- {
- IncrementAttribute(IntellectDisplayTextBox);
- }
- private void Wisdom_Minus_ButtonClick(object sender, RoutedEventArgs e)
- {
- DecrementAttribute(WisdomDisplayTextBox);
- }
- private void Wisdom_Plus_ButtonClick(object sender, RoutedEventArgs e)
- {
- IncrementAttribute(WisdomDisplayTextBox);
- }
- private void Luck_Minus_ButtonClick(object sender, RoutedEventArgs e)
- {
- DecrementAttribute(LuckDisplayTextBox);
- }
- private void Luck_Plus_ButtonClick(object sender, RoutedEventArgs e)
- {
- IncrementAttribute(LuckDisplayTextBox);
- }
- private void GenerateButton_Click(object sender, RoutedEventArgs e)
- {
- Reset();
- Random random = new Random();
- int[] warriorDistributionTable = new int[] { 0, 0, 0, 1, 2, 2, 2, 3, 3, 3, 4, 5, 6 };
- int[] useDistributionTable = warriorDistributionTable;
- Dictionary<int, TextBox> attributeMap = new Dictionary<int, TextBox>
- {
- { 0, StrengthDisplayTextBox },
- { 1, AgilityDisplayTextBox },
- { 2, DefenseDisplayTextBox },
- { 3, StaminaDisplayTextBox },
- { 4, IntellectDisplayTextBox },
- { 5, WisdomDisplayTextBox },
- { 6, LuckDisplayTextBox }
- };
- while (GetAvailablePoints() != 0)
- {
- if(useDistributionTable != null)
- {
- IncrementAttribute(attributeMap[useDistributionTable[random.Next(useDistributionTable.Length)]]);
- }
- else
- {
- IncrementAttribute(attributeMap[random.Next(7)]);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement