public override void showAvailableMoves(ChessBoardField[,] chessBoard, ChessBoardField nowBoard) { int[] coords = nowBoard.getCoords(); List <int[]> tempCoords = new List <int[]>(); tempCoords.Add(new int[] { (coords[0]), (coords[1] + 1) }); tempCoords.Add(new int[] { (coords[0]), (coords[1] - 1) }); tempCoords.Add(new int[] { (coords[0] + 1), (coords[1]) }); tempCoords.Add(new int[] { (coords[0] - 1), (coords[1]) }); tempCoords.Add(new int[] { (coords[0] + 1), (coords[1] + 1) }); tempCoords.Add(new int[] { (coords[0] + 1), (coords[1] - 1) }); tempCoords.Add(new int[] { (coords[0] - 1), (coords[1] - 1) }); tempCoords.Add(new int[] { (coords[0] - 1), (coords[1] + 1) }); tempCoords.ForEach((coords_) => { if (coords_[0] <= 7 && coords_[0] >= 0 && coords_[1] <= 7 && coords_[1] >= 0) { if (chessBoard[coords_[0], coords_[1]].getTeam() != nowBoard.getTeam()) { chessBoard[coords_[0], coords_[1]].setAvailableToGo(); addToTempAvialable(coords_[0], coords_[1]); } } }); }
public static void selectBoardField(ChessBoardField nowClickedBoard) { clickedBoard = nowClickedBoard; if (gameStart) { if (nowSelected == null) { if (!nowClickedBoard.hasFigure()) { return; } if (nowClickedBoard.getTeam() != nowSelectedTeam) { return; } nowSelected = nowClickedBoard; showAvailableMoves(); } else if (nowSelected != null) { if (TryToSelectTheSameFigure()) { nowSelected = null; clearHighlightedFields(); Figure.clearTempCoords(); return; } makeMove(); } } else { if (clickedBoard != null) { Figure newFigure = choosenFigureToAdd.generateFigure(); nowClickedBoard.setFigure(newFigure); } } }
public void testLoop(ChessBoardField[,] chessBoard, ChessBoardField nowBoard, List <int[]> array) { int tempCoordX, tempCoordY; int[] coords = nowBoard.getCoords(); bool found; array.ForEach((coords_) => { tempCoordX = coords[0]; tempCoordX += coords_[0]; tempCoordY = coords[1]; tempCoordY += coords_[1]; found = false; while (tempCoordX > -1 && tempCoordX < 8 && tempCoordY > -1 && tempCoordY < 8 && !found) { if (chessBoard[tempCoordX, tempCoordY].getTeam() == 0) { chessBoard[tempCoordX, tempCoordY].setAvailableToGo(); addToTempAvialable(tempCoordX, tempCoordY); } else { if (nowBoard.getTeam() != chessBoard[tempCoordX, tempCoordY].getTeam()) { chessBoard[tempCoordX, tempCoordY].setAvailableToGo(); addToTempAvialable(tempCoordX, tempCoordY); } found = true; } tempCoordX += coords_[0]; tempCoordY += coords_[1]; } }); }
public override void showAvailableMoves(ChessBoardField[,] chessBoard, ChessBoardField nowBoard) { var direction = (nowBoard.getTeam() == 1) ? "UP" : "DOWN"; int[] coords = nowBoard.getCoords(); if (direction == "UP") { if (coords[1] == 0) { return; } coords[1] -= 1; if (coords[1] < 0) { coords[1] = 0; } } else if (direction == "DOWN") { if (coords[1] == 7) { return; } coords[1] += 1; if (coords[1] > 7) { coords[1] = 8; } } if (chessBoard[coords[0], coords[1]].getTeam() == 0) { chessBoard[coords[0], coords[1]].setAvailableToGo(); tempCoords.Add(new int[] { coords[0], coords[1] }); } int tempRight = coords[0] + 1; if (tempRight <= 7 && chessBoard[tempRight, coords[1]].hasFigure() && chessBoard[tempRight, coords[1]].getTeam() != nowBoard.getTeam()) { chessBoard[tempRight, coords[1]].setAvailableToGo(); tempCoords.Add(new int[] { tempRight, coords[1] }); } int tempLeft = coords[0] - 1; if (tempLeft >= 0 && chessBoard[tempLeft, (coords[1])].hasFigure() && chessBoard[tempLeft, coords[1]].getTeam() != nowBoard.getTeam()) { chessBoard[tempLeft, coords[1]].setAvailableToGo(); tempCoords.Add(new int[] { tempLeft, coords[1] }); } if (firstMove) { coords[1] += (direction == "UP") ? -1 : 1; if (coords[1] < 0) { coords[1] = 0; } if (chessBoard[coords[0], coords[1]].getTeam() == 0) { chessBoard[coords[0], coords[1]].setAvailableToGo(); tempCoords.Add(new int[] { coords[0], coords[1] }); } firstMove = false; } }