public async void StartGame()
    {
        StartGameRequest startGameRequest = new StartGameRequest();
        await networkConnector.SendMessageAsync(startGameRequest, CancellationToken.None);

        scene.ChangeScene(Scenes.GAME);
    }
Example #2
0
 void Start()
 {
     starButton.onClick.AddListener(OnStartButtonClick);
     exitButton.onClick.AddListener(OnExitButtonClick);
     exitRoomRequest  = GetComponent <ExitRoomRequest>();
     startGameRequest = GetComponent <StartGameRequest>();
 }
        /// <summary>
        /// Instructs the PlayFab game server hosting service to instantiate a new Game Server Instance
        /// </summary>
        public static async Task <PlayFabResult <StartGameResponse> > StartGameAsync(StartGameRequest request, object customData = null)
        {
            if (PlayFabSettings.DeveloperSecretKey == null)
            {
                throw new Exception("Must have PlayFabSettings.DeveloperSecretKey set to call this method");
            }

            var httpResult = await PlayFabHttp.DoPost("/Matchmaker/StartGame", request, "X-SecretKey", PlayFabSettings.DeveloperSecretKey);

            if (httpResult is PlayFabError)
            {
                var error = (PlayFabError)httpResult;
                if (PlayFabSettings.GlobalErrorHandler != null)
                {
                    PlayFabSettings.GlobalErrorHandler(error);
                }
                return(new PlayFabResult <StartGameResponse> {
                    Error = error, CustomData = customData
                });
            }

            var resultRawJson = (string)httpResult;
            var resultData    = JsonWrapper.DeserializeObject <PlayFabJsonSuccess <StartGameResponse> >(resultRawJson);
            var result        = resultData.data;

            return(new PlayFabResult <StartGameResponse> {
                Result = result, CustomData = customData
            });
        }
        /// <inheritdoc/>
        public async Task<PlayerBoardViewModel> StartNewGameAsync(StartGameRequest request)
        {
            DifficultyLevel level = factory.CreateLevel(request.LevelName);

            var player = await playerRepository.FirstOrDefaultAsync(request.PlayerId);

            if(player == null)
            {
                throw new PlayerNotFoundException();
            }

            await boardRepository.DeleteAsync(board => board.PlayerId == player.Id);

            var templateBoardDb = await service.GetRandomTemplateBoardByLevelAsync(level);

            var templateBoard = mapper.Map<TemplateBoard>(templateBoardDb);

            var playerBoard = new PlayerBoard(templateBoard)
            {
                PlayerId = player.Id
            };

            var playerBoardDb = mapper.Map<PlayerBoardDbModel>(playerBoard);

            playerBoard.BoardId = await boardRepository.InsertAndGetIdAsync(playerBoardDb);

            return mapper.Map<PlayerBoardViewModel>(playerBoard);
        }
        /// <summary>
        /// Instructs the PlayFab game server hosting service to instantiate a new Game Server Instance
        /// </summary>
        public async Task <PlayFabResult <StartGameResponse> > StartGameAsync(StartGameRequest request, object customData = null, Dictionary <string, string> extraHeaders = null)
        {
            var developerSecretKey = request.AuthenticationContext?.DeveloperSecretKey ?? (authenticationContext?.DeveloperSecretKey ?? PlayFabSettings.DeveloperSecretKey);

            if (developerSecretKey == null)
            {
                throw new PlayFabException(PlayFabExceptionCode.DeveloperKeyNotSet, "DeveloperSecretKey is not found in Request, Server Instance or PlayFabSettings");
            }

            var httpResult = await PlayFabHttp.DoPost("/Matchmaker/StartGame", request, "X-SecretKey", developerSecretKey, extraHeaders, apiSettings);

            if (httpResult is PlayFabError)
            {
                var error = (PlayFabError)httpResult;
                PlayFabSettings.GlobalErrorHandler?.Invoke(error);
                return(new PlayFabResult <StartGameResponse> {
                    Error = error, CustomData = customData
                });
            }

            var resultRawJson = (string)httpResult;
            var resultData    = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <PlayFabJsonSuccess <StartGameResponse> >(resultRawJson);
            var result        = resultData.data;

            return(new PlayFabResult <StartGameResponse> {
                Result = result, CustomData = customData
            });
        }
