123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- 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;
- using System.Windows.Threading;
- namespace TamagochiProject.Pages
- {
- /// <summary>
- /// Логика взаимодействия для MainAnimalPage.xaml
- /// </summary>
- public partial class MainAnimalPage : Page
- {
- public MainAnimalPage()
- {
- InitializeComponent();
- DataContext = Globals.PickAnimal;
- ImageAnimal.Width = Globals.Width;
- ImageAnimal.Height=Globals.Height;
- Globals.TimerHealth.Interval = TimeSpan.FromSeconds(15);
- Globals.TimerSatiety.Interval = TimeSpan.FromSeconds(10);
- Globals.TimerHappy.Interval = TimeSpan.FromSeconds(3);
- Globals.TimerHeight.Interval = TimeSpan.FromSeconds(3);
- Globals.TimerHealth.Tick += TimerHealth_Tick;
- Globals.TimerSatiety.Tick += TimeSatiety_Tick;
- Globals.TimerHappy.Tick += TimerHappy_Tick;
- Globals.TimerHeight.Tick += TimerHeight_Tick;
- Globals.TimerSatiety.Start();
- Globals.TimerHealth.Start();
- Globals.TimerHappy.Start();
- Globals.TimerHeight.Start();
- }
- private void btnPlay_Click(object sender, RoutedEventArgs e)
- {
- Globals.TimerSatiety.Stop();
- Globals.TimerHealth.Stop();
- Globals.TimerHappy.Stop();
- Globals.TimerHeight.Stop();
- Globals.TimerHealth.Tick -= TimerHealth_Tick;
- Globals.TimerSatiety.Tick -= TimeSatiety_Tick;
- Globals.TimerHappy.Tick -= TimerHappy_Tick;
- Globals.TimerHeight.Tick -= TimerHeight_Tick;
- Globals.Frame.Navigate(new Pages.PlayAnimalPage());
- }
- private void btnHeal_Click(object sender, RoutedEventArgs e)
- {
- Globals.TimerSatiety.Stop();
- Globals.TimerHealth.Stop();
- Globals.TimerHappy.Stop();
- Globals.TimerHeight.Stop();
- Globals.TimerHealth.Tick -= TimerHealth_Tick;
- Globals.TimerSatiety.Tick -= TimeSatiety_Tick;
- Globals.TimerHappy.Tick -= TimerHappy_Tick;
- Globals.TimerHeight.Tick -= TimerHeight_Tick;
- Globals.Frame.Navigate(new Pages.HealAnimalPage());
- }
- private void btnFeed_Click(object sender, RoutedEventArgs e)
- {
- Globals.TimerSatiety.Stop();
- Globals.TimerHealth.Stop();
- Globals.TimerHappy.Stop();
- Globals.TimerHeight.Stop();
- Globals.TimerHealth.Tick -= TimerHealth_Tick;
- Globals.TimerSatiety.Tick -= TimeSatiety_Tick;
- Globals.TimerHappy.Tick -= TimerHappy_Tick;
- Globals.TimerHeight.Tick -= TimerHeight_Tick;
- Globals.Frame.Navigate(new Pages.FeedAnimalPage());
- }
- private void btnExite_Click(object sender, RoutedEventArgs e)
- {
- Globals.PickAnimal = new Animal();
- Globals.Frame.Navigate(new Pages.PickAnimalPage());
- }
- private void TimerHappy_Tick(object sender, EventArgs e)
- {
- if (Globals.PickAnimal.Happy > 1)
- {
- Globals.PickAnimal.Happy -= 1;
- tbHappy.Text = Globals.PickAnimal.Happy.ToString();
- }
- else
- {
- MessageBox.Show("Ваш питомец умер");
- Globals.Frame.Navigate(new Pages.PickAnimalPage());
- }
- }
- private void TimeSatiety_Tick(object sender, EventArgs e)
- {
- if (Globals.PickAnimal.Satiety > 10)
- {
- Globals.PickAnimal.Satiety -= 10;
- tbSatiety.Text = Globals.PickAnimal.Satiety.ToString();
- }
- else
- {
- MessageBox.Show("Ваш питомец умер");
- Globals.Frame.Navigate(new Pages.PickAnimalPage());
- }
- }
- private void TimerHealth_Tick(object sender, EventArgs e)
- {
- if (Globals.PickAnimal.Health > 10)
- {
- Globals.PickAnimal.Health -= 10;
- tbHealth.Text = Globals.PickAnimal.Health.ToString();
- }
- else
- {
- MessageBox.Show("Ваш питомец умер");
- Globals.Frame.Navigate(new Pages.PickAnimalPage());
- }
- }
- private void TimerHeight_Tick(object sender, EventArgs e)
- {
- if(ImageAnimal.Height<350 || ImageAnimal.Width<350)
- {
- Globals.Height += 5;
- Globals.Width += 5;
- ImageAnimal.Height += 5;
- ImageAnimal.Width += 5;
- }
- }
- }
- }
|