public static void CopyFrom(this GameDataViewModel target, GameDataModel source) { if (target == null) { throw new ArgumentNullException(nameof(target)); } if (source == null) { throw new ArgumentNullException(nameof(source)); } // TODO: Copy fields here. target.Round = source.Round; target.MaxLoyaltyPoints = source.LoyaltyTrackerSize; target.MaxWinPoints = source.WinPointTrackerSize; target.Players.ReplaceAll(source.Players.Select(x => { var viewModel = ServiceLocator.Container.Resolve <PlayerViewModel>(); // TODO: Copy fields here. viewModel.Race = x.Race; viewModel.LoyaltyPoints = x.LoyaltyPoints; viewModel.WinPoints = x.WinPoints; viewModel.Color = x.Color; viewModel.Counselor = target.CounselorMap[x.Counselor]; return(viewModel); })); target.UpdateRounds(); target.UpdateIsGameCanBeFinished(); target.GetInitiativePlayer().HasInitiative = true; }
public static void Reset(this GameDataViewModel item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } item.ScoreList.Clear(); item.Players.Clear(); item.MaxLoyaltyPoints = default; item.MaxWinPoints = default; item.IsOpenedAndReady = default; item.Round = default; item.IsGameCanBeFinished = default; foreach (var round in item.Rounds) { round.State = RoundStates.Arriving; } foreach (var counselorViewModel in item.CounselorMap.Values) { counselorViewModel.IsEnabled = true; } }
public async Task <ActionResult <GameViewModel> > GetByIdAsync(int id, CancellationToken cancellationToken) { var userId = (await GetUserAsync(cancellationToken: cancellationToken))?.Id; var game = await _gameService.GetGameByIdAsync(id, userId, cancellationToken : cancellationToken); var moves = await _moveService.GetMovesAsync(id, cancellationToken : cancellationToken); var cardFilter = new CardSearchFilter { Ids = moves.Select(x => x.CardId).ToArray(), }; var playedCards = await _cardService.GetCardsAsync(cardFilter, cancellationToken : cancellationToken); var data = new GameDataViewModel { Columns = game.Columns, Moves = moves.Select(x => new GameMoveViewModel { CardId = x.CardId, GameDeckCardCollectionId = x.GameDeckCardCollectionId, Column = x.Column, Row = x.Row, }).ToList(), PlayedCards = Array.AsReadOnly(playedCards.Results), Rows = game.Rows, }; var model = new GameViewModel(game) { Data = data, LastActivity = game.StartTime.AddSeconds(data.Moves.Count()), }; return(model); }
public static GameDataModel ToDataModel(this GameDataViewModel item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } // TODO: Copy fields here. return(new GameDataModel { Round = item.Round, WinPointTrackerSize = item.MaxWinPoints, LoyaltyTrackerSize = item.MaxLoyaltyPoints, Players = item.Players.Select(x => new PlayerDataModel { // TODO: Copy fields here. Race = x.Race, LoyaltyPoints = x.LoyaltyPoints, WinPoints = x.WinPoints, Color = x.Color, Counselor = x.Counselor.Value }).ToArray() }); }
public static PlayerViewModel GetInitiativePlayer(this GameDataViewModel item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } return(item.PlayerMap[item.Round % item.Players.Count]); }
public static void UpdateIsLastRound(this GameDataViewModel item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } item.IsLastRound = item.Round == item.Rounds.Count - 1; }
public static void UpdateIsGameCanBeFinished(this GameDataViewModel item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } item.IsGameCanBeFinished = item.IsLastRound || item.Players.Any( x => x.IsWinPointsValueLeadsToGameFinish || x.IsLoyaltyPointsValueLeadsToGameFinish); }
public static void UpdatePlayerMap(this GameDataViewModel item) { var index = 0; var playerMap = new Dictionary <int, PlayerViewModel>(); foreach (var player in item.Players) { playerMap.Add(index, player); index++; } item.PlayerMap = playerMap; }
private static void UpdateRounds(this GameDataViewModel item) { for (var i = 0; i < item.Rounds.Count; i++) { var round = item.Rounds[i]; if (i < item.Round) { round.State = RoundStates.Passed; } else if (i == item.Round) { round.State = RoundStates.Current; } else { round.State = RoundStates.Arriving; } } }