コード例 #1
0
    private bool CheckLeftDiagonal(EChipColor currentColor, int i, int j)
    {
        int count = 1;

        for (int k = 1; k < 7; ++k)
        {
            if ((i + k < 6) && (j - k >= 0))
            {
                //Debug.Log(i + " -- " + j);
                if (chips[i + k, j - k] != null)
                {
                    if (chips[i + k, j - k].GetColor() == currentColor)
                    {
                        //Debug.Log("Left Diagonal");
                        ++count;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
        if (count >= 4)
        {
            // Debug.Log(i + "--" + j);
            for (int k = 0; k < count; ++k)
            {
                chips[i + k, j - k].SetColorActive();
            }
            return(true);
        }
        return(false);
    }
コード例 #2
0
    private bool CheckRightDiagonal(EChipColor currentColor, int i, int j)
    {
        int count = 1;

        for (int k = 1; k < 7; ++k)
        {
            if ((i + k < 6) && (j + k < 7))
            {
                if (chips[i + k, j + k] != null)
                {
                    if (chips[i + k, j + k].GetColor() == currentColor)
                    {
                        ++count;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
        }
        if (count >= 4)
        {
            for (int k = 0; k < count; ++k)
            {
                chips[i + k, j + k].SetColorActive();
            }
            return(true);
        }
        return(false);
    }
コード例 #3
0
    private bool CheckVertical(EChipColor currentColor, int i, int j)
    {
        int count = 1;

        for (int k = i + 1; k < 6; ++k)
        {
            if (chips[k, j] != null)
            {
                if (chips[k, j].GetColor() == currentColor)
                {
                    ++count;
                }
                else
                {
                    break;
                }
            }
            else
            {
                break;
            }
        }
        if (count >= 4)
        {
            for (int k = i; k < i + count; ++k)
            {
                chips[k, j].SetColorActive();
            }
            return(true);
        }
        return(false);
    }
コード例 #4
0
 public void NewGame()
 {
     if (mode == EMode.HOT_SEAT)
     {
         SceneManager.LoadScene("MainGame");
     }
     else
     {
         newGamePanel.SetActive(false);
         currentColorStep = startColorStep;
         ChangeStartColor();
         if (customNetworkManager.IsServer())
         {
             redScore.text  = customNetworkManager.players[0].GetScore().ToString();
             blueScore.text = customNetworkManager.players[1].GetScore().ToString();
             customNetworkManager.GetLocalPlayer().CmdChangeClientRequest(-1);
             customNetworkManager.GetLocalPlayer().CmdChangeHostRequest(-1);
             if (currentColorStep == EChipColor.RED)
             {
                 customNetworkManager.GetLocalPlayer().SetActive(true);
                 customNetworkManager.GetDistancePlayer().SetActive(false);
             }
             else
             {
                 customNetworkManager.GetLocalPlayer().SetActive(false);
                 customNetworkManager.GetDistancePlayer().SetActive(true);
             }
         }
         else
         {
             redScore.text  = players[1].GetScore().ToString();
             blueScore.text = players[0].GetScore().ToString();
             GetLocalPlayer().CmdChangeClientRequest(-1);
             GetLocalPlayer().CmdChangeHostRequest(-1);
             if (currentColorStep == EChipColor.RED)
             {
                 GetDistancePlayer().SetActive(true);
                 GetLocalPlayer().SetActive(false);
             }
             else
             {
                 GetDistancePlayer().SetActive(false);
                 GetLocalPlayer().SetActive(true);
             }
         }
         redWin.text  = "";
         blueWin.text = "";
         DelChips();
         state = EState.PLAYER_STEP;
     }
 }
コード例 #5
0
 void Start()
 {
     chips            = new Chip[6, 7];
     redScore.text    = redScoreValue.ToString();
     blueScore.text   = blueScoreValue.ToString();
     currentColorStep = startColorStep;
     ChangeStartColor();
     if (mode == EMode.NON_SELECT)
     {
         choseModePanel.SetActive(true);
         state = EState.CHOSE_MODE;
     }
     else
     {
         choseModePanel.SetActive(false);
         state = EState.PLAYER_STEP;;
     }
 }
コード例 #6
0
    private bool CheckHorizontal(EChipColor currentColor, int i, int j)
    {
        int count = 1;

        for (int k = j + 1; k < 7; ++k)
        {
            if (chips[i, k] != null)
            {
                if (chips[i, k].GetColor() == currentColor)
                {
                    ++count;
                }
                else
                {
                    break;
                }
            }
            else
            {
                break;
            }
        }
        if (count >= 4)
        {
            for (int k = j; k < j + count; ++k)
            {
                chips[i, k].SetColorActive();
                if (mode == EMode.ONLINE)
                {
                    Debug.Log("RpcSetPointActive");
                    chips[i, k].RpcSetColorActive();
                }
            }
            return(true);
        }
        return(false);
    }
コード例 #7
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;
         }
     }
 }
コード例 #8
0
 public void ChangeCurrentColor()
 {
     currentColorStep = (currentColorStep == EChipColor.RED) ? EChipColor.BLUE : EChipColor.RED;
 }
コード例 #9
0
 public void ChangeStartColor()
 {
     startColorStep = (startColorStep == EChipColor.RED) ? EChipColor.BLUE : EChipColor.RED;
 }