Example #6
0
    private void Start()
    {
        // 本地玩家与敌方玩家Text初始化
        localPlayerUsername   = transform.Find("BluePanel/Username").GetComponent <Text>();
        localPlayerTotalCount = transform.Find("BluePanel/TotalCount").GetComponent <Text>();
        localPlayerWinCount   = transform.Find("BluePanel/WinCount").GetComponent <Text>();
        enemyPlayerUsername   = transform.Find("RedPanel/Username").GetComponent <Text>();
        enemyPlayerTotalCount = transform.Find("RedPanel/TotalCount").GetComponent <Text>();
        enemyPlayerWinCount   = transform.Find("RedPanel/WinCount").GetComponent <Text>();

        // 获取敌我面板,开始,退出按钮的引用
        bluePanel   = transform.Find("BluePanel");
        redPanel    = transform.Find("RedPanel");
        startButton = transform.Find("StartButton");
        exitButton  = transform.Find("ExitButton");

        // 基本信息的方法注册监听
        transform.Find("StartButton").GetComponent <Button>().onClick.AddListener(OnStartClick);
        transform.Find("ExitButton").GetComponent <Button>().onClick.AddListener(OnExitClick);

        quitRoomRequest  = GetComponent <QuitRoomRequest>();
        startGameRequest = GetComponent <StartGameRequest>();

        EnterAnim();
    }
        /// <summary>
        /// Instructs the PlayFab game server hosting service to instantiate a new Game Server Instance
        /// </summary>
        public static async Task <PlayFabResult <StartGameResponse> > StartGameAsync(StartGameRequest request, object customData = null, Dictionary <string, string> extraHeaders = null)
        {
            if (PlayFabSettings.staticSettings.DeveloperSecretKey == null)
            {
                throw new PlayFabException(PlayFabExceptionCode.DeveloperKeyNotSet, "Must have PlayFabSettings.staticSettings.DeveloperSecretKey set to call this method");
            }

            var httpResult = await PlayFabHttp.DoPost("/Matchmaker/StartGame", request, "X-SecretKey", PlayFabSettings.staticSettings.DeveloperSecretKey, extraHeaders);

            if (httpResult is PlayFabError)
            {
                var error = (PlayFabError)httpResult;
                PlayFabSettings.GlobalErrorHandler?.Invoke(error);
                return(new PlayFabResult <StartGameResponse> {
                    Error = error, CustomData = customData
                });
            }

            var resultRawJson = (string)httpResult;
            var resultData    = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <PlayFabJsonSuccess <StartGameResponse> >(resultRawJson);
            var result        = resultData.data;

            return(new PlayFabResult <StartGameResponse> {
                Result = result, CustomData = customData
            });
        }
Example #8
0
        public HttpResponseMessage Start([ModelBinder(typeof(JsonNetModelBinder))] StartGameRequest request)
        {
            var room = Data.FindRoom(request.GameName);

            if (room == null)
            {
                var startGameFailedResponse = new StartGameResponse()
                {
                    Result = false
                };
                return(new JsonNetResponseMessage(startGameFailedResponse));
            }

            if (room.Game != null)
            {
                var startGameFailedResponse = new StartGameResponse()
                {
                    Result = false
                };
                return(new JsonNetResponseMessage(startGameFailedResponse));
            }

            room.Game = new Game(room.Players, room.GameSetting.Difficultly);

            var response = new StartGameResponse()
            {
                Result = true
            };

            return(new JsonNetResponseMessage(response));
        }
