Exemplo n.º 1
0
 /// <summary>
 /// End game when one of players won
 /// </summary>
 /// <param name="data"></param>
 public void EndGame(GameEndResponse data)
 {
     PlayerStatsManager.Instance.SetPlayerStats(data.PlayerStats);
     FieldManager.Instance.CanControl = false;
     PlayerManager.Instance.PlayersDead();
     PlayerManager.Instance.ShowPlayerWonOrLost(data.PlayerWon);
 }
Exemplo n.º 2
0
    IEnumerator GameEndServer()
    {
        Debug.Log("Load from: " + gameEndUrl + "?pid=" + GameManager.instance.pid + "&gid=" + GameManager.instance.gid);

        UnityWebRequest www = UnityWebRequest.Get(gameEndUrl + "?pid=" + GameManager.instance.pid + "&gid=" + GameManager.instance.gid);

        yield return(www.SendWebRequest());

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log(www.error);
            // Show error:
            debugText.text = "NETWORK ERROR:\n" + www.error;
        }
        else
        {
            debugText.text = "RESPONSE:\n" + www.downloadHandler.text;

            // Parse JSON data from server:
            GameEndResponse responseJson = JsonUtility.FromJson <GameEndResponse>(www.downloadHandler.text);

            // Handle different "result" values:
            if (responseJson.result == "OK")
            {
                debugText.text = "OK:\n" + www.downloadHandler.text;

                // Update game data:
                GameManager.instance.player1id           = -1;
                GameManager.instance.player2id           = -1;
                GameManager.instance.player1name         = "";
                GameManager.instance.player2name         = "";
                GameManager.instance.gid                 = -1;
                GameManager.instance.player1VictoryState = false;
                GameManager.instance.player2VictoryState = false;

                // Back to lobby:
                SceneManager.LoadScene("Lobby");
            }
            else if (responseJson.result == "ERROR")
            {
                debugText.text = "ERROR:\n" + responseJson.info;
            }
        }
    }
Exemplo n.º 3
0
        /// <summary>
        /// Check if any player dead
        /// </summary>
        /// <param name="match"></param>
        /// <param name="response"></param>
        /// <returns></returns>
        private bool CheckForGameEnd(GameMatch match, out GameEndResponse response)
        {
            if (match.Player1.Health <= 0)
            {
                response = new GameEndResponse
                {
                    PlayerWon = match.Player2.InGameID,
                };

                return(true);
            }
            if (match.Player2.Health <= 0)
            {
                response = new GameEndResponse
                {
                    PlayerWon = match.Player1.InGameID,
                };

                return(true);
            }

            response = null;
            return(false);
        }
 private void HandleGameEndResponse(GameEndResponse response)
 {
     GameManager.Instance.EndGame(response);
 }