MainAnimalPage.xaml.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. using System.Windows.Threading;
  16. namespace TamagochiProject.Pages
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для MainAnimalPage.xaml
  20. /// </summary>
  21. public partial class MainAnimalPage : Page
  22. {
  23. public MainAnimalPage()
  24. {
  25. InitializeComponent();
  26. DataContext = Globals.PickAnimal;
  27. ImageAnimal.Width = Globals.Width;
  28. ImageAnimal.Height=Globals.Height;
  29. Globals.TimerHealth.Interval = TimeSpan.FromSeconds(15);
  30. Globals.TimerSatiety.Interval = TimeSpan.FromSeconds(10);
  31. Globals.TimerHappy.Interval = TimeSpan.FromSeconds(3);
  32. Globals.TimerHeight.Interval = TimeSpan.FromSeconds(3);
  33. Globals.TimerHealth.Tick += TimerHealth_Tick;
  34. Globals.TimerSatiety.Tick += TimeSatiety_Tick;
  35. Globals.TimerHappy.Tick += TimerHappy_Tick;
  36. Globals.TimerHeight.Tick += TimerHeight_Tick;
  37. Globals.TimerSatiety.Start();
  38. Globals.TimerHealth.Start();
  39. Globals.TimerHappy.Start();
  40. Globals.TimerHeight.Start();
  41. }
  42. private void btnPlay_Click(object sender, RoutedEventArgs e)
  43. {
  44. Globals.TimerSatiety.Stop();
  45. Globals.TimerHealth.Stop();
  46. Globals.TimerHappy.Stop();
  47. Globals.TimerHeight.Stop();
  48. Globals.TimerHealth.Tick -= TimerHealth_Tick;
  49. Globals.TimerSatiety.Tick -= TimeSatiety_Tick;
  50. Globals.TimerHappy.Tick -= TimerHappy_Tick;
  51. Globals.TimerHeight.Tick -= TimerHeight_Tick;
  52. Globals.Frame.Navigate(new Pages.PlayAnimalPage());
  53. }
  54. private void btnHeal_Click(object sender, RoutedEventArgs e)
  55. {
  56. Globals.TimerSatiety.Stop();
  57. Globals.TimerHealth.Stop();
  58. Globals.TimerHappy.Stop();
  59. Globals.TimerHeight.Stop();
  60. Globals.TimerHealth.Tick -= TimerHealth_Tick;
  61. Globals.TimerSatiety.Tick -= TimeSatiety_Tick;
  62. Globals.TimerHappy.Tick -= TimerHappy_Tick;
  63. Globals.TimerHeight.Tick -= TimerHeight_Tick;
  64. Globals.Frame.Navigate(new Pages.HealAnimalPage());
  65. }
  66. private void btnFeed_Click(object sender, RoutedEventArgs e)
  67. {
  68. Globals.TimerSatiety.Stop();
  69. Globals.TimerHealth.Stop();
  70. Globals.TimerHappy.Stop();
  71. Globals.TimerHeight.Stop();
  72. Globals.TimerHealth.Tick -= TimerHealth_Tick;
  73. Globals.TimerSatiety.Tick -= TimeSatiety_Tick;
  74. Globals.TimerHappy.Tick -= TimerHappy_Tick;
  75. Globals.TimerHeight.Tick -= TimerHeight_Tick;
  76. Globals.Frame.Navigate(new Pages.FeedAnimalPage());
  77. }
  78. private void btnExite_Click(object sender, RoutedEventArgs e)
  79. {
  80. Globals.PickAnimal = new Animal();
  81. Globals.Frame.Navigate(new Pages.PickAnimalPage());
  82. }
  83. private void TimerHappy_Tick(object sender, EventArgs e)
  84. {
  85. if (Globals.PickAnimal.Happy > 1)
  86. {
  87. Globals.PickAnimal.Happy -= 1;
  88. tbHappy.Text = Globals.PickAnimal.Happy.ToString();
  89. }
  90. else
  91. {
  92. MessageBox.Show("Ваш питомец умер");
  93. Globals.Frame.Navigate(new Pages.PickAnimalPage());
  94. }
  95. }
  96. private void TimeSatiety_Tick(object sender, EventArgs e)
  97. {
  98. if (Globals.PickAnimal.Satiety > 10)
  99. {
  100. Globals.PickAnimal.Satiety -= 10;
  101. tbSatiety.Text = Globals.PickAnimal.Satiety.ToString();
  102. }
  103. else
  104. {
  105. MessageBox.Show("Ваш питомец умер");
  106. Globals.Frame.Navigate(new Pages.PickAnimalPage());
  107. }
  108. }
  109. private void TimerHealth_Tick(object sender, EventArgs e)
  110. {
  111. if (Globals.PickAnimal.Health > 10)
  112. {
  113. Globals.PickAnimal.Health -= 10;
  114. tbHealth.Text = Globals.PickAnimal.Health.ToString();
  115. }
  116. else
  117. {
  118. MessageBox.Show("Ваш питомец умер");
  119. Globals.Frame.Navigate(new Pages.PickAnimalPage());
  120. }
  121. }
  122. private void TimerHeight_Tick(object sender, EventArgs e)
  123. {
  124. if(ImageAnimal.Height<350 || ImageAnimal.Width<350)
  125. {
  126. Globals.Height += 5;
  127. Globals.Width += 5;
  128. ImageAnimal.Height += 5;
  129. ImageAnimal.Width += 5;
  130. }
  131. }
  132. }
  133. }