Exemplo n.º 1
0
        public PartialViewResult NextQuestion()
        {
            var gameState = Session["GameState"] as GamePlayState;


            var question = gameState.QuestionsLeft.FirstOrDefault();

            if (question != null)
            {
                var model = new QuestionViewModel();
                model.Question = question;
                model.Answers  = question.Answers.ToList();
                model.Answers.Shuffle();
                model.Total = gameState.QuestionTotalCount;
                model.Index = gameState.QuestionTotalCount - gameState.QuestionsLeft.Count + 1;

                gameState.CurrentQuestion = model;

                return(PartialView("_Question", model));
            }


            var game   = QuizDb.QuizGames.SingleOrDefault(x => x.Id == gameState.Game.Id);
            var player = QuizDb.GamePlayers.SingleOrDefault(x => x.Id == gameState.Player.Id);

            var statisticsService = new GameStatisticsService(gameState.Quiz.Id, player.UserId);

            var statistics = statisticsService.GetStatistics(game.Id);

            return(PartialView("_EndGame", statistics));
        }
Exemplo n.º 2
0
        public ActionResult Total(Guid?id)
        {
            var quiz = GetQuiz(id);
            var user = GetCurrentUser();

            var service = new GameStatisticsService(quiz.Id, user.Id);

            var myGames = service.GetTotalGames();

            var model = new QuizGameStatisticsViewModel();

            model.Quiz = quiz;

            foreach (var game in myGames)
            {
                if (game.Players.Any())
                {
                    var stat = service.GetStatistics(game.Id, game.Players.First().UserId);
                    if (stat != null)
                    {
                        model.Games.Add(stat);
                    }
                }
            }


            return(View(model));
        }
Exemplo n.º 3
0
        public IHttpActionResult GetGameList(string userId)
        {
            var model = new GameList();

            model.Games = new List <GameSummary>();

            var quizzes = quizDb.Quizzes.Where(x => x.IsPubslished).ToList();

            foreach (var quiz in quizzes)
            {
                var statisticsService = new GameStatisticsService(quiz.Id, userId);

                // TODO: Liste auswerten
                var gameModel = new GameSummary();

                gameModel.Name           = quiz.Name;
                gameModel.QuizId         = quiz.Id;
                gameModel.QuestionCount  = statisticsService.GetQuestions().Count;
                gameModel.MyGameCount    = statisticsService.GetMyGames().Count;        // wie oft habe ich gespielt
                gameModel.TotalGameCount = statisticsService.GetTotalGames().Count;

                var bestGame = statisticsService.GetBestGame();
                if (bestGame != null)
                {
                    gameModel.BestGame = new GameApproach
                    {
                        PlayDateTime = bestGame.Game.CreatedAt,
                        Rank         = 0,
                        Score        = bestGame.CorrectAnswerCount
                    };
                }

                var lastGame = statisticsService.GetLastGame();
                if (lastGame != null)
                {
                    gameModel.LastGame = new GameApproach
                    {
                        PlayDateTime = lastGame.Game.CreatedAt,
                        Rank         = 0,
                        Score        = lastGame.CorrectAnswerCount
                    };
                }

                model.Games.Add(gameModel);
            }



            return(Ok(model));
        }
Exemplo n.º 4
0
        public IHttpActionResult GetQuizGameResult(Guid?gameId, Guid?playerId)
        {
            var QuizDb = new QuestDbContext();

            var result = new QuizGameResult();

            if (gameId.HasValue && playerId.HasValue)
            {
                var game   = QuizDb.QuizGames.SingleOrDefault(x => x.Id == gameId.Value);
                var player = QuizDb.GamePlayers.SingleOrDefault(x => x.Id == playerId.Value);

                // Die Antwort

                if (game != null && player != null)
                {
                    result.GameId   = game.Id;
                    result.PlayerId = player.Id;
                    result.QuizId   = game.Levels.First().Quiz.Id;

                    var service = new GameStatisticsService(result.QuizId, player.UserId);

                    var statistics = service.GetStatistics(game.Id);
                    result.QuestionCount      = statistics.TotalQuestionCount;
                    result.CorrectAnswerCount = statistics.CorrectAnswerCount;
                    result.PersonalRank       = service.GetPersonalRank(result.CorrectAnswerCount);
                    result.TotalRank          = service.GetTotalRank(result.CorrectAnswerCount);

                    result.Message = "OK";
                }
                else
                {
                    var sb = new StringBuilder();
                    if (game == null)
                    {
                        sb.Append("Spiel fehlt");
                    }
                    if (player == null)
                    {
                        sb.Append("Spieler fehlt");
                    }
                    result.Message = sb.ToString();
                }
            }
            else
            {
                result.Message = "Falsche Parameter";
            }

            return(Ok(result));
        }
Exemplo n.º 5
0
        // GET: Quiz/Statistics
        public ActionResult Personal(Guid?id)
        {
            var quiz = GetQuiz(id);
            var user = GetCurrentUser();

            var service = new GameStatisticsService(quiz.Id, user.Id);

            var myGames = service.GetMyGames();

            var model = new QuizGameStatisticsViewModel();

            model.Quiz = quiz;

            foreach (var game in myGames)
            {
                model.Games.Add(service.GetStatistics(game.Id));
            }


            return(View(model));
        }
 void Start()
 {
     gameStatisticsService = FindObjectOfType<GameStatisticsService>();
     webSocketService = FindObjectOfType<WebSocketService>();
     webSocketService.RegisterCommand(BossStatusUpdateDTO.COMMAND_NAME, BossStatusUpdateCallback, typeof(BossStatusUpdateDTO));
 }
 private void InitalizeDependencies()
 {
     HypeController.OnHypeAttack += HypeAttackEventHandler;
     gameControlService = FindObjectOfType<GameControlService>();
     gameStatisticsService = FindObjectOfType<GameStatisticsService>();
     playerPropertyService = FindObjectOfType<PlayerPropertyService>();
     bossStatusService = FindObjectOfType<BossStatusService>();
     bossStatusService.OnBossDead += BossDeadEventHandler;
 }