Exemplo n.º 1
0
 public int CheckHit(int posX, int posY, bool Player0VsAI1)
 {
     if (Player0VsAI1)
     {
         if (ReadGrid(posX, posY) == 0)
         {
             audioPlayer.PlayBlup();
             Debug.Log("<color=blue> AI turn ->  Miss X: " + posY + " Y: " + posX + "</color>");
             UI.AILogs(posY, posX, true);
             ChangeGrid(posX, posY, 1);
             SpawnMiss(posY, posX, false);
             turn = Turn.Player;
             return(0);
         }
         else if (ReadGrid(posX, posY) == 5)
         {
             //Hit
             audioPlayer.PlayBoom();
             Debug.Log("<color=blue> AI turn -> Hit X: " + posY + " Y: " + posX + "</color>");
             UI.AILogs(posY, posX, false);
             ChangeGrid(posX, posY, 4);
             kill = true;
             CheckKillShip(posX, posY, posX, posY, Player0VsAI1);
             //Debug.Log(kill);
             if (kill)
             {
                 audioPlayer.PlayBigBoom();
                 shipLenght = 0;
                 KillShip(posX, posY, -9, -9, Player0VsAI1);
                 currentShip.GetComponent <SpriteRenderer>().sprite = broken[shipLenght];
                 UI.KillShip(shipLenght + 1, true);
                 DisableKilledShipPlayer(shipLenght);
                 IsEnd();
             }
             else
             {
                 SpawnExplode(posY, posX, true);
             }
             return(5);
         }
     }
     else
     {
         if (AIReadGrid(posX, posY) == 0)
         {
             //Miss
             audioPlayer.PlayBlup();
             Debug.Log("<color=green> Player turn ->  Miss X: " + posY + " Y: " + posX + "</color>");
             UI.PlayerLogs(posY, posX, true);
             AIChangeGrid(posX, posY, 1);
             SpawnMiss(posY, posX, true);
             turn = Turn.AI;
             StartCoroutine(AI.LowAIAlgorithm());
             //AI.LowAIAlgorithm();
             return(0);
         }
         else if (AIReadGrid(posX, posY) == 5)
         {
             //Hit
             audioPlayer.PlayBoom();
             Debug.Log("<color=green> Player turn ->  Hit X: " + posY + " Y: " + posX + "</color>");
             UI.PlayerLogs(posY, posX, false);
             AIChangeGrid(posX, posY, 4);
             kill = true;
             CheckKillShip(posX, posY, posX, posY, Player0VsAI1);
             //Debug.Log(kill);
             if (kill)
             {
                 audioPlayer.PlayBigBoom();
                 shipLenght = 0;
                 KillShip(posX, posY, -9, -9, Player0VsAI1);
                 DisableKilledShipAI(shipLenght);
                 UI.KillShip(shipLenght + 1, false);
                 IsEnd();
             }
             else
             {
                 SpawnExplode(posY, posX, false);
             }
             return(5);
         }
     }
     return(1);
 }