示例#1
0
 public override void AddMoveForwardRight(Checker checker)
 {
     AllowedMoves.Add(new Move(checker,
                               TableCells.Cell[
                                   (checker.PlayerMoveDirection == PlayerMoveDirection.BottomTop) ? checker.Cell.X + 1 : checker.Cell.X - 1,
                                   (checker.PlayerMoveDirection == PlayerMoveDirection.BottomTop) ? checker.Cell.Y - 1 : checker.Cell.Y + 1]));
 }
示例#2
0
文件: Piece.cs 项目: wojciechN9/Chess
        public bool IsCorrectMove(Position newPosition)
        {
            var allowedMove = AllowedMoves.FirstOrDefault(
                p => p.Col == newPosition.Col && p.Row == newPosition.Row);

            return(allowedMove != null);
        }
示例#3
0
    protected void manageCoverUnderPiece()
    {
        Cell localCell = TransformVectorToCell(transform.position);

        if (localCell != cellNow)
        {
            if (coverUnderPiece != null)
            {
                Destroy(coverUnderPiece);
                coverUnderPiece = null;
            }
            cellNow = localCell;
            if ((cellNow == null) || (cellNow.Equals(cell)))
            {
                return;
            }

            if (AllowedMoves.Contains(cellNow))
            {
                coverUnderPiece = Instantiate(possibleMoveObject);
            }
            else
            {
                coverUnderPiece = Instantiate(wrongMoveObject);
            }
            coverUnderPiece.transform.position = startBoardPoint + new Vector3(localCell.Vertical, localCell.Horizontal, 0) * deltaCell +
                                                 new Vector3(5, 5, 0.1f);
        }
    }
示例#4
0
 public override void AddMoveBackwardRight(Checker checker, Checker[] killed, out Move move)
 {
     move = new Move(checker,
                     TableCells.Cell[
                         (checker.PlayerMoveDirection == PlayerMoveDirection.BottomTop) ? checker.Cell.X + 2 : checker.Cell.X - 2,
                         (checker.PlayerMoveDirection == PlayerMoveDirection.BottomTop) ? checker.Cell.Y + 2 : checker.Cell.Y - 2],
                     killed);
     AllowedMoves.Add(move);
 }
示例#5
0
 public override void AddMoveBackwardRight(Checker checker)
 {
     for (int i = Cell.X + 1, j = Cell.Y + 1; i < 8 && j < 8; i++, j++)
     {
         if (TableCells.Cell[i, j].IsClear())
         {
             AllowedMoves.Add(new Move(checker, TableCells.Cell[i, j]));
         }
         else
         {
             break;
         }
     }
 }
示例#6
0
 public override void AddMoveForwardLeft(Checker checker)
 {
     for (int i = Cell.X - 1, j = Cell.Y - 1; i >= 0 && j >= 0; i--, j--)
     {
         if (TableCells.Cell[i, j].IsClear())
         {
             AllowedMoves.Add(new Move(checker, TableCells.Cell[i, j]));
         }
         else
         {
             break;
         }
     }
 }
示例#7
0
 public override void AddMoveBackwardRight(Checker checker, Checker[] killed, out Move move)
 {
     move = null;
     for (int i = killed.Last().Cell.X + 1, j = killed.Last().Cell.Y + 1; i < 8 && j < 8; i++, j++)
     {
         if (TableCells.Cell[i, j].IsClear())
         {
             move = new Move(checker, TableCells.Cell[i, j], killed);
             AllowedMoves.Add(move);
         }
         else
         {
             break;
         }
     }
 }
示例#8
0
 public override void AddMoveForwardLeft(Checker checker, Checker[] killed, out Move move)
 {
     move = null;
     for (int i = killed.Last().Cell.X - 1, j = killed.Last().Cell.Y - 1; i >= 0 && j >= 0; i--, j--)
     {
         if (TableCells.Cell[i, j].IsClear())
         {
             move = new Move(checker, TableCells.Cell[i, j], killed);
             AllowedMoves.Add(move);
         }
         else
         {
             break;
         }
     }
 }
示例#9
0
    void OnMouseUp()
    {
        if (!isDragged)
        {
            return;
        }

        if (coverUnderPiece != null)
        {
            Destroy(coverUnderPiece);
            coverUnderPiece = null;
        }
        isDragged = false;
        Cell moveCell = TransformVectorToCell(transform.position);

        if ((moveCell == null) || (!AllowedMoves.Contains(moveCell)))
        {
            Move(cell);
            return;
        }
        NotifyMove(cell, moveCell);
    }
示例#10
0
 /// <summary>
 /// Checks if the requested <see cref="move"/> is legally able to be learned.
 /// </summary>
 /// <param name="move">Move to check if can be learned</param>
 /// <returns>True if can learn the move</returns>
 public bool CanLearn(int move) => AllowedMoves.Contains(move);
示例#11
0
    private void Update()
    {
        //UpdateSelection();
        //DrawChessboard();

        if (!isWhiteTurn)
        {
            if (selectedChessman == null)
            {
                var      blackPieces = activeChessman.Where(t => t.GetComponent <Chessman>().isWhite.Equals(false));
                Chessman cm          = blackPieces.ElementAt((int)UnityEngine.Random.Range(0f, blackPieces.Count() - 1)).GetComponent <Chessman>();
                SelectChessman(cm.CurrentX, cm.CurrentY);
                //SelectChessman(x,y);
            }
            else
            {
                if (timer >= 0f)
                {
                    timer -= Time.deltaTime;
                    return;
                }
                timer = TimerStartValue;

                List <Tile>    collection = new List <Tile>();
                List <Vector2> moves      = new List <Vector2>();
                for (int i = 0; i < AllowedMoves.GetLength(0); i++)
                {
                    for (int j = 0; j < AllowedMoves.GetLength(1); j++)
                    {
                        if (AllowedMoves[i, j] == true)
                        {
                            Tile tileNew = new Tile();
                            tileNew.pos = new Vector2(i, j);
                            //tileNew.whiteIs = (Chessmans[i, j].isWhite) ? true : false;
                            if (Chessmans[i, j] != null && Chessmans[i, j].isWhite)
                            {
                                tileNew.whiteIs = Chessmans[i, j].isWhite;
                                collection.Add(tileNew);
                            }
                            else
                            {
                                moves.Add(new Vector2(i, j));
                            }
                        }
                    }
                }

                if (collection.Count > 0)
                {
                    Tile tile = collection[UnityEngine.Random.Range(0, collection.Count - 1)];
                    MoveChessman((int)tile.pos.x, (int)tile.pos.y);
                }
                else
                {
                    Vector2 newPos = moves[UnityEngine.Random.Range(0, moves.Count - 1)];
                    MoveChessman((int)newPos.x, (int)newPos.y);
                }

                //newMove = collection[(int)UnityEngine.Random.Range(0f, collection.Count - 1)];
                //MoveChessman((int)newMove.x, (int)newMove.y);
            }
        }

        if (isFocused == true)
        {
            if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, LayerMask.GetMask("ChessPlane")))
            {
                //Debug.Log(hit.point);
                selectionX = (int)(hit.point.x / TILE_SIZE);
                selectionY = (int)(hit.point.z / TILE_SIZE);
                Debug.Log("x" + selectionX);
                Debug.Log("y" + selectionY);
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            if (selectionX >= 0 && selectionY >= 0)
            {
                if (selectedChessman == null)
                {
                    SelectChessman(selectionX, selectionY);
                }
                else
                {
                    MoveChessman(selectionX, selectionY);
                }
            }
        }
    }