public IEnumerable <Question> GenerateGameQuestions(int uniqueKey)
        {
            GameRepository gameRepo       = new GameRepository(_context);
            int            gameRoomId     = gameRepo.GetGameroomIdByUniqueKey(uniqueKey);
            var            gameCategories = _context.CategoryGames.Include(a => a.Category).Where(a => a.GameId == gameRoomId).Select(a => a.Category).Include(a => a.Questions).ToList();

            List <Question> lowDifficultyQuestions    = new List <Question>();
            List <Question> mediumDifficultyQuestions = new List <Question>();
            List <Question> highDifficultyQuestions   = new List <Question>();

            List <Question> gameQuestions = new List <Question>();

            foreach (var auxCategory in gameCategories)
            {
                lowDifficultyQuestions.AddRange(auxCategory.Questions.Where(a => a.QuestionDifficulty == 1));
                mediumDifficultyQuestions.AddRange(auxCategory.Questions.Where(a => a.QuestionDifficulty == 2));
                highDifficultyQuestions.AddRange(auxCategory.Questions.Where(a => a.QuestionDifficulty == 3));
            }

            gameQuestions.Add(SelectQuestionByDifficulty(lowDifficultyQuestions));
            gameQuestions.Add(SelectQuestionByDifficulty(mediumDifficultyQuestions));
            gameQuestions.Add(SelectQuestionByDifficulty(highDifficultyQuestions));

            SelectQuestionByCategory(gameCategories, gameQuestions);

            gameQuestions.ForEach(a => a.Category = null);
            return(gameQuestions);
        }
Example #2
0
        public void UpdatePlayerScore(int uniqueKey, String playerName, int score)
        {
            GameRepository gameRepo   = new GameRepository(_context);
            int            gameRoomId = gameRepo.GetGameroomIdByUniqueKey(uniqueKey);
            var            players    = _context.Players.Where(a => a.GameroomId == gameRoomId).ToList();

            if (Validation.UpdateScoreValidation(players, playerName))
            {
                var player = _context.Players.Where(a => a.GameroomId == gameRoomId).ToList()
                             .Where(a => a.PlayerName == playerName).First();
                player.PlayerScore += score;
                Edit(player);
            }
            else
            {
                throw new Exception("Player not found!");
            }
        }
Example #3
0
        public void Create(PlayerUniqueKey playerUniqueKey)
        {
            GameRepository gameRepo = new GameRepository(_context);
            Player         player   = new Player
            {
                PlayerName  = playerUniqueKey.PlayerName,
                PlayerScore = 0,
                GameroomId  = gameRepo.GetGameroomIdByUniqueKey(playerUniqueKey.UniqueKey)
            };

            var players = _context.Players.Where(a => a.GameroomId == player.GameroomId).ToList();

            if (Validation.CreatePlayerValidation(players, player))
            {
                _context.Players.Add(player);
                _context.SaveChanges();
            }
            else
            {
                throw new Exception("Nume deja existent!");
            }
        }