public void doMove(bool cap, BoardTile from, BoardTile to) { to.setPiece(from.getPiece()); if (to.y == 0 || to.y == 7) { to.getPiece().setKing(true); } from.remPiece(); if (!cap) { turn = 1 - turn; //Switch player } else { if (to.x > from.x) { if (to.y > from.y) { //LR boardRecs[from.x + 1, from.y + 1].remPiece(); } else { //UR boardRecs[from.x + 1, from.y - 1].remPiece(); } } else { if (to.y > from.y) { //LL boardRecs[from.x - 1, from.y + 1].remPiece(); } else { //UL boardRecs[from.x - 1, from.y - 1].remPiece(); } } } moves = new List<BoardTile>(); caps = new List<BoardTile>(); }
public void onClick(MouseState m) { BoardTile sel = getClicked(m); if (sel == null) return; //See if sel is in moves foreach (BoardTile bt in moves) { if (sel.Equals(bt)) { doMove(false, selected, sel); return; } } foreach (BoardTile bt in caps) { if (sel.Equals(bt)) { doMove(true, selected, sel); return; } } selected = sel; //Set move options moves = new List<BoardTile>(); caps = new List<BoardTile>(); if (!selected.hasPiece()) return; //No piece, return Piece p = selected.getPiece(); if (p.getColor() != turn) return; //Not correct color, return BoardTile t_move; //Black if (p.getColor() == PColor.black) { ////////////////////// Upper - Left if (selected.x > 0 && selected.y > 0) { t_move = boardRecs[selected.x - 1, selected.y - 1]; if (t_move.hasPiece()) { //Test for capture if (t_move.getPiece().getColor() != turn) { if (selected.x > 1 && selected.y > 1) { if (!boardRecs[selected.x - 2, selected.y - 2].hasPiece()) { //Can capture caps.Add(boardRecs[selected.x - 2, selected.y - 2]); } } } } else { //Empty moves.Add(t_move); } } ///////////////////////////// Upper - Right if (selected.x < 7 && selected.y > 0) { t_move = boardRecs[selected.x + 1, selected.y - 1]; if (t_move.hasPiece()) { //Test for capture if (t_move.getPiece().getColor() != turn) { if (selected.x < 6 && selected.y > 1) { if (!boardRecs[selected.x + 2, selected.y - 2].hasPiece()) { //Can capture caps.Add(boardRecs[selected.x + 2, selected.y - 2]); } } } } else { //Empty moves.Add(t_move); } } ////////////////////////// Kings Only if (p.isKing()) { //////////////////////// Lower - Left if (selected.x > 0 && selected.y < 7) { t_move = boardRecs[selected.x - 1, selected.y + 1]; if (t_move.hasPiece()) { //Test for capture if (t_move.getPiece().getColor() != turn) { if (selected.x > 1 && selected.y < 6) { if (!boardRecs[selected.x - 2, selected.y + 2].hasPiece()) { //Can capture caps.Add(boardRecs[selected.x - 2, selected.y + 2]); } } } } else { //Empty moves.Add(t_move); } } /////////////////////// Lower - Right if (selected.x < 7 && selected.y < 7) { t_move = boardRecs[selected.x + 1, selected.y + 1]; if (t_move.hasPiece()) { //Test for capture if (t_move.getPiece().getColor() != turn) { if (selected.x < 6 && selected.y < 6) { if (!boardRecs[selected.x + 2, selected.y + 2].hasPiece()) { //Can capture caps.Add(boardRecs[selected.x + 2, selected.y + 2]); } } } } else { //Empty moves.Add(t_move); } } } // End Kings } // End Black else { ///////////// Red //////////////////////// Lower - Left if (selected.x > 0 && selected.y < 7) { t_move = boardRecs[selected.x - 1, selected.y + 1]; if (t_move.hasPiece()) { //Test for capture if (t_move.getPiece().getColor() != turn) { if (selected.x > 1 && selected.y < 6) { if (!boardRecs[selected.x - 2, selected.y + 2].hasPiece()) { //Can capture caps.Add(boardRecs[selected.x - 2, selected.y + 2]); } } } } else { //Empty moves.Add(t_move); } } /////////////////////// Lower - Right if (selected.x < 7 && selected.y < 7) { t_move = boardRecs[selected.x + 1, selected.y + 1]; if (t_move.hasPiece()) { //Test for capture if (t_move.getPiece().getColor() != turn) { if (selected.x < 6 && selected.y < 6) { if (!boardRecs[selected.x + 2, selected.y + 2].hasPiece()) { //Can capture caps.Add(boardRecs[selected.x + 2, selected.y + 2]); } } } } else { //Empty moves.Add(t_move); } } ////////////////////////// Kings Only if (p.isKing()) { ////////////////////// Upper - Left if (selected.x > 0 && selected.y > 0) { t_move = boardRecs[selected.x - 1, selected.y - 1]; if (t_move.hasPiece()) { //Test for capture if (t_move.getPiece().getColor() != turn) { if (selected.x > 1 && selected.y > 1) { if (!boardRecs[selected.x - 2, selected.y - 2].hasPiece()) { //Can capture caps.Add(boardRecs[selected.x - 2, selected.y - 2]); } } } } else { //Empty moves.Add(t_move); } } ///////////////////////////// Upper - Right if (selected.x < 7 && selected.y > 0) { t_move = boardRecs[selected.x + 1, selected.y - 1]; if (t_move.hasPiece()) { //Test for capture if (t_move.getPiece().getColor() != turn) { if (selected.x < 6 && selected.y > 1) { if (!boardRecs[selected.x + 2, selected.y - 2].hasPiece()) { //Can capture caps.Add(boardRecs[selected.x + 2, selected.y - 2]); } } } } else { //Empty moves.Add(t_move); } } } // End Kings } //End Red }