Example #1
0
        public bool Equals(GameUser gameUser)
        {
            bool result = this.UserId == gameUser.UserId &&
                   this.UserName == gameUser.UserName &&
                   new CollectionHaveSameElementsComparison<Guid>(this.Weapons, gameUser.Weapons).DoIt();

            return result;
        }
        public string Create()
        {
            Guid gameQueueId = Guid.NewGuid();
            string userId = this.CurrentUserId;

            if (string.IsNullOrEmpty(userId))
            {
                throw new ServiceException("User does not exist. User Id: " + userId);
            }

            UserProfile profile = this.userRepository.GetUser(CurrentUserId);

            if (profile == null)
            {
                throw new ServiceException("User does not exist. User Id: " + userId);
            }

            GameUser user = new GameUser()
            {
                UserId = profile.Id,
                UserName = profile.DisplayName,
                Weapons = new List<Guid>()
            };

            GameQueue gameQueue = new GameQueue()
            {
                Id = gameQueueId,
                CreationTime = DateTime.UtcNow,
                Status = QueueStatus.Waiting,
                Users = new List<GameUser>() { user }
            };

            this.gameRepository.AddOrUpdateGameQueue(gameQueue);

            return gameQueueId.ToString();
        }
        public void AddUserToGameQueue(string userId, Guid gameQueueId)
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentException("userId");
            }

            if (gameQueueId == null || gameQueueId == Guid.Empty)
            {
                throw new ArgumentException("Game Queue Id cannot be null or empty");
            }

            var currentGameQueue = this.gameQueueContainer.Get(gameQueueId.ToString());

            if (currentGameQueue == null)
            {
                throw new InvalidOperationException(string.Format("Game Queue does not exist: {0}", gameQueueId));
            }

            var user = this.userContainer.Get(userId);
            var gameUser = new GameUser
            {
                UserId = user.Id,
                UserName = user.DisplayName
            };

            if (!currentGameQueue.Users.Any(u => u.UserId == gameUser.UserId))
            {
                currentGameQueue.Users.Add(gameUser);
            }

            this.gameQueueContainer.Save(gameQueueId.ToString(), currentGameQueue);
        }
        private Game CreateNewGame(IGameRepository gameRepository, params string[] userIds)
        {
            Guid gameID = Guid.NewGuid();

            Game game = new Game() { Id = gameID, ActiveUser = "******", GameActions = new List<GameAction>(), Users = new List<GameUser>() };

            foreach (string userId in userIds)
            {
                GameUser user = new GameUser() { UserId = userId };
                game.Users.Add(user);
            }

            gameRepository.AddOrUpdateGame(game);

            return game;
        }