void CheckPanelOn() { switch (ActivePanel) { case PanelOn.GAME_ON: PlayerUI.SetActive(true); TutorialPanel.SetActive(false); GameEndPanel.SetActive(false); break; case PanelOn.TUTORIAL: PlayerUI.SetActive(false); TutorialPanel.SetActive(true); GameEndPanel.SetActive(false); break; case PanelOn.GAME_OVER: PlayerUI.SetActive(false); TutorialPanel.SetActive(false); GameEndPanel.SetActive(true); break; case PanelOn.NONE: PlayerUI.SetActive(false); TutorialPanel.SetActive(false); GameEndPanel.SetActive(false); break; default: Debug.Log("ERROR-Unknown Panel Being Activated : " + ActivePanel); ActivePanel = PanelOn.GAME_ON; break; } }
void Start() { Instance = this; IsSuddenDeath = false; gameState = GameState.WAITING; ActivePanel = PanelOn.NONE; LastPanel = PanelOn.NONE; if (TutorialPanel == null) { Debug.Log("ERROR - Tutorial Panel not attached to GameManager"); } if (PlayerUI == null) { Debug.Log("ERROR - Player Panel not attached to GameManager"); } TutorialPanel.SetActive(false); PlayerUI.SetActive(true); UpdatePlayerPanel(); if (Programmer.LocalPlayerInstance == null) { Debug.LogFormat("We are Instantiating LocalPlayer from {0}", SceneManagerHelper.ActiveSceneName); // we're in a room. spawn a character for the local player. it gets synced by using PhotonNetwork.Instantiate PhotonNetwork.Instantiate(this.PlayerPrefab.name, new Vector3(0f, 5f, 0f), Quaternion.identity, 0); } else { Debug.LogFormat("Ignoring scene load for {0}", SceneManagerHelper.ActiveSceneName); } }
/// <summary> /// Toggle on and off tutorial panel /// </summary> public void ToggleTutorial() { PanelOn cache = ActivePanel; ActivePanel = (ActivePanel != PanelOn.TUTORIAL) ? PanelOn.TUTORIAL : LastPanel; LastPanel = cache; Debug.Log("Panel State is now" + ActivePanel); }
/// <summary> /// Updates PlayerPanel every frome. /// </summary> void UpdatePlayerPanel() { string turn = " -> (Turn)"; // TODO: Need better way to visualize player turn if (p1 != null) { p1Name.text = p1.GetName(); if (gameState == GameState.P1_TURN) { p1Name.text += turn; } p1Foo.text = p1.GetFooText(); p1Bar.text = p1.GetBarText(); p1Bugs.text = p1.GetBugText(); p1Screen.text = p1.PrintScreen(); } else { p1Name.text = ""; p1Foo.text = ""; p1Bar.text = ""; p1Bugs.text = ""; p1Screen.text = ""; Debug.Log("ERROR - Gamanager has no player 1"); } if (p2 != null) { p2Name.text = p2.GetName(); if (gameState == GameState.P2_TURN) { p2Name.text += turn; } p2Foo.text = p2.GetFooText(); p2Bar.text = p2.GetBarText(); p2Bugs.text = p2.GetBugText(); p2Screen.text = p2.PrintScreen(); if (ExeGameObj != null) { ExeGameObj.SetActive(true); } ActivePanel = (ActivePanel == PanelOn.NONE) ? PanelOn.GAME_ON : ActivePanel; } else { p2Name.text = ""; p2Foo.text = ""; p2Bar.text = ""; p2Bugs.text = ""; p2Screen.text = ""; if (ExeGameObj != null) { ExeGameObj.SetActive(false); } } }
/// <summary> /// Forces player to leave the game /// - Will also Unregisters all players registered to the GameManager /// - Will also clear p1 data and set p2 to null /// </summary> public void LeaveRoom() { if (p1) { p1.IsRegistered = false; p1.ResetPlayerStats(); Debug.Log("Cleared P1 Data"); } if (p2) { p2.IsRegistered = false; p2 = null; Debug.Log("Erased P2 Data..."); } UpdatePlayerPanel(); ActivePanel = PanelOn.NONE; LastPanel = PanelOn.NONE; PhotonNetwork.LeaveRoom(); }
/// <summary> /// Checks to see if either player's have won /// /// If one player ends a turn with 0 foo or bar or has 3 bugs then that players lose /// /// If both players lose, the game goes into sudden death /// /// Next player to have a bug will lose /// </summary> void CheckPlayerWin() { if (!p2 || gameState == GameState.GAME_OVER) { return; } // This line is used to check for the cheat code // In release build, this should not be here if (Winner != null) { gameState = (Winner == p1) ? GameState.P1_WIN : GameState.P2_WIN; } if (p1.Bugs >= 3 && p1.Bugs > p2.Bugs) { gameState = GameState.P2_WIN; } if ((p1.Foo == 0 || p1.Bar == 0) && (p2.Foo != 0 && p2.Bar != 0)) { gameState = GameState.P2_WIN; } if (p2.Bugs >= 3 && p2.Bugs > p1.Bugs) { gameState = GameState.P1_WIN; } if ((p2.Foo == 0 || p2.Bar == 0) && (p1.Foo != 0 && p1.Bar != 0)) { gameState = GameState.P1_WIN; } if (gameState == GameState.P1_WIN || gameState == GameState.P2_WIN) { p1.ResetPlayerStats(); p2.ResetPlayerStats(); LastPanel = ActivePanel; ActivePanel = PanelOn.GAME_OVER; } }
void CheckGameState() { if (!p2) { gameState = GameState.WAITING; return; } switch (gameState) { case GameState.WAITING: // When both players have joined // rng determines who goes first if (p1 != null && p2 != null) { int t1 = p1.rng.GetRandomInt(); int t2 = p2.rng.GetRandomInt(); Debug.Log("T1=" + t1.ToString()); Debug.Log("T2=" + t2.ToString()); if (t1 > t2) { p1.Turn = true; p2.Turn = false; gameState = GameState.P1_TURN; Debug.Log("Player 1 Turn"); } else if (t2 > t1) { p1.Turn = false; p2.Turn = true; gameState = GameState.P2_TURN; Debug.Log("Player 2 Turn"); } else { Debug.Log("Deciding on who's turn it is..."); } } break; case GameState.P1_TURN: if (!p1.Turn) { p2.Turn = true; gameState = GameState.P2_TURN; } break; case GameState.P2_TURN: if (!p2.Turn) { p1.Turn = true; gameState = GameState.P1_TURN; } break; case GameState.P1_WIN: Debug.Log("Player 1 Won"); Winner = p1; GameOverText.text = Consts.ON_WIN_TEXT; gameState = GameState.GAME_OVER; StartCoroutine(PostScores(Consts.userID, true)); break; case GameState.P2_WIN: Debug.Log("Player 2 Won"); Winner = p2; GameOverText.text = Consts.ON_LOSE_TEXT; gameState = GameState.GAME_OVER; StartCoroutine(PostScores(Consts.userID, false)); break; case GameState.GAME_OVER: if (p1.PlayAgain && p2.PlayAgain) { p1.ResetPlayerStats(); p2.ResetPlayerStats(); Winner = null; ActivePanel = PanelOn.GAME_ON; LastPanel = PanelOn.NONE; gameState = GameState.WAITING; } break; default: Debug.Log("ERROR-Unknown Game State : " + gameState); break; } }