Added missing javadoc
This commit is contained in:
parent
8da04452e1
commit
20b973662c
|
@ -39,10 +39,10 @@ public abstract class AbstractPiece implements IPiece {
|
|||
|
||||
/**
|
||||
* Create new piece
|
||||
* @param chessboard chessboard
|
||||
* @param x piece's X location
|
||||
* @param y piece's Y location
|
||||
* @param color piece's color
|
||||
* @param chessboard chessboard
|
||||
* @param x piece's X location
|
||||
* @param y piece's Y location
|
||||
* @param color piece's color
|
||||
*/
|
||||
public AbstractPiece(Chessboard chessboard, int x, int y, PieceColor color) {
|
||||
this.x = x;
|
||||
|
@ -54,8 +54,8 @@ public abstract class AbstractPiece implements IPiece {
|
|||
|
||||
/**
|
||||
* Create Path2D object from points
|
||||
* @param points object's points
|
||||
* @return Path2D object
|
||||
* @param points object's points
|
||||
* @return Path2D object
|
||||
*/
|
||||
public Path2D getObject(double[][] points) {
|
||||
Path2D object = new Path2D.Double();
|
||||
|
@ -70,9 +70,9 @@ public abstract class AbstractPiece implements IPiece {
|
|||
|
||||
/**
|
||||
* Create Path2D object from points
|
||||
* @param xPoints object's X points
|
||||
* @param yPoints object's Y points
|
||||
* @return Path2D object
|
||||
* @param xPoints object's X points
|
||||
* @param yPoints object's Y points
|
||||
* @return Path2D object
|
||||
*/
|
||||
public Path2D getObject(double[] xPoints, double[] yPoints) {
|
||||
double[][] points = new double[xPoints.length][];
|
||||
|
@ -86,11 +86,11 @@ public abstract class AbstractPiece implements IPiece {
|
|||
|
||||
/**
|
||||
* Create Ellipse2D from specified coordinates
|
||||
* @param x ellipse's X coordinate
|
||||
* @param y ellipse's Y coordinate
|
||||
* @param w ellipse width
|
||||
* @param h ellipse height
|
||||
* @return Ellipse2D object
|
||||
* @param x ellipse's X coordinate
|
||||
* @param y ellipse's Y coordinate
|
||||
* @param w ellipse width
|
||||
* @param h ellipse height
|
||||
* @return Ellipse2D object
|
||||
*/
|
||||
public Ellipse2D getEllipse(double x, double y, double w, double h) {
|
||||
return new Ellipse2D.Double(x, y, w, h);
|
||||
|
@ -98,7 +98,7 @@ public abstract class AbstractPiece implements IPiece {
|
|||
|
||||
/**
|
||||
* Create piece's stand
|
||||
* @return Path2D stand
|
||||
* @return Path2D stand
|
||||
*/
|
||||
public Path2D getStand() {
|
||||
|
||||
|
@ -108,9 +108,9 @@ public abstract class AbstractPiece implements IPiece {
|
|||
double[][] points = new double[xStand.length][];
|
||||
for (int i = 0; i < points.length; i++) {
|
||||
if(i == 4) {
|
||||
points[i] = new double[]{xStand[i], yStand[i], 69, 80, 69, 80};
|
||||
points[i] = new double[]{xStand[i], yStand[i], 69+3, 80-5, 69-3, 80+5};
|
||||
} else if(i == 8) {
|
||||
points[i] = new double[]{xStand[i], yStand[i], 31, 80, 31, 80};
|
||||
points[i] = new double[]{xStand[i], yStand[i], 31+3, 80+5, 31-3, 80-5};
|
||||
} else {
|
||||
points[i] = new double[2];
|
||||
points[i][0] = xStand[i];
|
||||
|
@ -125,8 +125,8 @@ public abstract class AbstractPiece implements IPiece {
|
|||
|
||||
/**
|
||||
* Paint specified objects
|
||||
* @param g2 Graphics2D
|
||||
* @param objects painted objects
|
||||
* @param g2 Graphics2D
|
||||
* @param objects painted objects
|
||||
*/
|
||||
public void paintObjects(Graphics2D g2, Shape[] objects) {
|
||||
g2.setStroke(new BasicStroke(7));
|
||||
|
@ -138,6 +138,10 @@ public abstract class AbstractPiece implements IPiece {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set piece's new position
|
||||
* @param pos piece position
|
||||
*/
|
||||
public void setPosition(PiecePosition pos) {
|
||||
chessboard.removePiece(x, y);
|
||||
x = pos.x;
|
||||
|
@ -145,23 +149,44 @@ public abstract class AbstractPiece implements IPiece {
|
|||
chessboard.addPiece(this, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set override location if piece is floating
|
||||
* @param x floating piece's X location
|
||||
* @param y floating piece's Y location
|
||||
*/
|
||||
public void setOverride(double x, double y) {
|
||||
overrideX = x;
|
||||
overrideY = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get piece's override X location
|
||||
* @return override X location
|
||||
*/
|
||||
public double getOverrideX() {
|
||||
return overrideX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get piece's override Y location
|
||||
* @return override Y location
|
||||
*/
|
||||
public double getOverrideY() {
|
||||
return overrideY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get piece's X location
|
||||
* @return piece's X location
|
||||
*/
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get piece's Y location
|
||||
* @return piece's Y location
|
||||
*/
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
|
|
@ -2,12 +2,26 @@ import java.awt.*;
|
|||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
|
||||
/**
|
||||
* Bishop piece class
|
||||
*/
|
||||
public class Bishop extends AbstractPiece {
|
||||
|
||||
/**
|
||||
* Create new Bishop piece
|
||||
* @param chessboard chessboard
|
||||
* @param x piece's X location
|
||||
* @param y piece's Y location
|
||||
* @param color piece's color
|
||||
*/
|
||||
public Bishop(Chessboard chessboard, int x, int y, PieceColor color) {
|
||||
super(chessboard, x, y, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint the Bishop piece
|
||||
* @param g2 Graphics2D
|
||||
*/
|
||||
@Override
|
||||
public void paint(Graphics2D g2) {
|
||||
|
||||
|
|
|
@ -6,6 +6,10 @@ import java.awt.*;
|
|||
*/
|
||||
public class Chess {
|
||||
|
||||
/**
|
||||
* Create the main window and chessboard with pieces
|
||||
* @param args command-line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
JFrame okno = new JFrame();
|
||||
|
|
|
@ -66,9 +66,9 @@ public class Chessboard extends JPanel {
|
|||
|
||||
/**
|
||||
* Add passed piece to the specified coordinates
|
||||
* @param piece piece
|
||||
* @param x piece's X location
|
||||
* @param y piese's Y location
|
||||
* @param piece piece
|
||||
* @param x piece's X location
|
||||
* @param y piese's Y location
|
||||
*/
|
||||
public void addPiece(IPiece piece, int x, int y) {
|
||||
pieces[y][x] = piece;
|
||||
|
@ -76,9 +76,9 @@ public class Chessboard extends JPanel {
|
|||
|
||||
/**
|
||||
* Remove piece at specified coordinates
|
||||
* @param x piece's X location
|
||||
* @param y piece's Y location
|
||||
* @return removed piece
|
||||
* @param x piece's X location
|
||||
* @param y piece's Y location
|
||||
* @return removed piece
|
||||
*/
|
||||
public IPiece removePiece(int x, int y) {
|
||||
IPiece piece = pieces[y][x];
|
||||
|
@ -88,7 +88,7 @@ public class Chessboard extends JPanel {
|
|||
|
||||
/**
|
||||
* Paint the chessboard
|
||||
* @param g the <code>Graphics</code> context in which to paint
|
||||
* @param g the <code>Graphics</code> context in which to paint
|
||||
*/
|
||||
public void paint(Graphics g) {
|
||||
|
||||
|
@ -164,9 +164,9 @@ public class Chessboard extends JPanel {
|
|||
|
||||
/**
|
||||
* Get coordinates of piece from mouse X and Y location
|
||||
* @param x mouse X location
|
||||
* @param y mouse Y location
|
||||
* @return piece position
|
||||
* @param x mouse X location
|
||||
* @param y mouse Y location
|
||||
* @return piece position
|
||||
*/
|
||||
public PiecePosition getPieceCoordinates(int x, int y) {
|
||||
int pieceX = (int) ((x-startX)/(SQUARE_SIZE*boardScale));
|
||||
|
@ -179,8 +179,8 @@ public class Chessboard extends JPanel {
|
|||
|
||||
/**
|
||||
* Get piece on specified piece position
|
||||
* @param pos piece position
|
||||
* @return piece
|
||||
* @param pos piece position
|
||||
* @return piece
|
||||
*/
|
||||
public IPiece getPiece(PiecePosition pos) {
|
||||
return pieces[pos.y][pos.x];
|
||||
|
@ -188,8 +188,8 @@ public class Chessboard extends JPanel {
|
|||
|
||||
/**
|
||||
* Grab piece at specified position and mark it as floating
|
||||
* @param pos piece position
|
||||
* @return piece
|
||||
* @param pos piece position
|
||||
* @return piece
|
||||
*/
|
||||
public IPiece grabPiece(PiecePosition pos) {
|
||||
IPiece piece = getPiece(pos);
|
||||
|
@ -200,7 +200,7 @@ public class Chessboard extends JPanel {
|
|||
|
||||
/**
|
||||
* Get current floating piece
|
||||
* @return floating piece
|
||||
* @return floating piece
|
||||
*/
|
||||
public IPiece getFloatingPiece() {
|
||||
return floating;
|
||||
|
@ -208,7 +208,7 @@ public class Chessboard extends JPanel {
|
|||
|
||||
/**
|
||||
* Return piece at specified position to the board and unmark it from floating
|
||||
* @param pos piece position
|
||||
* @param pos piece position
|
||||
*/
|
||||
public void returnPiece(PiecePosition pos) {
|
||||
if(floating != null) {
|
||||
|
|
|
@ -6,6 +6,10 @@ import java.awt.event.MouseEvent;
|
|||
*/
|
||||
public class ChessboardMouseAdapter extends MouseAdapter {
|
||||
|
||||
/**
|
||||
* Detect mouse press and select the piece
|
||||
* @param me mouse event
|
||||
*/
|
||||
public void mousePressed(MouseEvent me) {
|
||||
Chessboard c = (Chessboard) me.getSource();
|
||||
PiecePosition pos = c.getPieceCoordinates(me.getX(), me.getY());
|
||||
|
@ -17,6 +21,10 @@ public class ChessboardMouseAdapter extends MouseAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect mouse dragging and show floating piece
|
||||
* @param me mouse event
|
||||
*/
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent me) {
|
||||
Chessboard c = (Chessboard) me.getSource();
|
||||
|
@ -28,6 +36,10 @@ public class ChessboardMouseAdapter extends MouseAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletect mouse release and place piece on the chessboard
|
||||
* @param me mouse event
|
||||
*/
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent me) {
|
||||
Chessboard c = (Chessboard) me.getSource();
|
||||
|
|
|
@ -6,45 +6,45 @@ import java.awt.*;
|
|||
public interface IPiece {
|
||||
|
||||
/**
|
||||
* Paint piece
|
||||
* @param g2 Graphics2D
|
||||
* Paint the piece
|
||||
* @param g2 Graphics2D
|
||||
*/
|
||||
void paint(Graphics2D g2);
|
||||
|
||||
/**
|
||||
* Get piece's X location
|
||||
* @return piece's X location
|
||||
* @return piece's X location
|
||||
*/
|
||||
int getX();
|
||||
|
||||
/**
|
||||
* Get piece's Y location
|
||||
* @return piece's Y location
|
||||
* @return piece's Y location
|
||||
*/
|
||||
int getY();
|
||||
|
||||
/**
|
||||
* Set override location if piece is floating
|
||||
* @param x floating piece's X location
|
||||
* @param y floating piece's Y location
|
||||
* @param x floating piece's X location
|
||||
* @param y floating piece's Y location
|
||||
*/
|
||||
void setOverride(double x, double y);
|
||||
|
||||
/**
|
||||
* Get piece's override X location
|
||||
* @return override X location
|
||||
* @return override X location
|
||||
*/
|
||||
double getOverrideX();
|
||||
|
||||
/**
|
||||
* Get piece's override Y location
|
||||
* @return override Y location
|
||||
* @return override Y location
|
||||
*/
|
||||
double getOverrideY();
|
||||
|
||||
/**
|
||||
* Set piece's new position
|
||||
* @param pos piece position
|
||||
* @param pos piece position
|
||||
*/
|
||||
void setPosition(PiecePosition pos);
|
||||
|
||||
|
|
|
@ -3,12 +3,26 @@ import java.awt.geom.Area;
|
|||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Path2D;
|
||||
|
||||
/**
|
||||
* King piece class
|
||||
*/
|
||||
public class King extends AbstractPiece {
|
||||
|
||||
/**
|
||||
* Create new King piece
|
||||
* @param chessboard chessboard
|
||||
* @param x piece's X location
|
||||
* @param y piece's Y location
|
||||
* @param color piece's color
|
||||
*/
|
||||
public King(Chessboard chessboard, int x, int y, PieceColor color) {
|
||||
super(chessboard, x, y, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint the King piece
|
||||
* @param g2 Graphics2D
|
||||
*/
|
||||
@Override
|
||||
public void paint(Graphics2D g2) {
|
||||
|
||||
|
|
|
@ -1,11 +1,25 @@
|
|||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Knight piece class
|
||||
*/
|
||||
public class Knight extends AbstractPiece {
|
||||
|
||||
/**
|
||||
* Create new Knight piece
|
||||
* @param chessboard chessboard
|
||||
* @param x piece's X location
|
||||
* @param y piece's Y location
|
||||
* @param color piece's color
|
||||
*/
|
||||
public Knight(Chessboard chessboard, int x, int y, PieceColor color) {
|
||||
super(chessboard, x, y, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint the Knight piece
|
||||
* @param g2 Graphics2D
|
||||
*/
|
||||
@Override
|
||||
public void paint(Graphics2D g2) {
|
||||
|
||||
|
|
|
@ -1,12 +1,25 @@
|
|||
import java.awt.*;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
|
||||
/**
|
||||
* Pawn piece class
|
||||
*/
|
||||
public class Pawn extends AbstractPiece {
|
||||
|
||||
/**
|
||||
* Create new Pawn piece
|
||||
* @param chessboard chessboard
|
||||
* @param x piece's X location
|
||||
* @param y piece's Y location
|
||||
* @param color piece's color
|
||||
*/
|
||||
public Pawn(Chessboard chessboard, int x, int y, PieceColor color) {
|
||||
super(chessboard, x, y, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint the Pawn piece
|
||||
* @param g2 Graphics2D
|
||||
*/
|
||||
@Override
|
||||
public void paint(Graphics2D g2) {
|
||||
|
||||
|
|
|
@ -1,14 +1,38 @@
|
|||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Piece colors enum
|
||||
*/
|
||||
public enum PieceColor {
|
||||
|
||||
/**
|
||||
* Black color with white border
|
||||
*/
|
||||
BLACK(Color.BLACK, Color.WHITE),
|
||||
|
||||
/**
|
||||
* White color with black border
|
||||
*/
|
||||
WHITE(Color.WHITE, Color.BLACK);
|
||||
|
||||
/**
|
||||
* Fill color
|
||||
*/
|
||||
Color fill;
|
||||
|
||||
/**
|
||||
* Draw color
|
||||
*/
|
||||
Color draw;
|
||||
|
||||
/**
|
||||
* PieceColor constructor
|
||||
* @param fillColor fill color
|
||||
* @param drawColor draw color
|
||||
*/
|
||||
PieceColor(Color fillColor, Color drawColor) {
|
||||
fill = fillColor;
|
||||
draw = drawColor;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,26 @@
|
|||
/**
|
||||
* Piece position class
|
||||
*/
|
||||
public class PiecePosition {
|
||||
|
||||
/**
|
||||
* Piece's X location
|
||||
*/
|
||||
public int x;
|
||||
|
||||
/**
|
||||
* Piece's Y location
|
||||
*/
|
||||
public int y;
|
||||
|
||||
/**
|
||||
* PiecePosition constructor
|
||||
* @param x piece's X location
|
||||
* @param y piece's Y location
|
||||
*/
|
||||
public PiecePosition(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PiecePosition{" +
|
||||
"x=" + x +
|
||||
", y=" + y +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,25 @@
|
|||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Queen piece class
|
||||
*/
|
||||
public class Queen extends AbstractPiece {
|
||||
|
||||
/**
|
||||
* Create new Queen piece
|
||||
* @param chessboard chessboard
|
||||
* @param x piece's X location
|
||||
* @param y piece's Y location
|
||||
* @param color piece's color
|
||||
*/
|
||||
public Queen(Chessboard chessboard, int x, int y, PieceColor color) {
|
||||
super(chessboard, x, y, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint the Queen piece
|
||||
* @param g2 Graphics2D
|
||||
*/
|
||||
@Override
|
||||
public void paint(Graphics2D g2) {
|
||||
|
||||
|
|
|
@ -1,11 +1,25 @@
|
|||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Rook piece class
|
||||
*/
|
||||
public class Rook extends AbstractPiece {
|
||||
|
||||
/**
|
||||
* Create new Rook piece
|
||||
* @param chessboard chessboard
|
||||
* @param x piece's X location
|
||||
* @param y piece's Y location
|
||||
* @param color piece's color
|
||||
*/
|
||||
public Rook(Chessboard chessboard, int x, int y, PieceColor color) {
|
||||
super(chessboard, x, y, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint the Rook piece
|
||||
* @param g2 Graphics2D
|
||||
*/
|
||||
@Override
|
||||
public void paint(Graphics2D g2) {
|
||||
|
||||
|
|
Loading…
Reference in a new issue