public Tree1(CUser tempUser, CTree tempTree) { InitializeComponent(); myUser = tempUser; myTree = tempTree; lblUsername.Content = myUser.Username; lblSpecies.Content = myTree.Species; System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 1); dispatcherTimer.Start(); void dispatcherTimer_Tick(object sender, EventArgs e) //every 1s, execute block of command between parentheses { update(); mytreeUpdate(); } System.Windows.Threading.DispatcherTimer dispatcherTimer2 = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer2.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer2.Interval = new TimeSpan(1, 0, 0); dispatcherTimer2.Start(); void dispatcherTimer2_Tick(object sender, EventArgs e) //every 1h, execute block of command between parentheses { myTree.hydrationLoss(); } void update() { myTree.checkStatus(); myTree.updateTree(); TbMoney.Text = myUser.Money.ToString(); TbFertilizer.Text = myUser.Fertilizer.ToString(); TbWater.Text = myUser.Water.ToString(); lbStatus.Text = myTree.Status; } //karena percobaan assignment bitmap via class gagal, sementara saya hardcode agar fungsionalitas bagian lain app dapat diperlihatkan. void mytreeUpdate() { if (myTree.GrowthPhase == 1 & myTree.IsSick == false & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/1.jpg")); } else if (myTree.GrowthPhase == 1 & myTree.IsSick == true & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/1s.jpg")); } else if (myTree.GrowthPhase == 1 & myTree.IsSick == false & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/1dh.jpg")); } else if (myTree.GrowthPhase == 1 & myTree.IsSick == true & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/1snh.jpg")); } else if (myTree.GrowthPhase == 2 & myTree.IsSick == false & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/2.jpg")); } else if (myTree.GrowthPhase == 2 & myTree.IsSick == true & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/2s.jpg")); } else if (myTree.GrowthPhase == 2 & myTree.IsSick == false & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/2dh.jpg")); } else if (myTree.GrowthPhase == 2 & myTree.IsSick == true & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/2snh.jpg")); } else if (myTree.GrowthPhase == 3 & myTree.IsSick == false & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/3.jpg")); } else if (myTree.GrowthPhase == 3 & myTree.IsSick == true & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/3s.jpg")); } else if (myTree.GrowthPhase == 3 & myTree.IsSick == false & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/3dh.jpg")); } else if (myTree.GrowthPhase == 3 & myTree.IsSick == true & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/3snh.jpg")); } else if (myTree.GrowthPhase == 4 & myTree.IsSick == false & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/4.jpg")); } else if (myTree.GrowthPhase == 4 & myTree.IsSick == true & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/4s.jpg")); } else if (myTree.GrowthPhase == 4 & myTree.IsSick == false & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/4dh.jpg")); } else if (myTree.GrowthPhase == 4 & myTree.IsSick == true & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/4snh.jpg")); } } }
private void Button_Click(object sender, RoutedEventArgs e)//hanya untuk debugging { myTree.hydrationLoss(); }