public void AddPointTo(bool isDwarfPlayer, int earnPoint)
 {
     if (isDwarfPlayer)
     {
         if (BattleInformation.DwarfPlayer.ID == GameInformation.GetCurrentPlayer().ID)
         {
             DebugLog.DebugMessage("Player 1, who play dwarfs, win " + earnPoint + " points ! ", true);
             BattleInformation.Player1Point += earnPoint;
         }
         else
         {
             DebugLog.DebugMessage("Player 2, who play dwarfs, win " + earnPoint + " points ! ", true);
             BattleInformation.Player2Point += earnPoint;
         }
     }
     else
     {
         if (BattleInformation.TrollPlayer.ID == GameInformation.GetCurrentPlayer().ID)
         {
             DebugLog.DebugMessage("Player 1, who play trolls, win " + earnPoint + " points ! ", true);
             BattleInformation.Player1Point += earnPoint;
         }
         else
         {
             DebugLog.DebugMessage("Player 2, who play trolls, win " + earnPoint + " points ! ", true);
             BattleInformation.Player2Point += earnPoint;
         }
     }
 }
 public void AddTakenPawn(bool isDwarfPlayer, int count)
 {
     for (int i = 0; i < count; i++)
     {
         if (isDwarfPlayer)
         {
             if (BattleInformation.DwarfPlayer.ID == GameInformation.GetCurrentPlayer().ID)
             {
                 HudLink.player1TakenPawnGrid.AddTakenPawn();
             }
             else
             {
                 HudLink.player2TakenPawnGrid.AddTakenPawn();
             }
         }
         else
         {
             if (BattleInformation.TrollPlayer.ID == GameInformation.GetCurrentPlayer().ID)
             {
                 HudLink.player1TakenPawnGrid.AddTakenPawn();
             }
             else
             {
                 HudLink.player2TakenPawnGrid.AddTakenPawn();
             }
         }
     }
 }
Exemple #3
0
    private void InitializeBattle()
    {
        BattleInformation.RoundNum    = 1;
        BattleInformation.Turn        = 1;
        BattleInformation.IsDwarfTurn = true;
        BattleInformation.PlayerHasMadeAnActionInHisTurn = false;
        BattleInformation.DwarfPlayer = GameInformation.GetCurrentPlayer();

        if (PlayerPrefs.GetInt(Constants.gameIsVsIAKey) == 1)
        {
            BattleInformation.TrollPlayer = new Player("IA");
        }
        else if (PlayerPrefs.GetInt(Constants.gameIsOnlineKey) == 1)
        {
            BattleInformation.TrollPlayer = new Player("Online Player");
        }
        else
        {
            BattleInformation.TrollPlayer = GameInformation.GetPlayer2();
        }

        BattleInformation.Player1Point    = 0;
        BattleInformation.Player2Point    = 0;
        BattleInformation.TakenDwarfCount = 0;
        BattleInformation.TakenTrollCount = 0;

        HudLink.player1TakenPawnGrid.UpdateGrid();
        HudLink.player2TakenPawnGrid.UpdateGrid();

        HudLink.turnText.UpdateText();

        ShowTurnBanner();
    }
Exemple #4
0
 // Use this for initialization
 void Start()
 {
     if (isPlayer1)
     {
         //Change image and text of player 1 info panel
         transform.GetComponentInChildren <AvatarItem>().avatarImage.sprite  = PPSerialization.Base64ToSprite(GameInformation.GetCurrentPlayer().Base64Image);
         transform.GetComponentInChildren <AvatarItem>().avatarNameText.text = GameInformation.GetCurrentPlayer().Name;
     }
     else
     {
         if (PlayerPrefs.GetInt(Constants.gameIsVsIAKey) == 1)
         {
             //Change image and text of IA info panel
             transform.GetComponentInChildren <AvatarItem>().avatarImage.sprite  = null;
             transform.GetComponentInChildren <AvatarItem>().avatarNameText.text = "IA";
         }
         else if (PlayerPrefs.GetInt(Constants.gameIsOnlineKey) == 1)
         {
             //Change image and text of IA info panel
             transform.GetComponentInChildren <AvatarItem>().avatarImage.sprite  = null;
             transform.GetComponentInChildren <AvatarItem>().avatarNameText.text = "Online Player";
         }
         else //Is versus local player
         {
             //Change image and text of player 2 info panel
             transform.GetComponentInChildren <AvatarItem>().avatarImage.sprite  = PPSerialization.Base64ToSprite(GameInformation.GetPlayer2().Base64Image);
             transform.GetComponentInChildren <AvatarItem>().avatarNameText.text = GameInformation.GetPlayer2().Name;
         }
     }
 }
 public void CheckIfCanLaunchHVSHGame()
 {
     if (GameInformation.GetCurrentPlayer() != null)
     {
         SetIsSelectingPlayer2(true);
     }
     else
     {
         SetIsSelectingPlayer2(false);
     }
 }
