public void base_checker_should_be_able_to_move_from_3_0_to_2_1() { BoardLocation start = new BoardLocation(3,0); BoardLocation end = new BoardLocation(2,1); BaseCheckerPiece piece = new BaseCheckerPiece(BlackWhiteColor.Black, start); bool expected = true; bool actual = piece.CanPieceMove(end); Assert.AreEqual(expected, actual); }
public void base_checker_should_not_be_able_to_move_to_a_white_space() { BoardLocation start = new BoardLocation(1,0); BoardLocation end = new BoardLocation(1,1); BaseCheckerPiece piece = new BaseCheckerPiece(BlackWhiteColor.Black, start); bool expected = false; bool actual = piece.CanPieceMove(end); Assert.AreEqual(expected, actual); }
public void base_checker_not_be_able_to_move_to_its_same_row_horizontally() { BoardLocation start = new BoardLocation(1,0); BoardLocation end = new BoardLocation(3,0); BaseCheckerPiece piece = new BaseCheckerPiece(BlackWhiteColor.Black, start); bool expected = false; bool actual = piece.CanPieceMove(end); Assert.AreEqual(expected, actual); }
public bool CanPieceMove(BoardLocation newLocation) { int moveDistance = Math.Abs (newLocation.Y) - Math.Abs (Location.Y); if (newLocation.GetSquareColor () == BlackWhiteColor.White || moveDistance > 1 || moveDistance == 0) { return false; } else { return true; } }
public bool MovePiece(IPiece piece, BoardLocation newLocation) { RemovePiece (piece); piece.Location = newLocation; AddPiece (piece); return true; // if (piece.CanPieceMove (newLocation)) // { // RemovePiece (piece); // piece.Location = newLocation; // AddPiece (piece); // return true; // } // else // { // return false; // } }
public Piece(PieceColor color, int x, int y) { Color = color; Location = new BoardLocation(x, y); }
public BaseCheckerPiece(BlackWhiteColor color, int x, int y) { PieceColor = color; Location = new BoardLocation(x, y); }
public BaseCheckerPiece(BlackWhiteColor color, BoardLocation location) { PieceColor = color; Location = location; }
private void RemoveCapturedPiece(BoardLocation captureLocation) { this.Controls.Remove(FindPiece(captureLocation) as Control); AdjustBoard(captureLocation, GridEntry.EMPTY); }
private void MovePiece(GamePiece movingPiece, BoardLocation EndLoc, GameState gameState) { _GameTurn.GameState = GameState.INMOVE; AdjustBoard(movingPiece.BoardLocation, GridEntry.EMPTY); Controls.Remove(movingPiece as Control); movingPiece.BoardLocation = EndLoc; if (movingPiece.IsPromoted == false && (EndLoc.Row == 0 || EndLoc.Row == 7)) { if (movingPiece.PieceState == GridEntry.WHITEPAWN && EndLoc.Row == 7) { KingPiece(movingPiece, GetImage("Checkers.Assets.WhiteKing.png"), GridEntry.WHITEKING); } if (movingPiece.PieceState == GridEntry.BLACKPAWN && EndLoc.Row == 0) { KingPiece(movingPiece, GetImage("Checkers.Assets.BlackKing.png"), GridEntry.BLACKKING); } } movingPiece.Location = new Point((LEFTMARGIN + TILESIZE * EndLoc.Column) + 10, (TOPMARGIN + TILESIZE * EndLoc.Row) + 10); this.Controls.Add(movingPiece); this.Controls.SetChildIndex(movingPiece, 1000); movingPiece.BringToFront(); _GameTurn.GameState = gameState; AdjustBoard(movingPiece.BoardLocation, movingPiece.PieceState); TurnChange(); }
private void AdjustBoard(BoardLocation location, GridEntry state) { _GameTurn.BOARDARRAY[location.Row, location.Column] = (int)state; }
private GamePiece FindPiece(BoardLocation loc) { foreach (Control c in this.Controls) { if (c is GamePiece) { if (((GamePiece)c).BoardLocation.Row == loc.Row && ((GamePiece)c).BoardLocation.Column == loc.Column) { return (GamePiece)c; } } } return null; }
private bool IsCaptureMove(GamePiece currentPiece, TilePiece destinationTile) { int row = currentPiece.BoardLocation.Row - destinationTile.BoardLocation.Row; int column = currentPiece.BoardLocation.Column - destinationTile.BoardLocation.Column; if (Math.Abs(row) > 2 || Math.Abs(column) > 2) return false; bool IsCapture = false; BoardLocation captureLoc = new BoardLocation(); if (currentPiece.PieceState == GridEntry.WHITEPAWN) { var land = new BoardLocation { Row = currentPiece.BoardLocation.Row + 2, Column = currentPiece.BoardLocation.Column - 2 }; if (destinationTile.BoardLocation.Row == land.Row && destinationTile.BoardLocation.Column == land.Column) { GridEntry cellState = (GridEntry)Enum.Parse(typeof(GridEntry), _GameTurn.BOARDARRAY[currentPiece.BoardLocation.Row + 1, currentPiece.BoardLocation.Column - 1].ToString()); IsCapture = cellState == GridEntry.BLACKPAWN || cellState == GridEntry.BLACKKING; captureLoc = new BoardLocation() { Row = currentPiece.BoardLocation.Row + 1, Column = currentPiece.BoardLocation.Column - 1 }; } land = new BoardLocation { Row = currentPiece.BoardLocation.Row + 2, Column = currentPiece.BoardLocation.Column + 2 }; if (destinationTile.BoardLocation.Row == land.Row && destinationTile.BoardLocation.Column == land.Column) { GridEntry cellState = (GridEntry)Enum.Parse(typeof(GridEntry), _GameTurn.BOARDARRAY[currentPiece.BoardLocation.Row + 1, currentPiece.BoardLocation.Column + 1].ToString()); IsCapture = cellState == GridEntry.BLACKPAWN || cellState == GridEntry.BLACKKING; captureLoc = new BoardLocation() { Row = currentPiece.BoardLocation.Row + 1, Column = currentPiece.BoardLocation.Column + 1 }; } } else if (currentPiece.PieceState == GridEntry.BLACKPAWN) { var land = new BoardLocation { Row = currentPiece.BoardLocation.Row - 2, Column = currentPiece.BoardLocation.Column - 2 }; if (destinationTile.BoardLocation.Row == land.Row && destinationTile.BoardLocation.Column == land.Column) { GridEntry cellState = (GridEntry)Enum.Parse(typeof(GridEntry), _GameTurn.BOARDARRAY[currentPiece.BoardLocation.Row - 1, currentPiece.BoardLocation.Column - 1].ToString()); IsCapture = cellState == GridEntry.WHITEPAWN || cellState == GridEntry.WHITEKING; captureLoc = new BoardLocation() { Row = currentPiece.BoardLocation.Row - 1, Column = currentPiece.BoardLocation.Column - 1 }; } land = new BoardLocation { Row = currentPiece.BoardLocation.Row - 2, Column = currentPiece.BoardLocation.Column + 2 }; if (destinationTile.BoardLocation.Row == land.Row && destinationTile.BoardLocation.Column == land.Column) { GridEntry cellState = (GridEntry)Enum.Parse(typeof(GridEntry), _GameTurn.BOARDARRAY[currentPiece.BoardLocation.Row - 1, currentPiece.BoardLocation.Column + 1].ToString()); IsCapture = cellState == GridEntry.WHITEPAWN || cellState == GridEntry.WHITEKING; captureLoc = new BoardLocation() { Row = currentPiece.BoardLocation.Row - 1, Column = currentPiece.BoardLocation.Column + 1 }; } } else if (currentPiece.IsPromoted) { if (currentPiece.PieceState == GridEntry.WHITEKING) { var land = new BoardLocation { Row = currentPiece.BoardLocation.Row - 2, Column = currentPiece.BoardLocation.Column - 2 }; if (destinationTile.BoardLocation.Row == land.Row && destinationTile.BoardLocation.Column == land.Column) { GridEntry cellState = (GridEntry)Enum.Parse(typeof(GridEntry), _GameTurn.BOARDARRAY[currentPiece.BoardLocation.Row - 1, currentPiece.BoardLocation.Column - 1].ToString()); IsCapture = cellState == GridEntry.BLACKPAWN || cellState == GridEntry.BLACKKING; captureLoc = new BoardLocation() { Row = currentPiece.BoardLocation.Row - 1, Column = currentPiece.BoardLocation.Column - 1 }; } land = new BoardLocation { Row = currentPiece.BoardLocation.Row - 2, Column = currentPiece.BoardLocation.Column + 2 }; if (destinationTile.BoardLocation.Row == land.Row && destinationTile.BoardLocation.Column == land.Column) { GridEntry cellState = (GridEntry)Enum.Parse(typeof(GridEntry), _GameTurn.BOARDARRAY[currentPiece.BoardLocation.Row - 1, currentPiece.BoardLocation.Column + 1].ToString()); IsCapture = cellState == GridEntry.BLACKPAWN || cellState == GridEntry.BLACKKING; captureLoc = new BoardLocation() { Row = currentPiece.BoardLocation.Row - 1, Column = currentPiece.BoardLocation.Column + 1 }; } land = new BoardLocation { Row = currentPiece.BoardLocation.Row + 2, Column = currentPiece.BoardLocation.Column + 2 }; if (destinationTile.BoardLocation.Row == land.Row && destinationTile.BoardLocation.Column == land.Column) { GridEntry cellState = (GridEntry)Enum.Parse(typeof(GridEntry), _GameTurn.BOARDARRAY[currentPiece.BoardLocation.Row + 1, currentPiece.BoardLocation.Column + 1].ToString()); IsCapture = cellState == GridEntry.BLACKPAWN || cellState == GridEntry.BLACKKING; captureLoc = new BoardLocation() { Row = currentPiece.BoardLocation.Row + 1, Column = currentPiece.BoardLocation.Column + 1 }; } land = new BoardLocation { Row = currentPiece.BoardLocation.Row + 2, Column = currentPiece.BoardLocation.Column - 2 }; if (destinationTile.BoardLocation.Row == land.Row && destinationTile.BoardLocation.Column == land.Column) { GridEntry cellState = (GridEntry)Enum.Parse(typeof(GridEntry), _GameTurn.BOARDARRAY[currentPiece.BoardLocation.Row + 1, currentPiece.BoardLocation.Column - 1].ToString()); IsCapture = cellState == GridEntry.BLACKPAWN || cellState == GridEntry.BLACKKING; captureLoc = new BoardLocation() { Row = currentPiece.BoardLocation.Row + 1, Column = currentPiece.BoardLocation.Column - 1 }; } } else if (currentPiece.PieceState == GridEntry.BLACKKING) { var land = new BoardLocation { Row = currentPiece.BoardLocation.Row - 2, Column = currentPiece.BoardLocation.Column - 2 }; if (destinationTile.BoardLocation.Row == land.Row && destinationTile.BoardLocation.Column == land.Column) { GridEntry cellState = (GridEntry)Enum.Parse(typeof(GridEntry), _GameTurn.BOARDARRAY[currentPiece.BoardLocation.Row - 1, currentPiece.BoardLocation.Column - 1].ToString()); IsCapture = cellState == GridEntry.WHITEPAWN || cellState == GridEntry.WHITEKING; captureLoc = new BoardLocation() { Row = currentPiece.BoardLocation.Row - 1, Column = currentPiece.BoardLocation.Column - 1 }; } land = new BoardLocation { Row = currentPiece.BoardLocation.Row - 2, Column = currentPiece.BoardLocation.Column + 2 }; if (destinationTile.BoardLocation.Row == land.Row && destinationTile.BoardLocation.Column == land.Column) { GridEntry cellState = (GridEntry)Enum.Parse(typeof(GridEntry), _GameTurn.BOARDARRAY[currentPiece.BoardLocation.Row - 1, currentPiece.BoardLocation.Column + 1].ToString()); IsCapture = cellState == GridEntry.WHITEPAWN || cellState == GridEntry.WHITEKING; captureLoc = new BoardLocation() { Row = currentPiece.BoardLocation.Row - 1, Column = currentPiece.BoardLocation.Column + 1 }; } land = new BoardLocation { Row = currentPiece.BoardLocation.Row + 2, Column = currentPiece.BoardLocation.Column + 2 }; if (destinationTile.BoardLocation.Row == land.Row && destinationTile.BoardLocation.Column == land.Column) { GridEntry cellState = (GridEntry)Enum.Parse(typeof(GridEntry), _GameTurn.BOARDARRAY[currentPiece.BoardLocation.Row + 1, currentPiece.BoardLocation.Column + 1].ToString()); IsCapture = cellState == GridEntry.WHITEPAWN || cellState == GridEntry.WHITEKING; captureLoc = new BoardLocation() { Row = currentPiece.BoardLocation.Row + 1, Column = currentPiece.BoardLocation.Column + 1 }; } land = new BoardLocation { Row = currentPiece.BoardLocation.Row + 2, Column = currentPiece.BoardLocation.Column - 2 }; if (destinationTile.BoardLocation.Row == land.Row && destinationTile.BoardLocation.Column == land.Column) { GridEntry cellState = (GridEntry)Enum.Parse(typeof(GridEntry), _GameTurn.BOARDARRAY[currentPiece.BoardLocation.Row + 1, currentPiece.BoardLocation.Column - 1].ToString()); IsCapture = cellState == GridEntry.WHITEPAWN || cellState == GridEntry.WHITEKING; captureLoc = new BoardLocation() { Row = currentPiece.BoardLocation.Row + 1, Column = currentPiece.BoardLocation.Column - 1 }; } } } if (IsCapture) { this.Controls.Remove(FindPiece(captureLoc) as Control); _GameTurn.BOARDARRAY[captureLoc.Row, captureLoc.Column] = (int)GridEntry.EMPTY; } return IsCapture; }