Ejemplo n.º 1
0
        /*  public async override Task OnDisconnectedAsync(Exception e){
         *
         *
         * }
         */

        public async Task StartGame()
        {
            var user = await GetAppUser();

            if (_games.FindGameByUser(user) != null)
            {
                //In the game allready.
            }
            else
            {
                Player p = new Player {
                    User = user
                };

                if (_games.MatchPlayer(p))
                {
                    Game g = _games.FindGameByUser(user);

                    GameViewModel gameFromPerspectiveOfBlack = new GameViewModel(g, user);
                    await Clients.Caller.SendAsync("StartedGameAsBlack", new { game = gameFromPerspectiveOfBlack });

                    GameViewModel gameFromPerspectiveOfWhite = new GameViewModel(g, g.White.User);
                    var           whiteUserId       = _games.FindGameByUser(user).White.User.Id;
                    var           whiteConnectionId = _map[whiteUserId];
                    await Clients.Client(whiteConnectionId).SendAsync("StartedGameAsWhite", new { game = gameFromPerspectiveOfWhite });
                }
            }
        }
        public async Task <IActionResult> PageInitializationData()
        {
            var user = await GetAppUser();

            var game          = _games.FindGameByUser(user);
            var gameViewModel = (GameViewModel)null;

            if (game != null)
            {
                gameViewModel = new GameViewModel(game, user);
            }

            return(Json(new {
                game = gameViewModel
            }));
        }