Exemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (GameStarted)
     {
         if (!aWinner)
         {
             if (isMultiplayer)
             {
                 if (isHuman)
                 {
                     if (GetHumanInput())
                     {
                         isHuman = false;
                         gameStep--;
                         if (DoWeHaveAWiner(TicTacToeGrid, isPlayerOne ? '2' : '1'))
                         {
                             aWinner = true;
                             if (isPlayerOne)
                             {
                                 Debug.Log("Vitoria do jogador 2");
                             }
                             else
                             {
                                 Debug.Log("Vitoria do jogador 1");
                             }
                         }
                         else
                         {
                             if (gameStep < 0)
                             {
                                 Debug.Log("EMPATE");
                             }
                         }
                     }
                 }
                 else
                 {
                     Vector2 play = ai.GetAIInput(TicTacToeGrid, isPlayerOne ? '1' : '2');
                     Debug.Log(play);
                     PlaceXOnBoard(isPlayerOne ? '1' : '2', play);
                     if (DoWeHaveAWiner(TicTacToeGrid, isPlayerOne ? '1' : '2'))
                     {
                         aWinner = true;
                         if (!isPlayerOne)
                         {
                             Debug.Log("Vitoria do jogador 2");
                         }
                         else
                         {
                             Debug.Log("Vitoria do jogador 1");
                         }
                     }
                     else
                     {
                         if (gameStep < 0)
                         {
                             Debug.Log("EMPATE");
                         }
                     }
                     isPlayerOne = !isPlayerOne;
                     isHuman     = true;
                     gameStep--;
                 }
             }
             else
             {
                 if (GetHumanInput())
                 {
                     gameStep--;
                     if (DoWeHaveAWiner(TicTacToeGrid, isPlayerOne ? '2' : '1'))
                     {
                         aWinner = true;
                         if (isPlayerOne)
                         {
                             vencedor.text = "Vitoria do jogador X";
                         }
                         else
                         {
                             vencedor.text = "Vitoria do jogador O";
                         };
                     }
                     else
                     {
                         if (gameStep < 0)
                         {
                             Debug.Log("EMPATE");
                         }
                     }
                 }
             }
         }
         else
         {
             if (Input.GetMouseButtonUp(0) || Input.anyKey)
             {
                 SceneManager.LoadScene(0);
             }
         }
     }
 }