Esempio n. 1
0
 void Update()
 {
     if (gameState.StartsWith("Setup"))
     {
         if (gameState == "Setup")
         {
             var missingQtd = totalNumberShips - defense.shipCount;
             StatusText = "Still need to deploy " + missingQtd.ToString() + " ship" + (missingQtd > 1? "s" : "");
         }
         Setup();
     }
     if (latestAttackMessage != null)
     {
         var currentAM = latestAttackMessage;
         latestAttackMessage = null;
         Vector2Int loc = FromCoord(currentAM.coordinates);
         Debug.Log("Dealing with the latest attack message");
         if (gameState == "Turn")
         {
             Debug.Log("Turn");
             if (currentAM.win == "true")
             {
                 Debug.Log("It's a win!");
                 attack.ShowTileText(loc, "H");
                 gameState = "Win";
                 attack.SetIsActive(false);
                 StatusText      = "You won it!";
                 UIManager.State = 5;
                 UpdatePlayerScore(true);
             }
             else
             {
                 if (currentAM.hit == "true")
                 {
                     Debug.Log("You hit something");
                     attack.ShowTileText(loc, "H");
                 }
                 else
                 {
                     Debug.Log("You hit water");
                     attack.ShowTileText(loc, "M");
                 }
                 Debug.Log("Now it's your opponent's turn");
                 gameState  = "Wait";
                 StatusText = "It's opponent's time to attack";
                 attack.SetIsActive(false);
             }
         }
         else if (gameState == "Wait")
         {
             Debug.Log("Wait");
             defense.AttackTile(loc);
             if (currentAM.win == "true")
             {
                 Debug.Log("you lost the game!");
                 gameState = "Lost";
                 attack.SetIsActive(false);
                 StatusText      = "You Lost the game!";
                 UIManager.State = 5;
                 UpdatePlayerScore(false);
             }
             else
             {
                 Debug.Log("Now it's your time to attack");
                 gameState  = "Turn";
                 StatusText = "It's your time to attack";
                 attack.SetIsActive(true);
             }
         }
     }
 }