Example #1
0
    public virtual void AI_move(cell moveto)
    {
        mousePos = moveto.transform.position;
        cell old_cell = _currentCell;

        if (moveto.CurrentPiece == null)
        {
            moveto.SetPieces(this);
            _currentCell.SetPieces(null);
            _currentCell = moveto;
            Location     = mousePos;
            //Sound_CTL.Current.PlaySound(Esound.MOVE);
        }
        else
        {
            ChessBoard.Current.All_piece.Remove(moveto.CurrentPiece);
            moveto.CurrentPiece.Is_it_active = false;
            if (moveto.CurrentPiece.Player == Eplayer.BLACK)
            {
                ChessBoard.Current.Black_Pieces.Remove(moveto.CurrentPiece);
            }
            else
            {
                ChessBoard.Current.White_Pieces.Remove(moveto.CurrentPiece);
            }
            if (moveto.CurrentPiece.Type == Etype.KING)
            {
                BaseGameCTL.Current.end_game(Player);
            }
            Destroy(moveto.CurrentPiece.gameObject);
            moveto.SetPieces(this);
            _currentCell.SetPieces(null);
            _currentCell = moveto;
            Location     = mousePos;
            //Sound_CTL.Current.PlaySound(Esound.HIT);
        }
        if (BaseGameCTL.Current.CheckGameState() == Egame_state.PLAYING)
        {
            BaseGameCTL.Current.SwitchTurn();
        }
        is_it_moved = true;
        old_cell.SetCellState(Ecell_state.SELECTED);
    }
Example #2
0
 public void SetOriginalLocation(int x, int y)//Khởi tạo vị trí ban đầu
 {
     is_it_moved        = false;
     Is_it_active       = true;
     transform.position = new Vector3(x, y, -1);
     this.Location      = this.transform.position;
     //Gán ô cờ ở vị trí tương ứng cho _currentCell
     _currentCell = ChessBoard.Current.cells[x][y];
     //Gán quân cờ này cho biến Current_Piece của ô cờ vừa gán vào
     _currentCell.SetPieces(this);
 }
Example #3
0
 public void Return(cell old_cell, cell return_from_cell, BasePiece piece)
 {
     this.Location = new Vector2(old_cell.transform.position.x, old_cell.transform.position.y);
     _currentCell.SetPieces(piece);
     _currentCell = old_cell;
     old_cell.SetPieces(this);
     if (return_from_cell.CurrentPiece != null)
     {
         return_from_cell.CurrentPiece.Is_it_active = true;
     }
 }
Example #4
0
 public void Calculate_move(cell moveto)
 {
     this.Location = new Vector2(moveto.transform.position.x, moveto.transform.position.y);
     _currentCell.SetPieces(null);
     _currentCell = moveto;
     if (moveto.CurrentPiece != null && moveto.CurrentPiece.Player != _player)
     {
         moveto.CurrentPiece.Is_it_active = false;
     }
     moveto.SetPieces(this);
 }
Example #5
0
    protected virtual void OnMouseUp()
    {
        if (BaseGameCTL.Current.CheckGameState() != Egame_state.PLAYING ||
            BaseGameCTL.Current.CurrentPlayer != Player || side == Eside.AI)
        {
            return;
        }
        mouse_down = false;
        //làm tròn tọa độ cho khớp vô ô cờ
        mousePos.x = Mathf.Round(transform.position.x);
        mousePos.y = Mathf.Round(transform.position.y);

        //Lưu lại biến ô cờ sắp bị thay đổi
        cell old_cell = this._currentCell;

        cell new_cell = ChessBoard.Current.cells[(int)mousePos.x][(int)mousePos.y];

        if (_canMovecells.Contains(new_cell))
        {
            this._currentCell = new_cell;
            this._currentCell.SetPieces(this);
            old_cell.SetPieces(null);
            if (!ChessBoard.Current.HUMAN_King.isInCheck())
            {
                this.Location = mousePos;
                Sound_CTL.Current.PlaySound(Esound.MOVE);
            }
            else
            {
                this._currentCell = old_cell;
                old_cell.SetPieces(this);
                new_cell.SetPieces(null);
            }
        }
        else if (_target.Contains(new_cell))
        {
            new_cell.CurrentPiece.Is_it_active = false;
            if (!ChessBoard.Current.HUMAN_King.isInCheck())
            {
                ChessBoard.Current.All_piece.Remove(new_cell.CurrentPiece);
                new_cell.CurrentPiece.Is_it_active = false;
                if (new_cell.CurrentPiece.Player == Eplayer.BLACK)
                {
                    ChessBoard.Current.Black_Pieces.Remove(new_cell.CurrentPiece);
                }
                else
                {
                    ChessBoard.Current.White_Pieces.Remove(new_cell.CurrentPiece);
                }
                if (new_cell.CurrentPiece.Type == Etype.KING)
                {
                    BaseGameCTL.Current.end_game(this.Player);
                }
                Destroy(new_cell.CurrentPiece.gameObject);
                this._currentCell = new_cell;
                this._currentCell.SetPieces(this);
                old_cell.SetPieces(null);
                this.Location = mousePos;
                Sound_CTL.Current.PlaySound(Esound.HIT);
            }
            else
            {
                new_cell.CurrentPiece.Is_it_active = true;
            }
        }

        mousePos           = this.Location;
        mousePos.z         = -1;
        transform.position = mousePos;
        EndMove();
        if (_currentCell != old_cell)
        {
            is_it_moved = true;
            BaseGameCTL.Current.SwitchTurn();
            old_cell.SetCellState(Ecell_state.SELECTED);
        }
    }