void displayImage(DogModelClass dog, int id) { if (winflag) { timer.Stop(); return; } Image image = dog.image; long dogPos = Convert.ToInt64(image.GetValue(Canvas.LeftProperty)); //calculating the dog postion with respect to left property if (dogPos >= RaceTrack.Width - image.Width) //800 is the width of the panel { timer.Stop(); if (!winflag) { MessageBox.Show($"Dog {id} has won!!!"); CheckForWinner(id); winflag = true; InitializeDogModelPosition(); PunterList.Items.Refresh(); } } else { int pace = DogGeneratorClass.GenerateSteps(dog as DogBaseClass); Canvas.SetLeft(image, dogPos + pace); } }
private void CreateDogModel(int Top, int Left, DogBaseClass dog) { DogModelClass dogmodel; dogmodel = new DogModelClass(dog); dogmodel.callBackMethod = displayImage; dogmodel.Top = Top; dogmodel.Left = Left; //Canvas.SetTop(dogmodel.image, Top); //Canvas.SetLeft(dogmodel.image, Left); myCanvas.Children.Add(dogmodel.image); timer.Tick += new EventHandler(dogmodel.Move); myListOfDogs.Add(dogmodel); }