Пример #1
0
        public bool ScoreGoal(TableSide side)
        {
            if (IsFinished)
            {
                return(false);
            }

            var goal = new Goal
            {
                Side = side,
                Time = DateTime.Now
            };

            Goals.Add(goal);

            var lastGoal = Goals.Count(g => g.Side == goal.Side) >= GoalsToVictory;

            if (lastGoal)
            {
                IsFinished = true;
                EndTime    = DateTime.Now;
            }

            return(true);
        }
        public IHttpActionResult PutGoal(Guid tableGuid, TableSide side)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var table = _db.Tables.Single(t => t.Guid == tableGuid);
            var match = table.ActiveMatch();

            if (match == null)
            {
                return(Ok(Match.NoGameSummary()));
            }

            if (match.ScoreGoal(side))
            {
                //HACK BEGINS: Force resolving RedTeam and BlueTeam
                var redName  = match.RedTeam.Name;
                var blueName = match.BlueTeam.Name;
                var creator  = match.Creator.Name;
                //HACK ENDS

                _db.SaveChanges();
                return(Ok(match.Summary()));
            }
            return(Ok(Match.NoGameSummary()));
        }
Пример #3
0
        public void UpdateTest(int matchId, int repetition, TableSide side)
        {
            for (int i = 0; i < repetition; i++)
            {
                game.Score(matchId, side);
            }
            var match = game.Detail(matchId);

            Assert.Equal((repetition / 10) + 1, match.Periods.Count);
        }
Пример #4
0
        public void OneSidedTest(int repetition, TableSide side)
        {
            var match = game.Create();

            for (int i = 0; i < repetition; i++)
            {
                game.Score(match.Id, side);
            }
            var matchResult = game.Detail(match.Id);

            Assert.True(matchResult.IsFinished);
            Assert.True(matchResult.WasOneSided);
        }
Пример #5
0
        public async Task <IActionResult> Update([Required] int id, TableSide side)
        {
            if (!ModelState.IsValid)
            {
                return(new ObjectResult(errorHandler.GetMessage(ErrorMessagesEnum.ModelValidation))
                {
                    StatusCode = (Int32)HttpStatusCode.BadRequest
                });
            }
            var match = game.Score(id, side);

            return(new ObjectResult(match)
            {
                StatusCode = (Int32)HttpStatusCode.OK
            });
        }
Пример #6
0
        public MatchDtoDetail Score(int matchId, TableSide side)
        {
            if (side == TableSide.None)
            {
                throw new TableSideException("Score cannot be set on none");
            }
            var match = context.Match.Include(o => o.Periods).ThenInclude(j => j.Goals).FirstOrDefault(o => o.Id == matchId);

            if (match == null)
            {
                throw new EntityNullException("Match not found");
            }

            if (logic.IsGameOver(match).Result)
            {
                throw new FinishedMatchException("Match is completed and cannot be modified");
            }

            var period = match.Periods.FirstOrDefault(o => o.MatchId == match.Id && o.IsFinished == false);

            if (period == null)
            {
                throw new EntityNullException("Period not found");
            }
            period.Goals.Add(new Goal()
            {
                Player = side
            });
            if (logic.IsPeriodOver(period).Result)
            {
                logic.CompletePeriod(period);
                if (logic.IsGameOver(match).Result)
                {
                    logic.CompleteGame(match);
                }
                else
                {
                    match.Periods.Add(new Period());
                }
            }
            context.SaveChanges();
            return(mapper.Map <Match, MatchDtoDetail>(match));
        }
 internal void init(int id, TableSide tableSide)
 {
     this.id        = id;
     this.tableSide = tableSide;
 }
Пример #8
0
        public double CalculateScoreFactor(Match match, TableSide side)
        {
            var goalDelta = match.Goals.Sum(goal => goal.Side == side ? 1 : -1);

            return((goalDelta + 10.0) / 20.0);
        }