Example #9
0
    // Use this for initialization
    private void Start()
    {
        localPlayerUserName = transform.Find("BluePanel/UserName").GetComponent <Text>();
        localPlayerWinRate  = transform.Find("BluePanel/WinRate").GetComponent <Text>();

        enemyPlayerUserName = transform.Find("RedPanel/UserName").GetComponent <Text>();
        enemyPlayerWinRate  = transform.Find("RedPanel/WinRate").GetComponent <Text>();

        bluePanel = transform.Find("BluePanel");
        redPanel  = transform.Find("RedPanel");
        startGame = transform.Find("StartGame");
        exitRoom  = transform.Find("ExitRoom");

        startButtonAnime = transform.Find("StartGame").GetComponent <Animator>();
        exitButtonAnime  = transform.Find("ExitRoom").GetComponent <Animator>();

        startButton = transform.Find("StartGame").GetComponent <Button>();
        exitButton  = transform.Find("ExitRoom").GetComponent <Button>();
        startButton.onClick.AddListener(OnStartClick);
        exitButton.onClick.AddListener(OnExitClick);

        quitRoomRequest  = GetComponent <QuitRoomRequest>();
        startGameRequest = GetComponent <StartGameRequest>();

        EnterAnime();
    }
Example #10
0
        public async Task <ActionResult> PostStartGameAsync(Guid gameId, StartGameRequest request)
        {
            var command = new StartGameCommand(gameId, request.StartTime);
            await _startGameCommandHandler.HandleAsync(command);

            return(Ok());
        }
        public async Task <ActionResult> Start()
        {
            var request = new StartGameRequest();
            var result  = await _mediator.Send(request);

            return(ProcessResult(result));
        }
Example #12
0
        public async Task StartGame(StartGameRequest startGameRequest)
        {
            try
            {
                var response = await _hubService.StartGame(startGameRequest.RoomCode);

                if (response.GetType() == typeof(HubErrorResponse))
                {
                    await SendErrorResponseToCaller((HubErrorResponse)response);

                    return;
                }

                var successResponse = (HubSuccessResponse)response;
                var data            = (StartGameResponse)successResponse.Data;

                // TODO: do we need this? await SendSuccessResponseToCaller( successResponse );
                await SendSuccessResponseToGroup(data.GroupName, successResponse);
            }
            catch (Exception ex)
            {
                await SendErrorResponseToCaller(new HubErrorResponse
                {
                    Message = ex.Message,
                    Method  = "StartGame"
                });
            }
        }
Example #13
0
        /// <summary>
        /// Instructs the PlayFab game server hosting service to instantiate a new Game Server Instance
        /// </summary>
        public void StartGame(StartGameRequest request, Action <StartGameResponse> resultCallback, Action <PlayFabError> errorCallback, object customData = null, Dictionary <string, string> extraHeaders = null)
        {
            var context      = (request == null ? null : request.AuthenticationContext) ?? authenticationContext;
            var callSettings = apiSettings ?? PlayFabSettings.staticSettings;

            PlayFabHttp.MakeApiCall("/Matchmaker/StartGame", request, AuthType.DevSecretKey, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this);
        }
 private void Awake()
 {
     Init();
     UGUIEventListener.Get(StartButton).onClick = StartGameClick;
     UGUIEventListener.Get(ExitButton).onClick  = CloseRoomClick;
     quitRoomRequest  = GetComponent <QuitRoomRequest>();
     startGameRequest = GetComponent <StartGameRequest>();
 }
