コード例 #1
0
        public void AddDogToRacetrack_Test()
        {
            var newDog = _racetrack.CreateDog(DogBreedEnum.Greyhound);

            _racetrack.AddDogToRacetrack(newDog);
            var result = _racetrack.GetAllDogsInRacetrack();

            (result.Count == 1).Should().BeTrue();
        }
コード例 #2
0
        public Notification Execute(object obj = null)
        {
            List <Image> dogImages    = (List <Image>)obj;
            var          notification = new Notification();
            var          totalDogs    = _racetrack.GetAllDogsInRacetrack().Count;

            if (totalDogs < maxNumberOfDogsInRacetrack)
            {
                IDog newDog = _racetrack.CreateDog(DogBreedEnum.Greyhound);
                newDog.DogImage = dogImages[totalDogs];
                _racetrack.AddDogToRacetrack(newDog);
                notification.Code        = NotificationEnum.Ok;
                notification.Description = AllNotifications.NewDogToRacetrackOk(newDog.Name.ToString());
                notification.Items       = _racetrack.GetAllDogsInRacetrack().Count();
                return(notification);
            }

            notification.Code        = NotificationEnum.Warning;
            notification.Description = AllNotifications.NewDogToRacetrackWarning();
            notification.Items       = totalDogs;
            return(notification);
        }
コード例 #3
0
        public int BtnAddDog_Click(ComboBox comboBoxDogs, Label labelNotification, List <Image> dogImages)
        {
            ICommand newDogCommand = _commandInvoker.GetCommand(ActionCommandEnum.NewDogToRacetrack);
            var      notification  = newDogCommand.Execute(dogImages);

            if (notification.Items < 2)
            {
                labelNotification.Content    = notification.Description + "\nMin number of dogs for a race is 2";
                labelNotification.Foreground = NotificationColors.GetBrushColor(notification.Code);
            }
            else if (notification.Items >= 2)
            {
                labelNotification.Content    = notification.Description;
                labelNotification.Foreground = NotificationColors.GetBrushColor(notification.Code);
            }
            var allDogsNames = _racetrack.GetAllDogsInRacetrack().Select(a => a.Name).ToList();

            comboBoxDogs.ItemsSource = allDogsNames;
            return(notification.Items);
        }
コード例 #4
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);
        }