public GamePlayViewModel(GamePlay gamePlay) { GamePlay = gamePlay; TeamRotation[] currentRotation = gamePlay.Sets[gamePlay.CurrentSetNumber].TeamRotations; int[] teamARotation = currentRotation[0].ShirtNumbers; int[] teamBRotation = currentRotation[1].ShirtNumbers; RotationForView = new TeamRotation[2] { new TeamRotation() { ShirtNumbers = new int[6] { teamARotation[4], teamARotation[5], teamARotation[0], teamARotation[3], teamARotation[2], teamARotation[1] } } , new TeamRotation() { ShirtNumbers = new int[6] { teamBRotation[1], teamBRotation[2], teamBRotation[3], teamBRotation[0], teamBRotation[5], teamBRotation[4] } } }; }
public GameUpdateResult LogTimeOut(GamePlay gamePlay, int team) { //!! more validation Set currentSet = gamePlay.GetCurrentSet(); TeamInSetInformation teamInSetInformation = currentSet.Information[team]; if (teamInSetInformation.NumberOfTimeOutsUsed == Constants.MaximumNumberOfTimeOutsPerTeamPerSet) return GameUpdateResult.LimitExceeced; TimeOut timeOut = new TimeOut { TeamAScore = currentSet.Score[0], TeamBScore = currentSet.Score[1] }; teamInSetInformation.TimeOuts[teamInSetInformation.NumberOfTimeOutsUsed] = timeOut; teamInSetInformation.NumberOfTimeOutsUsed++; Save(gamePlay); return teamInSetInformation.NumberOfTimeOutsUsed == Constants.MaximumNumberOfTimeOutsPerTeamPerSet ? GameUpdateResult.SuccessLastAvailable : GameUpdateResult.Success; }
public AddPointResult AddPoint(GamePlay game, int pointWinner, int thisPointsServer) { var currentSetNumber = game.GetHighestActivatedSetNumber(); game.Sets[currentSetNumber].Score[pointWinner]++; if (thisPointsServer > -1 && pointWinner != thisPointsServer) game.Sets[currentSetNumber].TeamRotations[pointWinner] = Rotate(game.Sets[currentSetNumber].TeamRotations[pointWinner]); AddPointResult result = new AddPointResult { Game = game, ResultStatus = PointResultStatus.Continue, NextServer = pointWinner }; if (game.IsEndOfSet(currentSetNumber)) { FinishCurrentSet(game, currentSetNumber, pointWinner); if (game.IsEndOfGame()) { FinishGame(game); result = new AddPointResult { Game = game, ResultStatus = PointResultStatus.EndOfGame }; } else if (game.IsNextSetDeciding()) result = new AddPointResult { Game = game, ResultStatus = PointResultStatus.EndOfSetNextDeciding }; else result = new AddPointResult { Game = game, ResultStatus = PointResultStatus.EndOfSet, NextServer = GetNewSetsFirstServer(game, currentSetNumber) }; } Save(game); return result; }
public GamePlay StartNewSet(GamePlay game, TeamRotation[] teamRotations, int firstServe) { var highestActivatedSetNumber = game.GetHighestActivatedSetNumber(); game.Sets[highestActivatedSetNumber + 1] = new Set { TeamRotations = teamRotations, Score = new int[2], FirstServer = firstServe, StartedAt = DateTime.Now, Information = new TeamInSetInformation[2] { new TeamInSetInformation() { Substitutions = new Substitution[Constants.MaximumNumberOfSubstitutionsPerTeamPerSet], TimeOuts = new TimeOut[Constants.MaximumNumberOfTimeOutsPerTeamPerSet] }, new TeamInSetInformation() { Substitutions = new Substitution[Constants.MaximumNumberOfSubstitutionsPerTeamPerSet], TimeOuts = new TimeOut[Constants.MaximumNumberOfTimeOutsPerTeamPerSet] } }, }; return game; }
private void Save(GamePlay gamePlay) { _gameAccess.Save(gamePlay); }
private int GetNewSetsFirstServer(GamePlay game, int highestActivatedSetNumber) { return game.Sets[highestActivatedSetNumber].FirstServer == 0 ? 1 : 0; }
private void FinishGame(GamePlay gamePlay) { Game game = GetGame(gamePlay.GameId); game.EndedAt = DateTime.Now; //!! utc? Save(game); }
private void FinishCurrentSet(GamePlay game, int currentSetNumber, int pointWinner) { game.Sets[currentSetNumber].Winner = pointWinner; game.Sets[currentSetNumber].EndedAt = DateTime.Now; game.SetWins[pointWinner]++; }
public GameUpdateResult Substitute(GamePlay game, int team, int shirtNumberGoingIn, int shirtNumberComingOut) { Set currentSet = game.GetCurrentSet(); int opponentTeam = team == 1 ? 0 : 1; //repeated logic?? //!!Validation // team in 0, 1 // team contains shirt coming out // no. of substitutions done for team for set int completedSubstitutionCount; //!! store this count in the object? for (completedSubstitutionCount = 0; completedSubstitutionCount < currentSet.Information[team].Substitutions.Length; completedSubstitutionCount++) { if (currentSet.Information[team].Substitutions[completedSubstitutionCount] == null) break; } if (completedSubstitutionCount == 4) return GameUpdateResult.LimitExceeced; // new shirt number isn't already there int positionOfPlayerComingOut = Array.IndexOf(currentSet.TeamRotations[team].ShirtNumbers, shirtNumberComingOut); var substitution = new Substitution { OpponentScore = currentSet.Score[opponentTeam], PlayerComingOut = currentSet.TeamRotations[team].ShirtNumbers[positionOfPlayerComingOut], PlayerGoingIn = shirtNumberGoingIn, RequestedTeamScore = currentSet.Score[team] }; currentSet.Information[team].Substitutions[completedSubstitutionCount++] = substitution; currentSet.TeamRotations[team].ShirtNumbers[positionOfPlayerComingOut] = shirtNumberGoingIn; Save(game); return GameUpdateResult.Success; }
public void Save(GamePlay gamePlay) { var game = Load<Game>(GetDocumentId(gamePlay.GameId)); game.GamePlay = gamePlay; Save(game); }