public void EndOfTurn() { if (PlayerPrefs.GetInt(Constants.gameIsOnlineKey) == 1 && (BattleInformation.DwarfPlayer.ID == GameInformation.GetCurrentPlayer().ID&& BattleInformation.IsDwarfTurn) || (BattleInformation.TrollPlayer.ID == GameInformation.GetCurrentPlayer().ID&& !BattleInformation.IsDwarfTurn)) { OnlineBattleManager.PrintShotInfo(BattleInformation.currentPlayerShot); //Add missing values to current player shot BattleInformation.currentPlayerShot.id_game = BattleInformation.OnlineGameInfo.id_game; BattleInformation.currentPlayerShot.id_shot = BattleInformation.ShotCount; //Send current player shot info to the online player via API OnlineBattleManager.SendCurrentPlayerShot(BattleInformation.currentPlayerShot); } else { NextTurn(); } }
private void InitializeBattle() { DebugLog.DebugMessage("Initialize battle ...", true); BattleInformation.RoundNum = 1; BattleInformation.Turn = 1; BattleInformation.ShotCount = 1; BattleInformation.IsDwarfTurn = true; BattleInformation.PlayerHasMadeAnActionInHisTurn = false; BattleInformation.currentPlayerShot = new ShotInfo(); if (PlayerPrefs.GetInt(Constants.gameIsVsIAKey) == 1) { DebugLog.DebugMessage("Battle is VS IA", true); DebugLog.DebugMessage("Current player play Dwarf, IA play Troll", true); BattleInformation.DwarfPlayer = GameInformation.GetCurrentPlayer(); BattleInformation.TrollPlayer = new Player("IA"); BattleInformation.TrollPlayer.ID = -1; } else if (PlayerPrefs.GetInt(Constants.gameIsOnlineKey) == 1) { DebugLog.DebugMessage("Battle is VS Online Player", true); //Est ce que le joueur courant est le créateur de la partie : if (Network.player.ipAddress == BattleInformation.OnlineGameInfo.starter) { DebugLog.DebugMessage("Current player play Dwarf, Online player play Troll", true); BattleInformation.DwarfPlayer = GameInformation.GetCurrentPlayer(); BattleInformation.TrollPlayer = new Player("Online Player"); BattleInformation.TrollPlayer.ID = -2; } else { DebugLog.DebugMessage("Current player play Troll, Online Player play Dwarf", true); BattleInformation.DwarfPlayer = new Player("Online Player"); BattleInformation.DwarfPlayer.ID = -2; BattleInformation.TrollPlayer = GameInformation.GetCurrentPlayer(); } } else { DebugLog.DebugMessage("Battle is VS Local Player", true); DebugLog.DebugMessage("Current player play Dwarf, Player2 play Troll", true); BattleInformation.DwarfPlayer = GameInformation.GetCurrentPlayer(); BattleInformation.TrollPlayer = GameInformation.GetPlayer2(); } DebugLog.DebugMessage("Init Points", true); BattleInformation.Player1Point = 0; BattleInformation.Player2Point = 0; BattleInformation.TakenDwarfCount = 0; BattleInformation.TakenTrollCount = 0; DebugLog.DebugMessage("Init HUD", true); HudLink.player1TakenPawnGrid.UpdateGrid(); HudLink.player2TakenPawnGrid.UpdateGrid(); HudLink.turnText.UpdateText(); ShowTurnBanner(); DebugLog.DebugMessage("Set parameters to the player who play his turn ...", true); DebugLog.DebugMessage("Dwarf Player name : " + BattleInformation.DwarfPlayer.Name + " Current Player name : " + GameInformation.GetCurrentPlayer().Name, false); if (BattleInformation.DwarfPlayer.ID == GameInformation.GetCurrentPlayer().ID) { BattleInformation.currentPlayerShot = new ShotInfo(); DebugLog.DebugMessage("Wait for current player action", true); //Keep the player to play his turn } else { if (PlayerPrefs.GetInt(Constants.gameIsVsIAKey) == 1) { DebugLog.DebugMessage("Wait for IA action", true); //Unallow current player to do an action BattleInformation.PlayerHasMadeAnActionInHisTurn = true; //IA Turn } else if (PlayerPrefs.GetInt(Constants.gameIsOnlineKey) == 1) { DebugLog.DebugMessage("Wait for online player action", true); //Unallow current player to do an action BattleInformation.PlayerHasMadeAnActionInHisTurn = true; //Disable buttons SetButtonsState(false); //Show online player loading shot block HudLink.player2ThinkingBlock.gameObject.SetActive(true); //Wait online player shot OnlineBattleManager.WaitOtherPlayerShot(); } else { DebugLog.DebugMessage("Wait for local player 2 action", true); //Keep the player 2 to play his turn } } }
//Use to switch dwarf and troll turn public void NextTurn() { //Unselect selected pawn FindObjectOfType <Co_GameBoard>().SetSelectedPawn(null); BattleInformation.ShotCount++; //Change play side BattleInformation.IsDwarfTurn = !BattleInformation.IsDwarfTurn; if (BattleInformation.IsDwarfTurn) { BattleInformation.Turn++; HudLink.turnText.UpdateText(); } DebugLog.DebugMessage("trollPlayerId : " + BattleInformation.TrollPlayer.ID + " | current player ID : " + GameInformation.GetCurrentPlayer().ID + " | isDwarfTurn : " + BattleInformation.IsDwarfTurn, false); //If this turn is for current player if ((BattleInformation.DwarfPlayer.ID == GameInformation.GetCurrentPlayer().ID&& BattleInformation.IsDwarfTurn) || (BattleInformation.TrollPlayer.ID == GameInformation.GetCurrentPlayer().ID&& !BattleInformation.IsDwarfTurn)) { //Disable buttons SetButtonsState(true); //Show online player loading shot block HudLink.player2ThinkingBlock.gameObject.SetActive(false); //Autorize player to do an action BattleInformation.PlayerHasMadeAnActionInHisTurn = false; BattleInformation.PlayerHasMadeAnAttackInThisTurn = false; DebugLog.DebugMessage("Wait for current player action", true); //Keep the player to play his turn } else { if (PlayerPrefs.GetInt(Constants.gameIsVsIAKey) == 1) { //IA Turn DebugLog.DebugMessage("Wait for IA action", true); } else if (PlayerPrefs.GetInt(Constants.gameIsOnlineKey) == 1) { //Disable buttons SetButtonsState(false); //Show online player loading shot block HudLink.player2ThinkingBlock.gameObject.SetActive(true); DebugLog.DebugMessage("Wait for online player action", true); //Wait online player shot OnlineBattleManager.WaitOtherPlayerShot(); } else { DebugLog.DebugMessage("Wait for local player 2 action", true); //Keep the player 2 to play his turn //Allow next player to make an action BattleInformation.PlayerHasMadeAnActionInHisTurn = false; BattleInformation.PlayerHasMadeAnAttackInThisTurn = false; } } ShowTurnBanner(); }