예제 #1
0
 /// <summary>
 ///     Starts the horse racing game
 /// </summary>
 public void Start(int numberOfPings)
 {
     if (Horses.Count > 0)
     {
         foreach (var horse in Horses)
         {
             horse.Start(numberOfPings);
         }
     }
     else
     {
         ToastUtil.Notify("No horses", "Add at least 1 horse to start");
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_addHorse_OnClick(object sender, RoutedEventArgs e)
        {
            var canBeSubmitted = true;
            // valid url is: example.com // checks for https
            Regex           rx      = new Regex("^[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$");
            MatchCollection matches = rx.Matches(txt_horseUrl.Text.ToLower());

            if (string.IsNullOrEmpty(txt_horseName.Text))
            {
                ToastUtil.Notify("No name", "Name cannot be empty");
                canBeSubmitted = false;
            }

            //When matches is bigger than zero, the url is not valid
            if (matches.Count == 0)
            {
                ToastUtil.Notify("No valid url", "Url is not valid, needs to look like this: example.com");
                canBeSubmitted = false;
            }

            if (string.IsNullOrEmpty(txt_horseUrl.Text))
            {
                ToastUtil.Notify("No url", "Url cannot be empty");
                canBeSubmitted = false;
            }

            if (!canBeSubmitted)
            {
                return;
            }

            _gameController.AddHorse(txt_horseName.Text, 10, txt_horseUrl.Text.ToLower());

            // Clearing input fields after adding horse
            txt_horseName.Text = "";
            txt_horseUrl.Text  = "";
        }
예제 #3
0
        /// <summary>
        ///     Event gets triggered whenever a horse is finished pinging
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HorseFinished(object sender, EventArgs e)
        {
            Horse bestHorse = null;

            foreach (Horse horse in Horses)
            {
                if (horse.Status != HorseStatus.FINISHED)
                {
                    return;
                }

                if (bestHorse == null || bestHorse.Distance < horse.Distance)
                {
                    bestHorse = horse;
                }
            }

            if (bestHorse == null)
            {
                return;
            }
            ToastUtil.Notify($"{bestHorse.Name} is the winner!", $"With a total distance of: {bestHorse.Distance}");
            MediaUtil.PlaySound("trumpet1.mp3");
        }