Example #15
0
        public Task StartGame(StartGameRequest request)
        {
            _started = true;
            _lobbyTimeoutTimer.Stop();
            _lobbyUpdateTimer.Stop();

            return(SendStartedResponse());
        }
        /// <summary>
        /// Instructs the PlayFab game server hosting service to instantiate a new Game Server Instance
        /// </summary>
        public static void StartGame(StartGameRequest request, Action <StartGameResponse> resultCallback, Action <PlayFabError> errorCallback, object customData = null, Dictionary <string, string> extraHeaders = null)
        {
            if (PlayFabSettings.DeveloperSecretKey == null)
            {
                throw new PlayFabException(PlayFabExceptionCode.DeveloperKeyNotSet, "Must have PlayFabSettings.DeveloperSecretKey set to call this method");
            }

            PlayFabHttp.MakeApiCall("/Matchmaker/StartGame", request, AuthType.DevSecretKey, resultCallback, errorCallback, customData, extraHeaders);
        }
    /// <summary>
    /// Sends the game start message to the server.
    /// </summary>
    private void SendGameStartMessage()
    {
        Debug.Log("Sending request to start the game");
        StartGameRequest startGameRequest = new StartGameRequest();

        startGameRequest.gameId       = gameId;
        startGameRequest.playerNumber = playerNumber;
        serverMessageDispatcher.SendMessage(startGameRequest);
    }
Example #18
0
        private Task StartGame(SocketBase socket)
        {
            StartGameRequest startGameRequest = socket as StartGameRequest ?? throw new ArgumentNullException(nameof(socket));

            List <Player> players = _lobbyManager.GetPlayers();

            _gameManager.InitializeGame(players);
            return(_lobbyManager.StartGame(startGameRequest));
        }
Example #19
0
        public Task <StartGameReply> StartGame(ServerCallContext context, StartGameRequest request)
        {
            bool gameStarted = manager.StartGame();
            var  reply       = new StartGameReply.Builder {
                Result = gameStarted
            }.BuildPartial();

            return(Task.FromResult(reply));
        }
Example #20
0
        public GameDto StartNewGame(StartGameRequest request)
        {
            var game = _gameManager.AddGame(request.GameName,
                                            new Player {
                Id = new Guid(request.OwnerId), Name = request.OwnerName
            });

            return(ConvertGameToGameResource(game));
        }
Example #21
0
        /// <summary>
        /// Instructs the PlayFab game server hosting service to instantiate a new Game Server Instance
        /// </summary>
        public static void StartGame(StartGameRequest request, Action <StartGameResponse> resultCallback, Action <PlayFabError> errorCallback, object customData = null)
        {
            if (PlayFabSettings.DeveloperSecretKey == null)
            {
                throw new Exception("Must have PlayFabSettings.DeveloperSecretKey set to call this method");
            }

            PlayFabHttp.MakeApiCall("/Matchmaker/StartGame", request, AuthType.DevSecretKey, resultCallback, errorCallback, customData);
        }
 private void Start()
 {
     LocalPlayerUserName  = transform.Find("self/NameText").GetComponent <Text>();
     RemotePlayerUserName = transform.Find("opponent/RemotePlayer/NameText").GetComponent <Text>();
     WaitText             = transform.Find("opponent/WaitText").GetComponent <Text>();
     transform.Find("ExitRoom").GetComponent <Button>().onClick.AddListener(OnExitRoomClick);
     transform.Find("Begin").GetComponent <Button>().onClick.AddListener(OnBeginClick);
     quitRoomRequest  = GetComponent <QuitRoomRequest>();
     startGameRequest = GetComponent <StartGameRequest>();
     gameObject.SetActive(true);
 }
 private void Start()
 {
     //组件初始化
     _canvasGroup      = this.GetComponent <CanvasGroup>();
     creatRoomRequest  = this.GetComponent <CreatRoomRequest>();
     _quitRoomRequest  = this.GetComponent <QuitRoomRequest>();
     _startGameRequest = this.GetComponent <StartGameRequest>();
     //注册点击事件
     startGameBtn.onClick.AddListener(delegate() { StartGameButtonClicked(); });
     exitAndDeleteRoomBtn.onClick.AddListener(delegate() { ExitAndDeleteRoomButtonClicked(); });
 }
        /// <summary>
        /// Instructs the PlayFab game server hosting service to instantiate a new Game Server Instance
        /// </summary>
        public void StartGame(StartGameRequest request, Action <StartGameResponse> resultCallback, Action <PlayFabError> errorCallback, object customData = null, Dictionary <string, string> extraHeaders = null)
        {
            var context      = (request == null ? null : request.AuthenticationContext) ?? authenticationContext;
            var callSettings = apiSettings ?? PlayFabSettings.staticSettings;

            if (string.IsNullOrEmpty(callSettings.DeveloperSecretKey))
            {
                throw new PlayFabException(PlayFabExceptionCode.DeveloperKeyNotSet, "Must set DeveloperSecretKey in settings to call this method");
            }
            PlayFabHttp.MakeApiCall("/Matchmaker/StartGame", request, AuthType.DevSecretKey, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this);
        }
