Пример #1
0
 public static GameEntity ToEntity(this Domain.Game game, IEnumerable <UserInfo> playerUserInfo)
 {
     return(new GameEntity()
     {
         Id = game.Id,
         Title = game.Title,
         Status = game.Status,
         WinnerUserId = game.Winner.UserId,
         UserScores = game.Scores.Select(s => new UserScoreInfo()
         {
             User = playerUserInfo.FirstOrDefault(p => p.UserId == s.Key), Score = s.Value
         }).ToArray()
     });
 }
Пример #2
0
 public static GameDTO ToDto(this Domain.Game game, IEnumerable <UserInfoDTO> players)
 {
     return(new GameDTO()
     {
         Id = game.Id,
         Title = game.Title,
         Status = game.Status,
         UserScores = players.Select(p =>
                                     new UserScoreInfoDTO()
         {
             User = p,
             Score = game.Scores.ContainsKey(p.UserId) ? game.Scores[p.UserId] : 0
         }).ToList(),
         WinnerUserId = game.Winner?.UserId
     });
 }
Пример #3
0
        public Domain.Game Create(string title, IEnumerable <string> playerUserIds, TimeSpan duration)
        {
            if (title == null)
            {
                throw new ArgumentNullException(nameof(title));
            }

            if (playerUserIds == null || playerUserIds.Count() == 0)
            {
                throw new ArgumentException("Please invite players to the game!");
            }

            var game = new Domain.Game(Guid.NewGuid(), title, playerUserIds, duration);

            this.Games.AddOrUpdate(game.Id, game, (id, g) => game);

            return(game);
        }
Пример #4
0
 public GameEndedEventArgs(Domain.Game game, string winnerUserId)
 {
     Game         = game ?? throw new ArgumentNullException(nameof(game));
     WinnerUserId = winnerUserId;
 }