コード例 #1
0
ファイル: GameController.cs プロジェクト: thudjek/Bela
        public async Task <JsonResult> GetCurrentData(int gameId)
        {
            var userId = User.GetUserId();
            var model  = await _gameService.GetCurrentRoundData(gameId, userId);

            TimerBela timer = TimerHelper.GetTimerForGameId(Convert.ToInt32(gameId));

            model.RemainingTime = timer != null?TimerHelper.GetTimerForGameId(Convert.ToInt32(gameId)).GetRemainingTime() : 0;

            return(Json(model));
        }
コード例 #2
0
ファイル: RoomController.cs プロジェクト: thudjek/Bela
        private void OnTimerElapsed(object sender, ElapsedEventArgs e)
        {
            var       connString = _configuration.GetConnectionString("DefaultConnection");
            TimerBela timer      = sender as TimerBela;
            var       gameId     = timer.GameId;
            var       result     = _gameService.LeaveGameTimerElapsed(gameId, connString);

            if (result.IsSucessfull)
            {
                var quitUsername      = result.Values[0] as string;
                var opponent1Username = result.Values[1] as string;
                var opponent2Username = result.Values[2] as string;
                _gameHubContext.Clients.Group("Game" + gameId.ToString()).SendAsync("TimerElapsed", quitUsername, opponent1Username, opponent2Username);
                _lobbyHubContext.Clients.All.SendAsync("UpdateRoomList");
            }
        }
コード例 #3
0
ファイル: RoomController.cs プロジェクト: thudjek/Bela
        public async Task <JsonResult> TryStartGame(int roomId)
        {
            var result = await _roomService.CanGameBeStarted(roomId);

            if (result.IsSucessfull)
            {
                result = await _gameService.IsRoomInGame(roomId);

                if (!result.IsSucessfull)
                {
                    result = await _gameService.StartGame(roomId);

                    if (result.IsSucessfull)
                    {
                        await _roomHubContext.Clients.Group("Room" + roomId.ToString()).SendAsync("GameStarted");

                        await _lobbyHubContext.Clients.All.SendAsync("UpdateRoomList");

                        var       gameId = (int)result.Values[0];
                        TimerBela timer  = new TimerBela(18000, OnTimerElapsed, gameId);
                        TimerHelper.AddTimerForGameId(gameId, timer);
                        timer.Start();
                        return(Json(new { success = true }));
                    }
                    else
                    {
                        return(Json(new { error = result.Errors[0] }));
                    }
                }
                else
                {
                    return(Json(new { error = result.Errors[0] }));
                }
            }
            else
            {
                return(Json(new { error = result.Errors[0] }));
            }
        }