Example #25
0
        public void RegisterRequest_AfterStartGame_ShouldNotThrowEx()
        {
            var req = new StartGameRequest(_serverUrl);

            req.Execute();

            string id   = "123456789";
            string name = "Mr Bob";

            var req2 = new RegistrationRequest(_serverUrl, id, name);

            req2.Execute();
        }
Example #26
0
    public async Task <StartGameResponse> StartGame(string lobbyName)
    {
        MessageListener <StartGameResponse> startGameResponseListener = new MessageListener <StartGameResponse>();

        startGameResponseListener.Subscribe(_messageProcessor);
        StartGameRequest startGameRequest = new StartGameRequest(Guid.NewGuid(), lobbyName, _loggedInUser.Id);
        await _networkConnector.SendMessageAsync(startGameRequest, CancellationToken.None);

        StartGameResponse startGameResponse = await startGameResponseListener.ReceiveMessageAsync();

        startGameResponseListener.Unsubscribe();
        return(startGameResponse);
    }
Example #27
0
        public async Task <ActionResult> Start(StartGameRequest request)
        {
            var playerIds = new List <PlayerId>();

            foreach (var str in request.Players)
            {
                playerIds.Add(new PlayerId(str));
            }

            //Send a SendCommand command containing a StartGame GameCommand to the GameManagerActor

            return(Ok(new { Result = feedback.GetType().Name }));
        }
Example #28
0
        /// <summary>
        /// Sends a request to the server to start a game with another client.
        /// The other client will receive a start game request event and must accept or deny the request
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HandleStartGameRequestEvent(object sender, StringEventArgs e)
        {
            var target  = e.Data;
            var request = new StartGameRequest()
            {
                TargetClientMac = target, RequestingClientMac = Client.ClientId, RequestingClientDisplayName = displayName
            };
            var msg = new Message()
            {
                MessageId = StartGameRequest.MessageId, Contents = request
            };

            Events.OnSendMessageEvent(this, new ByteArrayEventArgs(msg.Serialize()));
        }
Example #29
0
        public async Task <StartGameResponse> StartGameAsync(StartGameRequest request)
        {
            var response = ServiceMessageFactory <StartGameResponse> .CreateFrom(request);

            var initializeGameRequest = ServiceMessageFactory <InitializeGameRequest> .CreateFrom(request);

            initializeGameRequest.GameDefinitionId = request.GameDefinitionId;
            initializeGameRequest.NumberOfPlayers  = request.PlayerCount;

            var initializeGameResponse = await gamePlayEngine.InitializeGameAsync(initializeGameRequest);

            response.GameSessionId = initializeGameResponse.GameSession.Id;
            return(response);
        }
Example #30
0
        public IActionResult RestartGame(StartGameRequest startGameRequest)
        {
            if (game.GameState != GameState.GameOver)
            {
                return(BadRequest("Game not finished"));
            }
            if (config["secretCode"] != startGameRequest.SecretCode)
            {
                return(BadRequest("Secret code doesn't match, unable to start game."));
            }

            game.Restarting();

            return(Ok());
        }
Example #31
0
 public Task<StartGameReply> StartGame(ServerCallContext context, StartGameRequest request)
 {
     bool gameStarted = manager.StartGame();
     var reply = new StartGameReply.Builder { Result = gameStarted }.BuildPartial();
     return Task.FromResult(reply);
 }