private void DisplayImage(RacerModelClass racer) { /* * if(winflag) * { * timer.Stop(); * return; * } */ //calculating the dog postion with respect to left property Image image = racer.Image; long leftPosition = Convert.ToInt64(image.GetValue(Canvas.LeftProperty)); int pace = CommonClass.GetValue(CommonClass.Racer_Parameter_Type.Speed, CommonClass.Speed.Level_4); if (leftPosition >= ImageBackground.Width - image.Width) //800 is the width of the panel { timer.Stop(); //if (!winflag) //{ MessageBox.Show($"Dog {racer.ID} has won!!!"); //CheckForWinner(id); //winflag = true; InitializeDogModelPosition(); //InitializeComponent(); //PunterList.Items.Refresh(); //} } else { Canvas.SetLeft(image, leftPosition + pace); } }
private void InitializeRacerModel() { int i = 1; foreach (var value in CommonCodeSingleton.Instance.getRandomSequence(CommonClass.Racer_Parameter_Type.Size)) { Image image; //int Top, Left=7; string name; switch (i) { case 1: image = image1; name = "Piggy 1"; //Top = 3; break; case 2: image = image2; name = "Piggy 2"; //Top = 45; break; case 3: image = image3; name = "Piggy 3"; //Top = 90; break; case 4: image = image4; name = "Piggy 4"; //Top = 130; break; default: throw new NotSupportedException(); } RacerModelClass model = new RacerModelClass(value, name, image); { // //model.Top = Top; Left = 0; }; //model.CallBackMethod = DisplayImage; i++; RacerList.Add(model); //timer.Tick += new EventHandler(model.Move); timer.Tick += (sender, e) => Timer_Tick_Method(model, e); } i = 0; foreach (var value in CommonCodeSingleton.Instance.getRandomSequence(CommonClass.Racer_Parameter_Type.Speed)) { RacerList[i].Speed = value; i++; } }
private void Timer_Tick_Method(object sender, EventArgs e) { RacerModelClass racer = sender as RacerModelClass; Image image = racer.Image; long leftPosition = Convert.ToInt64(image.GetValue(Canvas.LeftProperty)); int pace = CommonClass.GetValue(CommonClass.Racer_Parameter_Type.Speed, racer.Speed); if (leftPosition >= ImageBackground.Width - image.Width) //800 is the width of the panel { timer.Stop(); MessageBox.Show($"{racer.Name} has won!!!"); int id = int.Parse(racer.Name.Substring(6)); CheckForWinner(id); //winflag = true; //RacerList[racer.ID - 1].Left = 10; InitializeDogModelPosition(); //PunterList.Items.Refresh(); } else { Canvas.SetLeft(image, leftPosition + pace); } }