Exemple #1
0
        public GamePlayStates HandleGame(IList <Event> events, string homeTeam)
        {
            Init(events);

            var goalsAndPenalties = GetGoalsAndPenalties(events, homeTeam);
            var endOfGame         = goalsAndPenalties.OrderBy(e => e.EndTime).Last().EndTime;
            var lastEndTime       = 0;

            for (var second = 0; second <= endOfGame; second++)
            {
                var eventsThatStartThisSecond     = goalsAndPenalties.EventsThatStartThisSecond(second);
                var penaltiesThatExpireThisSecond = _penaltyBox.PenaltiesThatExpireThisSecond(second);

                if (eventsThatStartThisSecond.Any() || penaltiesThatExpireThisSecond.Any())
                {
                    _gamePlayStates.Add(new GamePlayState
                    {
                        GameId            = _gameId,
                        StartTime         = lastEndTime,
                        EndTime           = second,
                        PlayersOnIce      = _penaltyBox.PlayersOnIce,
                        HomeTeamAdvantage = _homeTeamAdvantage,
                    });
                    lastEndTime = second;
                }

                HandleGoalsThisSecond(eventsThatStartThisSecond, second);

                HandlePenaltiesThisSecond(eventsThatStartThisSecond, second);
            }

            Logger.Debug(string.Format("END GAME {0}", _gameId));
            Logger.Debug("");

            return(new GamePlayStates {
                Items = _gamePlayStates.OrderBy(g => g.StartTime).ToList()
            });
        }
        public void DoubleMinorPlusDoubleMinorAndMajorPlusDoubleMinorPlusMinorShouldBeFourOnFourForTwoMinutes()
        {
            _penaltyBox.AddPenalties(new[] { PenaltyCreator.CreateDoubleMinor(true), PenaltyCreator.CreateDoubleMinor(true), PenaltyCreator.CreateMajorAndGame(false), PenaltyCreator.CreateDoubleMinor(false), PenaltyCreator.CreateMinor(false) });

            Assert.AreEqual(PlayersOnIce.FourOnFour, _penaltyBox.PlayersOnIce);

            //Expire minors
            var ex = _penaltyBox.PenaltiesThatExpireThisSecond(220).ToList();

            _penaltyBox.ExpirePenalties(ex);

            Assert.AreEqual(PlayersOnIce.FiveOnFour, _penaltyBox.PlayersOnIce);

            //Expire Major
            var ex2 = _penaltyBox.PenaltiesThatExpireThisSecond(400).ToList();

            _penaltyBox.ExpirePenalties(ex2);

            Assert.AreEqual(PlayersOnIce.FiveOnFive, _penaltyBox.PlayersOnIce);

            //Assert.AreEqual(2, _penaltyBox.PenaltyScoreBoard.Home.Count());
            //Assert.AreEqual(340, _penaltyBox.PenaltyScoreBoard.Home.Last().EndTime);
        }