Ejemplo n.º 1
0
 /// <summary>
 /// 玩家下棋
 /// </summary>
 private void PlayerGo(Vector3 pointerPos)
 {
     for (int i = 0; i < ConstKey.BoardCrossCount; i++)
     {
         for (int j = 0; j < ConstKey.BoardCrossCount; j++)
         {
             _curChess = _chess[i, j];
             if (_curChess.CurChessState == ChessState.None && Dis(_pointerPos, _curChess.Position) < _minGridDis / 2)                          //找到最接近鼠标点击位置的点,如果空,则落子
             {
                 _chess[i, j].CurChessState = _isPlayerFirst? ChessState.BlackChess:ChessState.WhiteChess;
                 _curInstantiationObj       = _isPlayerFirst ? _blackPrefab : _whiteParefab;
                 _lastObj  = Instantiate(_curInstantiationObj, _curChess.Position, Quaternion.identity);
                 _curChess = _chess[i, j];
                 //落子成功,更换下棋顺序
                 _whoTurn = WhoTurn.AiGo;
                 _isWin   = IsWin(i, j, _curChess.CurChessState);
                 if (_isWin)
                 {
                     _isStartGame = false;
                     ShowResultPanel(_curChess.CurChessState);
                 }
                 else
                 {
                     AiGo(i, j);
                 }
                 return;
             }
         }
     }
 }
Ejemplo n.º 2
0
 public void OnClickComputerFirst()
 {
     _isPlayerFirst = false;
     _whoTurn       = WhoTurn.AiGo;
     _ai.ComputerFirst(out _chessX, out _chessY);
     StartPlaying();
     _chess[_chessX, _chessY].CurChessState = ChessState.BlackChess;                                                                          //默认先手为黑子
     _lastObj = Instantiate(_blackPrefab, _curChess.Position, Quaternion.identity);
     _whoTurn = WhoTurn.PlayerGo;
 }
Ejemplo n.º 3
0
    public void ChangeTurn()
    {
        switch (turn)
        {
        case WhoTurn.Player:
            turn = WhoTurn.AI;
            break;

        case WhoTurn.AI:
            turn = WhoTurn.Player;
            break;

        default:
            break;
        }

        OnChangeTurn?.Invoke(turn);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// AI下棋
    /// </summary>
    private void AiGo(int x, int y)
    {
        _playerX = x;
        _playerY = y;
        _ai.ComputerDo(x, y, out _chessX, out _chessY);
        _chess[_chessX, _chessY].CurChessState = _isPlayerFirst? ChessState.WhiteChess:ChessState.BlackChess;
        _curInstantiationObj = _isPlayerFirst ? _whiteParefab : _blackPrefab;
        _curChess            = _chess[_chessX, _chessY];
        _curObj = Instantiate(_curInstantiationObj, _curChess.Position, Quaternion.identity);
        var isWin = IsWin(_chessX, _chessY, _curChess.CurChessState);

        if (isWin)
        {
            _isStartGame = false;
            ShowResultPanel(_curChess.CurChessState);
            _isWin = true;
        }
        else
        {
            _whoTurn = WhoTurn.PlayerGo;
            _canUndo = true;
        }
    }
Ejemplo n.º 5
0
 public void OnClickPlayerFirst()
 {
     _isPlayerFirst = true;
     _whoTurn       = WhoTurn.PlayerGo;
     StartPlaying();
 }