Exemple #1
0
        public void GetScore(string player, string RoomID)
        {
            GameModel game  = GameManagerModel.GetInstance().GetGame(RoomID);
            string    score = game.GetPlayer(player).Points.ToString();

            Clients.Caller.sendScore(score);
        }
Exemple #2
0
        public ActionResult JoinRoom(NewRoomModel newRoom)
        {
            ViewBag.RoomID   = newRoom.ID;
            ViewBag.Nickname = newRoom.Nickname;
            GameManagerModel gameModel = GameManagerModel.GetInstance();

            ViewBag.Players = gameModel.GetGame(newRoom.ID).PlayerNickNames.Values;
            return(View("NewRoom"));
        }
Exemple #3
0
        private void HandleTransitionTimer(string roomId)
        {
            GameModel game        = GameManagerModel.GetInstance().GetGame(roomId);
            string    newQuestion = game.GetQuestion();

            if (newQuestion == null)
            {
                Clients.Group(roomId).endGame();
            }
            else
            {
                Clients.Group(roomId).newQuestion(newQuestion);
            }
        }
Exemple #4
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            // The order of this is important
            RouteTable.Routes.MapHubs();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();

            GameManagerModel.GetInstance();
        }
Exemple #5
0
        public ActionResult StartGame(StartGameModel startGame)
        {
            ViewBag.Player         = startGame.PlayerName;
            ViewBag.RoomID         = startGame.RoomID;
            ViewBag.QuestionNumber = 1;
            ViewBag.Question       = startGame.Question;
            GameManagerModel gameModel = GameManagerModel.GetInstance();

            try
            {
                ViewBag.Players = gameModel.GetGame(startGame.RoomID).PlayerNickNames.Values;
            }
            catch (Exception) { }
            return(View());
        }
Exemple #6
0
        public void SendChoice(string player, string playerChoice, string roomId)
        {
            GameModel   game   = GameManagerModel.GetInstance().GetGame(roomId);
            PlayerModel result = game.SendAnswer(player, playerChoice);

            if (result != null)
            {
                Clients.Group(roomId).showResult(result);
                Timer transitionTimer = new Timer(10000);
                transitionTimer.Elapsed  += (source, e) => HandleTransitionTimer(roomId);
                transitionTimer.Enabled   = true;
                transitionTimer.AutoReset = false;
                transitionTimer.Start();
            }
        }
Exemple #7
0
        public void JoinRoom(string nickname, string roomID)
        {
            GameManagerModel gameManager = GameManagerModel.GetInstance();
            GameModel        game        = gameManager.GetGame(roomID);

            if (game == null)
            {
                Clients.Caller.throwExeption();
            }
            else
            {
                game.AddPlayer(new PlayerModel(nickname, Context.ConnectionId));
                Clients.Caller.submitJoinRoomForm();
            }
        }
Exemple #8
0
        public async Task NewRoom(string nickname)
        {
            GameManagerModel gameManager = GameManagerModel.GetInstance();

            Random      random       = new Random();
            int         randomNumber = random.Next(0, 9999);
            string      newID        = randomNumber.ToString("D4");
            GameModel   newGame      = new GameModel(newID, 5); //change to new input textbox!
            PlayerModel newPlayer    = new PlayerModel(nickname, Context.ConnectionId);

            newGame.AddPlayer(newPlayer);
            gameManager.AddGame(newGame);

            await Groups.Add(Context.ConnectionId, newID);

            Clients.Caller.submitNewRoomForm(newID);
        }
Exemple #9
0
        public ActionResult EndGame(EndGameModel endGame)
        {
            ViewBag.Player = endGame.Nickname;
            ViewBag.RoomID = endGame.RoomId;
            GameModel   game       = GameManagerModel.GetInstance().GetGame(endGame.RoomId);
            PlayerModel thisPlayer = game.GetPlayer(endGame.Nickname);
            PlayerModel winner     = game.GetWinner();

            if (thisPlayer.NickName.Equals(winner.NickName))
            {
                ViewBag.MostLikely = "You won!";
            }
            else
            {
                ViewBag.MostLikely = "The winner is " + winner.NickName + "!";
            }
            ViewBag.MostPoints = "with " + winner.Points;
            return(View());
        }
Exemple #10
0
        public void StartGame(string roomID)
        {
            string firstQuestion = GameManagerModel.GetInstance().GetGame(roomID).GetQuestion();

            Clients.Group(roomID).startGame(firstQuestion);
        }