Example #1
0
        public bool IsGameValid(ScheduleGame game)
        {
            //does the game match its rules?
            //does the home tema not equal away
            var validator = new ScheduleGameValidator(game).IsValid;

            return(validator);
        }
Example #2
0
 public ScheduleGameValidator(ScheduleGame game)
 {
     Messages = new List <string>();
     IsValid  = !(game.Home.Id == game.Away.Id);
     if (!IsValid)
     {
         Messages.Add("Game:" + game.GameNumber + " day: " + game.Day + " has the same Home and Away team");
     }
 }
Example #3
0
        public static int AddGameToSchedule(Schedule schedule, ScheduleGame game, int dayToStartOn)
        {
            bool foundDayToAddTeamTo = false;
            int  currentDay          = dayToStartOn;
            int  dayToAddTeamTo      = currentDay;
            int  maxDay = schedule.Days.Count == 0 ? dayToStartOn :schedule.Days.Keys.Max();

            while (!foundDayToAddTeamTo && currentDay <= maxDay)
            {
                if (schedule.Days.ContainsKey(currentDay))
                {
                    bool canAdd = true;
                    canAdd = canAdd && !schedule.Days[currentDay].DoesTeamPlayInDay(game.Home.Id);
                    canAdd = canAdd && !schedule.Days[currentDay].DoesTeamPlayInDay(game.Away.Id);

                    if (canAdd)
                    {
                        foundDayToAddTeamTo = true;
                    }

                    dayToAddTeamTo = currentDay;
                }

                currentDay++;
            }

            if (!foundDayToAddTeamTo)
            {
                schedule.AddDay(currentDay);
                dayToAddTeamTo = currentDay;
            }

            schedule.Days[dayToAddTeamTo].AddGame(game);

            return(currentDay);
        }
Example #4
0
 public void AddGame(ScheduleGame game)
 {
     game.Day = DayNumber;
     Games.Add(game);
 }