MainWindow.axaml.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Avalonia.Controls;
  2. using Avalonia.Interactivity;
  3. using System;
  4. namespace _01_02_MDK
  5. {
  6. public partial class MainWindow : Window
  7. {
  8. public MainWindow()
  9. {
  10. InitializeComponent();
  11. }
  12. enum Triangles
  13. {
  14. Isosceles, //Ðàâíîáåäðåííûé
  15. Equilateral, //Ðàâíîñòîðîííèé
  16. Versatile, //Ðàçíîñòîðîííèé
  17. NotExist //Íå ñóùåñòâóåò
  18. }
  19. private void pressedButton_Click(object sender, RoutedEventArgs e)
  20. {
  21. try {
  22. var a = Convert.ToInt32(firstSide.Text);
  23. var b = Convert.ToInt32(secondSide.Text);
  24. var c = Convert.ToInt32(thirdSide.Text);
  25. var triangleType = DetermineTypeOfTriangle(a, b, c);
  26. typeOfTriangle.Text = FromEnumToString(triangleType);
  27. }
  28. catch (FormatException)
  29. {
  30. typeOfTriangle.Text = "Ââåä¸ííûå çíà÷åíèÿ íåêîððåêòíû. Ïîïðîáóéòå åù¸ ðàç!";
  31. }
  32. catch (Exception ex) {
  33. typeOfTriangle.Text= ex.Message;
  34. }
  35. }
  36. static string FromEnumToString(Triangles triangle)
  37. {
  38. return new[] { "Ðàâíîáåäðåííûé", "Ðàâíîñòîðîííèé", "Ðàçíîñòîðîííèé", "Íå ñóùåñòâóåò" }[(int)triangle];
  39. }
  40. static Triangles DetermineTypeOfTriangle(int a, int b, int c)
  41. {
  42. if (a + b > c && a + c > b && b + c > a)
  43. {
  44. if (a == b || b == c || c == a)
  45. {
  46. if (a == b && b == c)
  47. return Triangles.Equilateral;
  48. return Triangles.Isosceles;
  49. }
  50. return Triangles.Versatile;
  51. }
  52. return Triangles.NotExist;
  53. }
  54. }
  55. }