示例#1
0
        /// <summary>
        /// Simulates a competition that is given as parameter.
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="competition"></param>
        public void Compete(Storage storage, Competition competition)
        {
            TimeSpan   ts = new TimeSpan(0, 0, 2);
            Skateboard competitor;

            while (true)
            {
                try
                {
                    competitor = ChooseBoard(storage, competition.GetRequirements());
                    break;
                }
                catch (NoMatchingBoardException)
                {
                    PrintErrorMessage("There is no board with the given name.");
                    Thread.Sleep(ts);
                }
            }
            if (competition.EligibleForCompetition(competitor) == true)
            {
                if (competition.Race(storage, competitor) == true)
                {
                    Console.WriteLine("Congratulations, you won!");
                    Thread.Sleep(ts);
                }
                else
                {
                    Console.WriteLine("You lost the competition this time.");
                    Thread.Sleep(ts);
                }
            }
            else
            {
                throw new NotEligibleException();
            }
        }