private void FillCalls(CurrentGameDataViewModel model, List <Call> calls, PlayerPosition playerPosition) { foreach (var pos in Enum.GetValues(typeof(PlayerPosition))) { var position = (PlayerPosition)pos; var callValuesForPosition = calls.Where(c => c.PlayerPosition == position).Select(c => c.Value).ToList(); var onScreenPosition = playerPosition.GetOnScreenPosition(position); if (callValuesForPosition.Count > 0) { int maxValue = callValuesForPosition.Max(); switch (onScreenPosition) { case PlayerPosition.Up: model.UpCallValue = maxValue; break; case PlayerPosition.Left: model.LeftCallValue = maxValue; break; case PlayerPosition.Right: model.RightCallValue = maxValue; break; case PlayerPosition.Down: model.DownCallValue = maxValue; break; } } } }
private void FillPlayedCards(CurrentGameDataViewModel model, List <CardPlayed> cardsPlayed, PlayerPosition playerPosition) { foreach (var cardPlayed in cardsPlayed) { var onScreenPosition = playerPosition.GetOnScreenPosition(cardPlayed.PlayerPosition); Card card = CardsManager.GetCardFromString(cardPlayed.CardString); switch (onScreenPosition) { case PlayerPosition.Up: model.UpCard = card.ImgPath; break; case PlayerPosition.Left: model.LeftCard = card.ImgPath; break; case PlayerPosition.Right: model.RightCard = card.ImgPath; break; case PlayerPosition.Down: model.DownCard = card.ImgPath; break; } } }
public async Task <CurrentGameDataViewModel> GetCurrentRoundData(int gameId, int userId) { var model = new CurrentGameDataViewModel(); var game = await _gameRepository.GetGameWithRoundsById(gameId); var player = await _playerRepository.GetPlayerByUserIdAsync(userId); Round round = game.Rounds.OrderByDescending(r => r.RoundNumber).FirstOrDefault(); FillBasicRoundData(model, round, player.PlayerPosition.Value); FillTotalScores(game, player.Team.Value, model: model); FillRoundScores(round, player.Team.Value, model: model); FillCalls(model, round.Calls, player.PlayerPosition.Value); if ((int)round.RoundPhase > 2) { var cardsPlayed = round.CardsPlayed.Where(ga => ga.RoundPhase == round.RoundPhase).OrderBy(ga => ga.Id).ToList(); FillPlayedCards(model, cardsPlayed, player.PlayerPosition.Value); } var rounds = game.Rounds.OrderBy(r => r.RoundNumber).ToList(); AddRoundsToData(model.Rounds, rounds, player.Team.Value); return(model); }
private void FillBasicRoundData(CurrentGameDataViewModel model, Round round, PlayerPosition playerPosition) { model.CurrentRoundId = round.Id; model.CurrentRoundPhase = (int)round.RoundPhase; model.SelectedTrump = round.CurrentTrump.HasValue ? (int)round.CurrentTrump : 0; model.TrumpSelectedBy = !string.IsNullOrEmpty(round.TrumpSelectedBy) ? round.TrumpSelectedBy : ""; model.PositionToPlay = (int)playerPosition.GetOnScreenPosition(round.CurrentPlayerToPlay); model.DealerPosition = (int)playerPosition.GetOnScreenPosition(round.FirstPlayerToPlay.GetPreviousPosition()); model.isLast = playerPosition == round.FirstPlayerToPlay.GetPreviousPosition(); }
private void FillRoundScores(Round round, Team team, Dictionary <string, int> scores = null, CurrentGameDataViewModel model = null) { switch (team) { case Team.FirstTeam: if (scores != null) { scores.Add("miCalls", round.FirstTeamCalls); scores.Add("viCalls", round.SecondTeamCalls); scores.Add("miPoints", round.FirstTeamScore); scores.Add("viPoints", round.SecondTeamScore); scores.Add("miRoundTotal", round.FirstTeamRoundTotal); scores.Add("viRoundTotal", round.SecondTeamRoundTotal); } else if (model != null) { model.MiCalls = round.FirstTeamCalls; model.ViCalls = round.SecondTeamCalls; model.MiPoints = round.FirstTeamScore; model.ViPoints = round.SecondTeamScore; model.MiRoundTotal = round.FirstTeamRoundTotal; model.ViRoundTotal = round.SecondTeamRoundTotal; } break; case Team.SecondTeam: if (scores != null) { scores.Add("miCalls", round.SecondTeamCalls); scores.Add("viCalls", round.FirstTeamCalls); scores.Add("miPoints", round.SecondTeamScore); scores.Add("viPoints", round.FirstTeamScore); scores.Add("miRoundTotal", round.SecondTeamRoundTotal); scores.Add("viRoundTotal", round.FirstTeamRoundTotal); } else if (model != null) { model.MiCalls = round.SecondTeamCalls; model.ViCalls = round.FirstTeamCalls; model.MiPoints = round.SecondTeamScore; model.ViPoints = round.FirstTeamScore; model.MiRoundTotal = round.SecondTeamRoundTotal; model.ViRoundTotal = round.FirstTeamRoundTotal; } break; } }
private void FillTotalScores(Game game, Team team, Dictionary <string, int> scores = null, CurrentGameDataViewModel model = null) { switch (team) { case Team.FirstTeam: if (scores != null) { scores.Add("miTotalScore", game.FirstTeamTotalScore); scores.Add("viTotalScore", game.SecondTeamTotalScore); } else if (model != null) { model.MiTotalScore = game.FirstTeamTotalScore; model.ViTotalScore = game.SecondTeamTotalScore; } break; case Team.SecondTeam: if (scores != null) { scores.Add("miTotalScore", game.SecondTeamTotalScore); scores.Add("viTotalScore", game.FirstTeamTotalScore); } else if (model != null) { model.MiTotalScore = game.SecondTeamTotalScore; model.ViTotalScore = game.FirstTeamTotalScore; } break; } }