コード例 #1
0
 void Update()
 {
     if (state != EState.CHOSE_MODE)
     {
         if (state == EState.WAIT_PLAYERS)
         {
             if (customNetworkManager.IsServer() && customNetworkManager.players.Count == 2)
             {
                 state = EState.PLAYER_STEP;
                 customNetworkManager.InstantiateCSC();
                 ClientServerConnector.Instanse.clientRequest = -1;
                 ClientServerConnector.Instanse.hostRequest   = -1;
                 waitingPanel.SetActive(false);
                 return;
             }
             if (!customNetworkManager.IsServer())
             {
                 players = Object.FindObjectsOfType <Player>();
                 if (players.Length == 2)
                 {
                     state = EState.PLAYER_STEP;
                     ClientServerConnector.Instanse.clientRequest = -1;
                     ClientServerConnector.Instanse.hostRequest   = -1;
                     waitingPanel.SetActive(false);
                 }
                 return;
             }
         }
         if (state == EState.PLAYER_STEP)
         {
             if (mode == EMode.HOT_SEAT)
             {
                 MouseControl();
             }
             else
             {
                 if (customNetworkManager.IsServer())
                 {
                     if (ClientServerConnector.Instanse.clientRequest != (-1))
                     {
                         Debug.Log("Server: Client Requst is: " + ClientServerConnector.Instanse.clientRequest);
                         AddChip(ClientServerConnector.Instanse.clientRequest);
                         ClientServerConnector.Instanse.clientRequest = -1;
                         customNetworkManager.GetLocalPlayer().SetActive(true);
                         customNetworkManager.GetDistancePlayer().SetActive(false);
                         state = EState.MOVE_CHIP;
                     }
                     else
                     {
                         if (customNetworkManager.GetLocalPlayer().GetActive())
                         {
                             MouseControl();
                         }
                     }
                 }
                 else
                 {
                     if (ClientServerConnector.Instanse.hostRequest != (-1))
                     {
                         Debug.Log("Client: Host Requst is: " + ClientServerConnector.Instanse.hostRequest);
                         AddChip(ClientServerConnector.Instanse.hostRequest);
                         GetLocalPlayer().CmdChangeHostRequest(-1);
                         GetLocalPlayer().SetActive(true);
                         GetDistancePlayer().SetActive(false);
                         state = EState.MOVE_CHIP;
                         //customNetworkManager.GetLocalPlayer().SetActive(!customNetworkManager.GetLocalPlayer().GetActive());
                         //customNetworkManager.GetDistancePlayer().SetActive(!customNetworkManager.GetDistancePlayer().GetActive());
                     }
                     else
                     {
                         if (GetLocalPlayer().GetActive())
                         {
                             MouseControl();
                         }
                     }
                 }
             }
         }
         if (state == EState.MOVE_CHIP)
         {
             if (chips[lastChipIdI, lastChipIdJ].IsMove())
             {
                 chips[lastChipIdI, lastChipIdJ].MoveToNewPosition();
             }
             else
             {
                 state = EState.CHECK_WINNER;
             }
             return;
         }
         if (state == EState.CHECK_WINNER)
         {
             for (int i = 0; i < 6; ++i)
             {
                 for (int j = 0; j < 7; ++j)
                 {
                     if (chips[i, j] != null)
                     {
                         EChipColor currentColor = chips[i, j].GetColor();
                         if (CheckHorizontal(currentColor, i, j) ||
                             CheckVertical(currentColor, i, j) ||
                             CheckRightDiagonal(currentColor, i, j) ||
                             CheckLeftDiagonal(currentColor, i, j))
                         {
                             state = EState.PLAYER_WIN;
                             return;
                         }
                         if (CheckFoolChips())
                         {
                             state = EState.DRAW;
                             return;
                         }
                     }
                 }
             }
             state = EState.PLAYER_STEP;
             ChangeCurrentColor();
             return;
         }
         if (state == EState.PLAYER_WIN)
         {
             if (currentColorStep == EChipColor.RED)
             {
                 ++redScoreValue;
                 if (mode == EMode.ONLINE)
                 {
                     if (customNetworkManager.IsServer())
                     {
                         customNetworkManager.GetLocalPlayer().IncreaseScore();
                     }
                     else
                     {
                         GetDistancePlayer().IncreaseScore();
                     }
                 }
                 redWin.text  = "Winner";
                 blueWin.text = "Loser";
             }
             else
             {
                 ++blueScoreValue;
                 if (mode == EMode.ONLINE)
                 {
                     if (customNetworkManager.IsServer())
                     {
                         customNetworkManager.GetDistancePlayer().IncreaseScore();
                     }
                     else
                     {
                         GetLocalPlayer().IncreaseScore();
                     }
                 }
                 redWin.text  = "Loser";
                 blueWin.text = "Winner";
             }
             newGamePanel.SetActive(true);
             state = EState.WAIT_CHOSE;
             return;
         }
         if (state == EState.DRAW)
         {
             redWin.text  = "Draw";
             blueWin.text = "Draw";
             newGamePanel.SetActive(true);
             state = EState.WAIT_CHOSE;
             return;
         }
     }
 }