Text-based board game created in Java, where players can interact with a game board, create pieces, move them, and display the board.
This project simulates the movement of pieces on a board. The pieces can move in various directions with different movement capabilities. It includes both flexible and fast pieces with rules that prevent them from moving outside the board.
This project helped me revise my Object-Oriented Programming (OOP) skills and was part of my Data Structures and Algorithms (DSA) courses, where I applied core OOP concepts and problem-solving techniques to create an efficient and structured solution.
This project simulates the movement of the pieces on a board. The pieces can move in various directions with different movement capabilities. It includes both flexible and fast pieces with rules that prevent them from moving outside the board.
This project models a set of pieces that can move within a fixed 8x8 grid board. The movement of the pieces is based on their type (slow or fast) and whether they are flexible (able to move vertically or just horizontally).
- Slow pieces move one space at a time and cannot move off the board.
- Fast pieces can move multiple spaces but are restricted to not crossing the board boundaries.
- Flexible pieces can move both horizontally and vertically, with restrictions depending on their speed.
The Piece class represents a basic piece. It holds the name, color, and position of the piece.
Name: Name of the piece (e.g., Pawn, Knight).Colour: Color of the piece (e.g., White, Black).Position: APosobject representing the position of the piece on the board.
getName(): Returns the name of the piece.getColour(): Returns the color of the piece.getPosition(): Returns the position of the piece.setName(String name): Sets the name of the piece.setColour(String colour): Sets the color of the piece.setPosition(Pos position): Sets the position of the piece.toString(): Returns a string representation of the piece.
The Pos class represents the position of a piece on the board with x and y coordinates.
xpos: The x-coordinate of the piece.ypos: The y-coordinate of the piece.
getXpos(): Returns the x-coordinate.getYpos(): Returns the y-coordinate.setXpos(int xpos): Sets the x-coordinate.setYpos(int ypos): Sets the y-coordinate.moveXpos(int amount): Moves the piece horizontally.moveYpos(int amount): Moves the piece vertically.toString(): Returns a string representation of the position.
The SlowPiece class extends Piece and represents a piece that moves slowly.
move(String direction): Moves the piece left or right by one position if possible.
The SlowFlexible class extends SlowPiece and allows for vertical movement (up and down) in addition to horizontal movement.
move(String direction): Moves the piece left, right, up, or down by one position if possible.
The FastPiece class extends Piece and represents a piece that can move multiple spaces at once.
move(String direction, int n): Moves the piece left or right bynpositions if possible.
The FastFlexible class extends FastPiece and allows for vertical movement (up and down) in addition to horizontal movement.
move(String direction, int n): Moves the piece left, right, up, or down bynpositions if possible.
The Board class represents the board, where the pieces are placed and moved.
gameBoard: A 2D array representing the 8x8 grid of the board.
addNewPiece(boolean isFlexible, boolean isFast, String name, String colour, Pos position): Adds a new piece to the board at a specified position.moveAPiece(int xpos, int ypos, String direction, int spaces): Moves a piece on the board by a specified number of spaces in a given direction.