コード例 #1
0
ファイル: BasePiece.cs プロジェクト: hnducnd98/Chess
    protected void SetNewLocation(Cell newCell)
    {
        var me = this;

        ChessBoard.Current.arrayLocationFuture[this.location.X, this.location.Y]       = 0;
        ChessBoard.Current.arrayLocationFuture[newCell.location.X, newCell.location.Y] = this.Info.Score;

        setPosCount++;
        if (setPosCount > 1)
        {
            this._currentCell.SetPiece(null);
        }

        this._currentCell = newCell;
        newCell.SetPiece(this);
        this.location = newCell.location;

        currentLocationX = newCell.location.X;
        currentLocationY = newCell.location.Y;

        //this.transform.position = offsetPosition + new Vector2(location.X * ChessBoard.Current.CELL_SIZE,
        //    location.Y * ChessBoard.Current.CELL_SIZE);

        this.transform.DOMove(offsetPosition + new Vector2(location.X * ChessBoard.Current.CELL_SIZE,
                                                           location.Y * ChessBoard.Current.CELL_SIZE), 0.75f);



        if ((this.Info.Score == 10 && this.location.Y == 7) || (this.Info.Score == -10 && this.location.Y == 0))
        {
            var pieceInfor = new PieceInfor();
            if (this.location.Y == 7)
            {
                pieceInfor.Name  = "W_QUEEN_" + ChessBoard.Current.indexQueenWhite;
                pieceInfor.Path  = "Pieces/W_QUEEN";
                pieceInfor.Score = 80;
                pieceInfor.X     = this.location.X;
                pieceInfor.Y     = this.location.Y;
                ChessBoard.Current.indexQueenWhite++;
            }
            else
            {
                pieceInfor.Name  = "B_QUEEN_" + ChessBoard.Current.indexQueenBlack;
                pieceInfor.Path  = "Pieces/B_QUEEN";
                pieceInfor.Score = 80;
                pieceInfor.X     = this.location.X;
                pieceInfor.Y     = this.location.Y;
                ChessBoard.Current.indexQueenBlack++;
            }

            GameObject.Destroy(this.gameObject);

            GameObject GO = GameObject.Instantiate <GameObject>(ResourceCTL.Instance.GetGameObject(pieceInfor.Path));
            GO.transform.parent = ChessBoard.Current.transform.GetChild(1);
            GO.name             = pieceInfor.Name;
            BasePiece p = GO.GetComponent <BasePiece>();
            //p.setInfor(pieceInfor, _cells[item.X][item.Y]);
            p.setInfor(pieceInfor, ChessBoard.Current.Cells[pieceInfor.X][pieceInfor.Y]);

            _currentCell.SetPiece(p);


            newCell._currentPiece.BeSelected();
            var list = new List <Cell>();
            foreach (var item in newCell._currentPiece._targetedCells)
            {
                list.Add(item);
            }
            var _pieceInfor = new EnemyInfor(newCell._currentPiece, list);
            if (this.Info.Score == 10)
            {
                ChessBoard.Current.whiteLifeCells.Add(_pieceInfor);
            }
            else
            {
                ChessBoard.Current.blackLifeCells.Add(_pieceInfor);
            }
            newCell._currentPiece.BeUnSelected();
        }
    }
コード例 #2
0
ファイル: BasePiece.cs プロジェクト: hnducnd98/Chess
 public void setInfor(PieceInfor info, Cell newCell)
 {
     Info = info;
     SetNewLocation(newCell);
 }