Exemple #6
0
        public void AssociateCurrentPlayerToUI()
        {
            Player currentPlayer = GameInformation.GetCurrentPlayer();

            if (currentPlayer != null)
            {
                currentPlayerUIPanel.GetComponent <AvatarItem>().avatarNameText.text = currentPlayer.Name;
                currentPlayerUIPanel.GetComponent <AvatarItem>().avatarImage.sprite  = PPSerialization.Base64ToSprite(currentPlayer.Base64Image);
                currentPlayerUIPanel.gameObject.SetActive(true);
            }
            else
            {
                currentPlayerUIPanel.gameObject.SetActive(false);
            }
        }
        //Populate avatar UI List with players present in PlayerPrefs
        private void PopulateAvatarUIList()
        {
            DebugLog.DebugMessage("isSelectingPlayer2 : " + isSelectingPlayer2, true);
            //Get all players
            List <Player> playerList = GameInformation.GetAllPlayers();

            //Add player as child
            foreach (Player player in playerList)
            {
                //Hide player if isSelecting player2 and if this player is the current player
                if (isSelectingPlayer2 && player.ID == GameInformation.GetCurrentPlayer().ID)
                {
                    //Do nothing..
                }
                else
                {
                    //Add avatar item in the UI list
                    GameObject avatarItem = Instantiate(avatarPrefab);
                    avatarItem.transform.SetParent(avatarUIList.transform, false);
                    //Set some paramter in the avatar item script
                    avatarItem.GetComponent <AvatarItem>().avatarNameText.text = player.Name;
                    avatarItem.GetComponent <AvatarItem>().avatarImage.sprite  = PPSerialization.Base64ToSprite(player.Base64Image);
                    avatarItem.GetComponent <AvatarItem>().associatedPlayer    = player;
                    avatarItem.GetComponent <AvatarItem>().mainMenu            = mainMenu;
                    avatarItem.GetComponent <AvatarItem>().selectAvatarMenu    = this;
                    if (isSelectingPlayer2)
                    {
                        avatarItem.GetComponent <AvatarItem>().isSelectingPlayer2 = true;
                    }
                    if (isDeleting)
                    {
                        avatarItem.GetComponent <AvatarItem>().isDeleting = true;
                    }
                }
            }
            //Put the + button at the end of the grid
            avatarUIList.transform.Find("CreateNewAvatarPanel").SetAsLastSibling();
        }
        private void OnEnable()
        {
            player1Image.sprite = PPSerialization.Base64ToSprite(GameInformation.GetCurrentPlayer().Base64Image);
            player1Name.text    = GameInformation.GetCurrentPlayer().Name;
            if (PlayerPrefs.GetInt(Constants.gameIsVsIAKey) == 1)
            {
                player2Image.sprite = null;
                player2Name.text    = "IA";
            }
            else if (PlayerPrefs.GetInt(Constants.gameIsOnlineKey) == 1)
            {
                player2Image.sprite = null;
                player2Name.text    = "Online Player";
            }
            else
            {
                player2Image.sprite = PPSerialization.Base64ToSprite(GameInformation.GetPlayer2().Base64Image);
                player2Name.text    = GameInformation.GetPlayer2().Name;
            }

            player1Score.text = BattleInformation.Player1Point.ToString();
            player2Score.text = BattleInformation.Player2Point.ToString();

            if (BattleInformation.Player1Point > BattleInformation.Player2Point)
            {
                player1CardBackground.color = winnerColor;
            }
            else if (BattleInformation.Player1Point < BattleInformation.Player2Point)
            {
                player2CardBackground.color = winnerColor;
            }
            else if (BattleInformation.Player1Point == BattleInformation.Player2Point)
            {
                player1CardBackground.color = winnerColor;
                player2CardBackground.color = winnerColor;
            }
        }
        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();
        }
 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();
     }
 }