Beispiel #1
0
        public Notification Execute(object obj = null)
        {
            int          totalDistance = (int)obj, iteration = 1;
            Notification notification = new Notification();
            List <IDog>  dogs         = _racetrack.GetAllDogsInRacetrack();
            Stopwatch    timer        = Stopwatch.StartNew();
            bool         keepRacing   = true;

            while (keepRacing)
            {
                foreach (var dog in dogs)
                {
                    double initialDistanceCoveredByADog = dog.GetStandardMaxMetresCoveredPer1Second();
                    var    distance = _racetrack.RaceGo(initialDistanceCoveredByADog);
                    dog.DistanceCoveredByDog += distance;
                    dog.RaceIteration         = iteration;
                    //==Moving the picture BEGIN==========================================
                    var positionImage = Canvas.GetLeft(dog.DogImage);
                    var newPosition   = positionImage + distance;
                    Canvas.SetLeft(dog.DogImage, newPosition);
                    //==Moving the picture END============================================
                }
                var winnerDogName = DogWonTheRace(totalDistance, dogs);
                if (winnerDogName != 0)
                {
                    var winnerdog = dogs.Where(a => a.Name == winnerDogName).FirstOrDefault();
                    winnerdog.WinnerDog = true;
                    break;
                }
                iteration++;
            }
            timer.Stop();
            TimeSpan timespan      = timer.Elapsed;
            var      totalRaceTime = String.Format("{0:00}:{1:00}:{2:00}", timespan.Minutes, timespan.Seconds, timespan.Milliseconds / 10);
            var      winnerDog     = dogs.Where(a => a.WinnerDog == true).FirstOrDefault();

            notification.Code        = Common.Enums.NotificationEnum.Ok;
            notification.Description = $"{winnerDog.Name} - {totalDistance} - {totalRaceTime}";
            notification.Items       = dogs.Count();
            return(notification);
        }
Beispiel #2
0
        public void RaceGo_Test()
        {
            var result = _racetrack.RaceGo(10);

            (result >= 0).Should().BeTrue();
        }