private void selectPawn(Position position) { tempPos = position; selectedPosition = position; selectedPosition.isSelected = true; Invalidate(); Update(); }
private void setDiferencesXY(Position currPos, out int differenceX, out int differenceY) { differenceX = tempPos.getX() - currPos.getX(); differenceY = tempPos.getY() - currPos.getY(); }
private void movePawn(Position currPos) { currPos.setPawn(tempPos.getPawn()); // set pawn on position deletePawn(); }
private void movePawnToEmptySpace(Position selectedPosition) { int distanceX; int distanceY; setDiferencesXY(selectedPosition, out distanceX, out distanceY); if (isMoveAllowed(selectedPosition, distanceX, distanceY)) { movePawn(selectedPosition); nextPlayerTurn(); } }
private bool isMoveAllowed(Position selectedPosition, int distanceX, int distanceY) { return checkMoveAllowance(selectedPosition, distanceX, distanceY, 1) || (checkMoveAllowance(selectedPosition, distanceX, distanceY, 2) && checkForNearbyPieces(selectedPosition, distanceX, distanceY)); }
private bool isPositionsEqual(Position pos1, Position pos2) { if (pos1 != null && pos2 != null) { if (pos1.getX() == pos2.getX() && pos1.getY() == pos2.getY()) return true; } return false; }
private void drawCell(Graphics g, int marginX, int marginY, int incValue, int a, int y, int x) { Brush cellColor; if (isPositionEven(y, x)) cellColor = new SolidBrush(Color.White); else cellColor = new SolidBrush(Color.Black); if (validateSelectedPosition(y, x)) cellColor = new SolidBrush(Color.LightGreen); if (isGeneratedStartPawnSet == false) positions[x, y] = new Position(); g.FillRectangle(cellColor, marginX + x * incValue, marginY + y * incValue, a, a); }
private void deselectPawn() { selectedPosition.isSelected = false; tempPos = null; Invalidate(); Update(); }
private bool checkPlayerTurn(Position pos) { if (!pos.isEmpty && pos.getPawn().getColor().Equals(players[playerNrAllowedToMove].color)) return true; else { MessageBox.Show("It's "+ (players[playerNrAllowedToMove].color.Name) + " Player move!"); return false; } }
private bool checkMoveAllowance(Position selectedPosition, int distanceX, int distanceY, int radius) { return checkPosition(distanceX, distanceY, radius) && selectedPosition.isEmpty; }
private static bool checkForNearbyPieces(Position selectedPosition, int distanceX, int distance) { return !positions[selectedPosition.getX() + ((distanceX != 0 ? (distanceX > 0 ? distanceX - 1 : distanceX + 1) : 0)), selectedPosition.getY() + ((distance != 0 ? (distance > 0 ? distance - 1 : distance + 1) : 0))].isEmpty; }