Skip to content

Commit

Permalink
Wrote documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
falseme committed Oct 28, 2021
1 parent 94289b8 commit dfcb06a
Show file tree
Hide file tree
Showing 13 changed files with 458 additions and 73 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/bin/
/res/
/doc/
.git
.rar
41 changes: 36 additions & 5 deletions src/event/SquareMouse.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,46 @@
import ui.Square;
import ui.Table;

/**
* Mouse listener class. Used to check pieces in a square and move them in the table.
* It also implements some mechanics as castilng, passant pawn capture and pawn promotion.<br>
*
* @author Fabricio Tomás <a href="https://github.com/Fabricio-Tomas">github-profile</a>
*/
public class SquareMouse extends MouseAdapter {

private static boolean whiteMoving = true;
private static boolean whiteMoving = true; // True if the white team is doing the moving or false if not.

private Square owner;
private static Square moving; // contains the square with the piece which is moving;
private Square owner; // The squre which has added the mouse listener.
private static Square moving; // The square that has the piece which was selected to move

private boolean in = false;
private boolean in = false; // true if the mouse pointer is inside or false if it is outside

/**
* Creates a listener with a parent from the Square class. <br>
* How to use: <br>
* Square square = new Square(img, x, y); <br>
* square.addMouseListener(new SquareMouse(square));
*
* @param owner The parent object which this listener will work with.
*/
public SquareMouse(Square owner) {

this.owner = owner;

}

/**
* Called when mouse is clicked inside the OWNER (square) object.<br>
* It selects or unselects the square clicked so as to let the player move the piece in the square or select another.<br>
* When moving, checks for castling movements, passant captures or promotions at last row.<br>
* When promoting, opens a JOptionPane to select a piece.<br>
* After moving changes the player's turn, from wite to black or from black to white, if offline.<br><br>
*
* Uses the method Table.enable and Table.enableAll to set which square is clickable or not.
* @param e - object from java.awt.event.MouseEvent. necessary in the MouseListener.
* @see Table
*/
public void clicked(MouseEvent e) {

if (App.CLIENT != null) {
Expand All @@ -50,7 +75,7 @@ public void clicked(MouseEvent e) {

moving.getPiece().moved = true;

// if it is a king > check if the movement is a castling
// if it is a king => check if the movement is a castling
if (moving.getPiece() == Piece.wKing && owner.getPiece() == Piece.wRock
|| moving.getPiece() == Piece.bKing && owner.getPiece() == Piece.bRock) {

Expand Down Expand Up @@ -220,13 +245,19 @@ public void mouseReleased(MouseEvent e) {

}

/**
* Sets the statics variables to default (Any piece is selected to move and it is the white's turn to move).
*/
public static void reset() {

whiteMoving = true;
moving = null;

}

/**
* Used when offline. Switches the player turn.
*/
public static void switchDefaultTurn() {

whiteMoving = !whiteMoving;
Expand Down
41 changes: 38 additions & 3 deletions src/gui/Assets.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,42 @@

import ui.Table;

/**
* Used to drive the graphics files stored in the "res" folder.
*
* @author Fabricio Tomás <a href="https://github.com/Fabricio-Tomas">github-profile</a>
*/
public class Assets {

// white pieces
public static BufferedImage W_PAWN;
public static BufferedImage W_ROCK;
public static BufferedImage W_HORSE;
public static BufferedImage W_BISHOP;
public static BufferedImage W_KING;
public static BufferedImage W_QUEEN;

//black pieces
public static BufferedImage B_PAWN;
public static BufferedImage B_ROCK;
public static BufferedImage B_HORSE;
public static BufferedImage B_BISHOP;
public static BufferedImage B_KING;
public static BufferedImage B_QUEEN;

/** List with the squares textures of the table. */
public static BufferedImage[][] TABLE;
/** The frame of the table with the numbers and letters for the rows and cols. */
public static BufferedImage FRAME;

private static String pieces; // type of pieces ("2d" or "3d"). Used to load a folder
private static String material; // material of the board and pieces ("wood" or "stone"). Used to load a folder
private static String pieces; // Type of pieces ("2d" or "3d"). Used to load a folder
private static String material; // Material of the board and pieces ("wood" or "stone"). Used to load a folder

private static boolean init = false; // true if the "init" method was called almost once
private static boolean init = false; // True if the "init" method was called almost once.

/**
* Loads the default pieces and table. (2d-pieces and stone-material)
*/
public static void init() {

pieces = "2d";
Expand All @@ -40,26 +52,46 @@ public static void init() {

}

/**
* Sets the material to stone and loads everything.
*/
public static void loadStone() {
material = "stone";
loadAll();
}

/**
* Sets the material to wood and loads everything.
*/
public static void loadWood() {
material = "wood";
loadAll();
}

/**
* Sets the dimension to 2D and loads everything.
*/
public static void load2d() {
pieces = "2d";
loadAll();
}

/**
* Sets the dimension to 3D and loads everything.
*/
public static void load3d() {
pieces = "3d";
loadAll();
}

/**
* Loads everything using the Loader class <br>
* Uses the material and the dimension setted to load the pieces and the table graphics. <br> <br>
* Uses the method Table.updateGui to redraw the pieces and table.
*
* @see Loader
* @see Table
*/
public static void loadAll() {

W_PAWN = Loader.loadPng("/pieces/" + pieces + "/" + material + "/PawnW.png");
Expand Down Expand Up @@ -112,6 +144,9 @@ public static void loadAll() {

}

/**
* Sets every asset to null so as to empty the momory.
*/
public static void emptyAll() {

W_PAWN = null;
Expand Down
11 changes: 11 additions & 0 deletions src/gui/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@

import javax.imageio.ImageIO;

/**
* Loads assets files by a path given.
*
* @author Fabricio Tomás <a href="https://github.com/Fabricio-Tomas">github-profile</a>
*/
public class Loader {

/**
* Loads a png file by a path given.
*
* @param path The file path.
* @return The png file: image, if it exists or null if the file does not exist.
*/
public static BufferedImage loadPng(String path) {

if (!path.endsWith(".png"))
Expand Down
17 changes: 17 additions & 0 deletions src/main/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,27 @@
import multiplayer.Client;
import ui.Window;

/**
* Main application class. Contains the main method and the client for a multiplayer (LAN) match.
*
* @author Fabricio Tomás <a href="https://github.com/Fabricio-Tomas">github-profile</a>
*/
public class App {

/**
* The player client. Used for a multiplayer (Lan) connection.
*
* @see Client
*/
public static Client CLIENT;

/**
* Main method - Initialize the game assets and opens a Window.
*
* @param args Idk what is this for.
* @see ui.Window
* @see gui.Assets
**/
public static void main(String[] args) {

Assets.init();
Expand Down
Loading

0 comments on commit dfcb06a

Please sign in to comment.