MainWindow.xaml.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Input;
  4. using System.Windows.Media.Imaging;
  5. namespace Clicker_2._0
  6. {
  7. /// <summary>
  8. /// Логика взаимодействия для MainWindow.xaml
  9. /// </summary>
  10. public partial class MainWindow : Window
  11. {
  12. long point = 0;
  13. static int click = 1;
  14. double sol_b1 = 10 + 10 * (30 + click * 0.2);
  15. double sol_b2 = 20 + 20 * (60 + click * 0.4);
  16. double sol_b3 = 30 + 30 * (90 + click * 0.6);
  17. double sol_b4 = 40 + 40 * (1200 + click * 0.8);
  18. public MainWindow()
  19. {
  20. InitializeComponent();
  21. }
  22. public void Update()
  23. {
  24. poi.Text = "Points: " + point; // Вывод Points в первый label
  25. cli.Text = "Points for click: " + click; // Вывод Points per click во второй label
  26. b1.Content = (sol_b1).ToString(); //
  27. b2.Content = (sol_b2).ToString(); // Вывод цены Upgrade для Points per click на кнопке
  28. b3.Content = (sol_b3).ToString(); //
  29. b4.Content = (sol_b4).ToString(); //
  30. }
  31. // ClickImg
  32. private void Image_MouseDown(object sender, MouseButtonEventArgs e)
  33. {
  34. point = IncreasePoint(point, click);
  35. Update();
  36. }
  37. public long IncreasePoint(long point, int click)
  38. {
  39. return point += click;
  40. }
  41. // UpgradeBtn1
  42. private void b1_Click(object sender, RoutedEventArgs e)
  43. {
  44. if (IsUpgraded(point, 1))
  45. {
  46. point -= Convert.ToInt64(Math.Round(sol_b1));
  47. click = IncreaseClick(click, 1);
  48. Update();
  49. ChangeImage();
  50. }
  51. }
  52. // UpgradeBtn2
  53. private void b2_Click(object sender, RoutedEventArgs e)
  54. {
  55. if (IsUpgraded(point, 2))
  56. {
  57. point -= Convert.ToInt64(Math.Round(sol_b2));
  58. click = IncreaseClick(click, 2);
  59. Update();
  60. ChangeImage();
  61. }
  62. }
  63. // UpgradeBtn3
  64. private void b3_Click(object sender, RoutedEventArgs e)
  65. {
  66. if (IsUpgraded(point, 3))
  67. {
  68. point -= Convert.ToInt64(Math.Round(sol_b3));
  69. click = IncreaseClick(click, 3);
  70. Update();
  71. ChangeImage();
  72. }
  73. }
  74. // UpgradeBtn4
  75. private void b4_Click(object sender, RoutedEventArgs e)
  76. {
  77. if (IsUpgraded(point, 4))
  78. {
  79. point = DecreasePoint(point, 4);
  80. click = IncreaseClick(click, 4);
  81. Update();
  82. ChangeImage();
  83. }
  84. }
  85. public long DecreasePoint(long point, int btnLvl)
  86. {
  87. if (btnLvl == 1)
  88. {
  89. return point - Convert.ToInt64(Math.Round(sol_b1));
  90. }
  91. else if (btnLvl == 2)
  92. {
  93. return point - Convert.ToInt64(Math.Round(sol_b2));
  94. }
  95. else if (btnLvl == 3)
  96. {
  97. return point - Convert.ToInt64(Math.Round(sol_b3));
  98. }
  99. else
  100. {
  101. return point - Convert.ToInt64(Math.Round(sol_b4));
  102. }
  103. }
  104. public int IncreaseClick(int click, int btnLvl)
  105. {
  106. if (btnLvl == 1)
  107. {
  108. return click + 3;
  109. }
  110. else if (btnLvl == 2)
  111. {
  112. return click + 10;
  113. }
  114. else if (btnLvl == 3)
  115. {
  116. return click + 30;
  117. }
  118. else
  119. {
  120. return click + 50;
  121. }
  122. }
  123. public bool IsUpgraded(long point, int btnLvl)
  124. {
  125. if (btnLvl == 1)
  126. {
  127. if (point >= (sol_b1))
  128. {
  129. return true;
  130. }
  131. return false;
  132. }
  133. else if (btnLvl == 2)
  134. {
  135. if (point >= (sol_b2))
  136. {
  137. return true;
  138. }
  139. return false;
  140. }
  141. else if (btnLvl == 3)
  142. {
  143. if (point >= (sol_b3))
  144. {
  145. return true;
  146. }
  147. return false;
  148. }
  149. else
  150. {
  151. if (point >= (sol_b4))
  152. {
  153. return true;
  154. }
  155. return false;
  156. }
  157. }
  158. private void ChangeImage()
  159. {
  160. if (click > 50)
  161. {
  162. imgYatoro.Source = BitmapFrame.Create(new Uri(@"Images/YatoroWin.jpg"));
  163. }
  164. else if (click > 30)
  165. {
  166. imgYatoro.Source = BitmapFrame.Create(new Uri(@"Images/Yatoro.jpg"));
  167. }
  168. else if (click > 10)
  169. {
  170. imgYatoro.Source = BitmapFrame.Create(new Uri(@"Images/YatoroDnw.jpg"));
  171. }
  172. }
  173. private void Button_Click(object sender, RoutedEventArgs e)
  174. {
  175. Close();
  176. }
  177. }
  178. }