Advertisement
Krythic

Attribute System Test

Nov 3rd, 2023
1,213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15.  
  16. namespace Attribute_System
  17. {
  18.  
  19.     /// <summary>
  20.     /// Interaction logic for MainWindow.xaml
  21.     /// </summary>
  22.     public partial class MainWindow : Window
  23.     {
  24.         public int AvailablePoints = 35;
  25.         public int DefaultAttributeValue = 8;
  26.         public int MaximumAttributeValue = 18;
  27.  
  28.  
  29.         public MainWindow()
  30.         {
  31.             InitializeComponent();
  32.             Reset();
  33.         }
  34.  
  35.         public int CalculateNextCost(int currentValue)
  36.         {
  37.             switch (currentValue)
  38.             {
  39.                 case 7:
  40.                 case 8:
  41.                 case 9:
  42.                 case 10:
  43.                 case 11:
  44.                 case 12:
  45.                 case 13:
  46.                     return 1;
  47.                 case 14:
  48.                 case 15:
  49.                     return 2;
  50.                 case 16:
  51.                 case 17:
  52.                 case 18:
  53.                     return 3;
  54.                 default:
  55.                     throw new Exception("No value for : " + currentValue);
  56.             }
  57.         }
  58.  
  59.         public int CalculatePreviousCost(int currentValue)
  60.         {
  61.             return CalculateNextCost(currentValue - 1);
  62.         }
  63.  
  64.         public void Reset()
  65.         {
  66.             AvailablePointsDisplayTextBox.Text = AvailablePoints.ToString();
  67.             StrengthDisplayTextBox.Text = DefaultAttributeValue.ToString();
  68.             AgilityDisplayTextBox.Text = DefaultAttributeValue.ToString();
  69.             DefenseDisplayTextBox.Text = DefaultAttributeValue.ToString();
  70.             StaminaDisplayTextBox.Text = DefaultAttributeValue.ToString();
  71.             IntellectDisplayTextBox.Text = DefaultAttributeValue.ToString();
  72.             WisdomDisplayTextBox.Text = DefaultAttributeValue.ToString();
  73.             LuckDisplayTextBox.Text = DefaultAttributeValue.ToString();
  74.         }
  75.  
  76.         public int GetAvailablePoints()
  77.         {
  78.             return Int32.Parse(AvailablePointsDisplayTextBox.Text);
  79.         }
  80.  
  81.         public void DecrementAttribute(TextBox textBox)
  82.         {
  83.             /**
  84.              * Perform Minimum Validation Check
  85.              */
  86.             int currentAttributeScore = Int32.Parse(textBox.Text);
  87.             int availablePoints = GetAvailablePoints();
  88.             int cost = CalculatePreviousCost(currentAttributeScore);
  89.             if (currentAttributeScore <= DefaultAttributeValue)
  90.             {
  91.                 return;
  92.             }
  93.             this.AvailablePointsDisplayTextBox.Text = (availablePoints + cost).ToString();
  94.             textBox.Text = (currentAttributeScore - 1).ToString();
  95.         }
  96.  
  97.         public void IncrementAttribute(TextBox textBox)
  98.         {
  99.             /**
  100.              * Perform Maximum Validation Check
  101.              */
  102.             int currentAttributeScore = Int32.Parse(textBox.Text);
  103.             int availablePoints = GetAvailablePoints();
  104.             int cost = CalculateNextCost(currentAttributeScore);
  105.             if (currentAttributeScore == MaximumAttributeValue)
  106.             {
  107.                 return;
  108.             }
  109.             /**
  110.              * Perform sanity check
  111.              */
  112.             if (cost > availablePoints)
  113.             {
  114.                 return;
  115.             }
  116.             this.AvailablePointsDisplayTextBox.Text = (availablePoints - cost).ToString();
  117.             textBox.Text = (currentAttributeScore + 1).ToString();
  118.         }
  119.  
  120.         private void Reset_ButtonClick(object sender, RoutedEventArgs e)
  121.         {
  122.             Reset();
  123.         }
  124.  
  125.         private void Strength_Minus_ButtonClick(object sender, RoutedEventArgs e)
  126.         {
  127.             DecrementAttribute(StrengthDisplayTextBox);
  128.         }
  129.  
  130.         private void Strength_Plus_ButtonClick(object sender, RoutedEventArgs e)
  131.         {
  132.             IncrementAttribute(StrengthDisplayTextBox);
  133.         }
  134.  
  135.         private void Agility_Minus_ButtonClick(object sender, RoutedEventArgs e)
  136.         {
  137.             DecrementAttribute(AgilityDisplayTextBox);
  138.         }
  139.  
  140.         private void Agility_Plus_ButtonClick(object sender, RoutedEventArgs e)
  141.         {
  142.             IncrementAttribute(AgilityDisplayTextBox);
  143.         }
  144.  
  145.         private void Defense_Minus_ButtonClick(object sender, RoutedEventArgs e)
  146.         {
  147.             DecrementAttribute(DefenseDisplayTextBox);
  148.         }
  149.  
  150.         private void Defense_Plus_ButtonClick(object sender, RoutedEventArgs e)
  151.         {
  152.             IncrementAttribute(DefenseDisplayTextBox);
  153.         }
  154.  
  155.         private void Stamina_Minus_ButtonClick(object sender, RoutedEventArgs e)
  156.         {
  157.             DecrementAttribute(StaminaDisplayTextBox);
  158.         }
  159.  
  160.         private void Stamina_Plus_ButtonClick(object sender, RoutedEventArgs e)
  161.         {
  162.             IncrementAttribute(StaminaDisplayTextBox);
  163.         }
  164.  
  165.         private void Intellect_Minus_ButtonClick(object sender, RoutedEventArgs e)
  166.         {
  167.             DecrementAttribute(IntellectDisplayTextBox);
  168.         }
  169.  
  170.         private void Intellect_Plus_ButtonClick(object sender, RoutedEventArgs e)
  171.         {
  172.             IncrementAttribute(IntellectDisplayTextBox);
  173.         }
  174.  
  175.         private void Wisdom_Minus_ButtonClick(object sender, RoutedEventArgs e)
  176.         {
  177.             DecrementAttribute(WisdomDisplayTextBox);
  178.         }
  179.  
  180.         private void Wisdom_Plus_ButtonClick(object sender, RoutedEventArgs e)
  181.         {
  182.             IncrementAttribute(WisdomDisplayTextBox);
  183.         }
  184.  
  185.         private void Luck_Minus_ButtonClick(object sender, RoutedEventArgs e)
  186.         {
  187.             DecrementAttribute(LuckDisplayTextBox);
  188.         }
  189.  
  190.         private void Luck_Plus_ButtonClick(object sender, RoutedEventArgs e)
  191.         {
  192.             IncrementAttribute(LuckDisplayTextBox);
  193.         }
  194.  
  195.         private void GenerateButton_Click(object sender, RoutedEventArgs e)
  196.         {
  197.             Reset();
  198.             Random random = new Random();
  199.             int[] warriorDistributionTable = new int[] { 0, 0, 0, 1, 2, 2, 2, 3, 3, 3, 4, 5, 6 };
  200.             int[] useDistributionTable = warriorDistributionTable;
  201.             Dictionary<int, TextBox> attributeMap = new Dictionary<int, TextBox>
  202.             {
  203.                 { 0, StrengthDisplayTextBox },
  204.                 { 1, AgilityDisplayTextBox },
  205.                 { 2, DefenseDisplayTextBox },
  206.                 { 3, StaminaDisplayTextBox },
  207.                 { 4, IntellectDisplayTextBox },
  208.                 { 5, WisdomDisplayTextBox },
  209.                 { 6, LuckDisplayTextBox }
  210.             };
  211.             while (GetAvailablePoints() != 0)
  212.             {
  213.                 if(useDistributionTable != null)
  214.                 {
  215.                     IncrementAttribute(attributeMap[useDistributionTable[random.Next(useDistributionTable.Length)]]);
  216.                 }
  217.                 else
  218.                 {
  219.                     IncrementAttribute(attributeMap[random.Next(7)]);
  220.                 }
  221.             }
  222.         }
  223.     }
  224. }
  225.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement