Compare commits

..

2 Commits

Author SHA1 Message Date
9af06e36f8 change project structure 2025-04-05 10:18:02 +02:00
a0af8caf57 post exec 2025-04-05 10:12:25 +02:00
25 changed files with 68 additions and 60 deletions

View File

@@ -3,11 +3,11 @@
*/ */
package chess; package chess;
import chess.io.CommandExecutor; import chess.controller.CommandExecutor;
import chess.io.commands.NewGameCommand; import chess.controller.commands.NewGameCommand;
import chess.model.ChessBoard; import chess.model.ChessBoard;
import chess.model.Game; import chess.model.Game;
import chess.simplerender.Window; import chess.view.simplerender.Window;
public class App { public class App {
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -1,4 +1,4 @@
package chess.io; package chess.controller;
import chess.model.Game; import chess.model.Game;
@@ -16,4 +16,6 @@ public abstract class Command {
} }
public abstract CommandResult execute(Game game, OutputSystem outputSystem); public abstract CommandResult execute(Game game, OutputSystem outputSystem);
public void postExec(Game game, OutputSystem outputSystem) {}
} }

View File

@@ -1,6 +1,6 @@
package chess.io; package chess.controller;
import chess.io.Command.CommandResult; import chess.controller.Command.CommandResult;
import chess.model.Game; import chess.model.Game;
import chess.model.Game.GameStatus; import chess.model.Game.GameStatus;
@@ -24,6 +24,7 @@ public class CommandExecutor {
assert result != CommandResult.Moved || command instanceof PlayerCommand; assert result != CommandResult.Moved || command instanceof PlayerCommand;
processResult(command, result); processResult(command, result);
command.postExec(game, outputSystem);
return result; return result;
} }

View File

@@ -1,4 +1,4 @@
package chess.io; package chess.controller;
import chess.model.Color; import chess.model.Color;
import chess.model.Coordinate; import chess.model.Coordinate;

View File

@@ -1,4 +1,4 @@
package chess.io; package chess.controller;
import chess.model.Game; import chess.model.Game;

View File

@@ -1,7 +1,7 @@
package chess.io.commands; package chess.controller.commands;
import chess.io.OutputSystem; import chess.controller.OutputSystem;
import chess.io.PlayerCommand; import chess.controller.PlayerCommand;
import chess.model.Game; import chess.model.Game;
public class CastlingCommand extends PlayerCommand { public class CastlingCommand extends PlayerCommand {

View File

@@ -1,10 +1,10 @@
package chess.io.commands; package chess.controller.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import chess.io.Command; import chess.controller.Command;
import chess.io.OutputSystem; import chess.controller.OutputSystem;
import chess.model.ChessBoard; import chess.model.ChessBoard;
import chess.model.Coordinate; import chess.model.Coordinate;
import chess.model.Game; import chess.model.Game;

View File

@@ -1,7 +1,7 @@
package chess.io.commands; package chess.controller.commands;
import chess.io.Command; import chess.controller.Command;
import chess.io.OutputSystem; import chess.controller.OutputSystem;
import chess.model.Coordinate; import chess.model.Coordinate;
import chess.model.Game; import chess.model.Game;
import chess.model.Piece; import chess.model.Piece;

View File

@@ -1,7 +1,7 @@
package chess.io.commands; package chess.controller.commands;
import chess.io.OutputSystem; import chess.controller.OutputSystem;
import chess.io.PlayerCommand; import chess.controller.PlayerCommand;
import chess.model.Game; import chess.model.Game;
public class GrandCastlingCommand extends PlayerCommand { public class GrandCastlingCommand extends PlayerCommand {

View File

@@ -1,7 +1,7 @@
package chess.io.commands; package chess.controller.commands;
import chess.io.OutputSystem; import chess.controller.OutputSystem;
import chess.io.PlayerCommand; import chess.controller.PlayerCommand;
import chess.model.ChessBoard; import chess.model.ChessBoard;
import chess.model.Coordinate; import chess.model.Coordinate;
import chess.model.Game; import chess.model.Game;
@@ -50,7 +50,7 @@ public class MoveCommand extends PlayerCommand {
return CommandResult.NotAllowed; return CommandResult.NotAllowed;
} }
if (shouldPromote(game, outputSystem)) if (game.pawnShouldBePromoted())
return CommandResult.ActionNeeded; return CommandResult.ActionNeeded;
return CommandResult.Moved; return CommandResult.Moved;
@@ -63,14 +63,18 @@ public class MoveCommand extends PlayerCommand {
board.undoMove(move, deadPiece); board.undoMove(move, deadPiece);
} }
private boolean shouldPromote(Game game, OutputSystem outputSystem) { @Override
public void postExec(Game game, OutputSystem outputSystem) {
tryPromote(game, outputSystem);
}
private void tryPromote(Game game, OutputSystem outputSystem) {
Coordinate pawnPos = game.pawnPromotePosition(); Coordinate pawnPos = game.pawnPromotePosition();
if (pawnPos == null) if (pawnPos == null)
return false; return;
outputSystem.promotePawn(pawnPos); outputSystem.promotePawn(pawnPos);
return true;
} }
} }

View File

@@ -1,7 +1,7 @@
package chess.io.commands; package chess.controller.commands;
import chess.io.Command; import chess.controller.Command;
import chess.io.OutputSystem; import chess.controller.OutputSystem;
import chess.model.ChessBoard; import chess.model.ChessBoard;
import chess.model.Color; import chess.model.Color;
import chess.model.Coordinate; import chess.model.Coordinate;

View File

@@ -1,7 +1,7 @@
package chess.io.commands; package chess.controller.commands;
import chess.io.OutputSystem; import chess.controller.OutputSystem;
import chess.io.PlayerCommand; import chess.controller.PlayerCommand;
import chess.model.ChessBoard; import chess.model.ChessBoard;
import chess.model.Color; import chess.model.Color;
import chess.model.Coordinate; import chess.model.Coordinate;

View File

@@ -1,7 +1,7 @@
package chess.io.commands; package chess.controller.commands;
import chess.io.Command; import chess.controller.Command;
import chess.io.OutputSystem; import chess.controller.OutputSystem;
import chess.model.Color; import chess.model.Color;
import chess.model.Game; import chess.model.Game;

View File

@@ -1,7 +1,7 @@
package chess.io.commands; package chess.controller.commands;
import chess.io.Command; import chess.controller.Command;
import chess.io.OutputSystem; import chess.controller.OutputSystem;
import chess.model.Game; import chess.model.Game;
public class UndoCommand extends Command{ public class UndoCommand extends Command{

View File

@@ -1,4 +1,4 @@
package chess.render; package chess.view.render;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Vector3f; import org.joml.Vector3f;

View File

@@ -1,4 +1,4 @@
package chess.render; package chess.view.render;
import org.lwjgl.opengl.GL30; import org.lwjgl.opengl.GL30;

View File

@@ -1,10 +1,11 @@
package chess.render; package chess.view.render;
import org.joml.Vector3f; import org.joml.Vector3f;
import org.lwjgl.opengl.*; import org.lwjgl.opengl.*;
import chess.view.render.shader.BoardShader;
import static org.lwjgl.opengl.GL30.*; import static org.lwjgl.opengl.GL30.*;
import chess.render.shader.BoardShader;
public class Renderer { public class Renderer {
private BoardShader shader; private BoardShader shader;

View File

@@ -1,4 +1,4 @@
package chess.render; package chess.view.render;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@@ -1,4 +1,4 @@
package chess.render; package chess.view.render;
public record VertexAttribPointer(int index, int size, int offset) { public record VertexAttribPointer(int index, int size, int offset) {

View File

@@ -1,4 +1,4 @@
package chess.render; package chess.view.render;
import static org.lwjgl.opengl.GL11.GL_FLOAT; import static org.lwjgl.opengl.GL11.GL_FLOAT;

View File

@@ -1,4 +1,4 @@
package chess.render; package chess.view.render;
import org.lwjgl.*; import org.lwjgl.*;
import org.lwjgl.glfw.*; import org.lwjgl.glfw.*;

View File

@@ -1,4 +1,4 @@
package chess.render.shader; package chess.view.render.shader;
import org.joml.Matrix4f; import org.joml.Matrix4f;

View File

@@ -1,4 +1,4 @@
package chess.render.shader; package chess.view.render.shader;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;

View File

@@ -1,4 +1,4 @@
package chess.simplerender; package chess.view.simplerender;
import java.awt.Image; import java.awt.Image;
import java.util.HashMap; import java.util.HashMap;

View File

@@ -1,4 +1,4 @@
package chess.simplerender; package chess.view.simplerender;
import java.awt.Color; import java.awt.Color;
import java.awt.GridLayout; import java.awt.GridLayout;
@@ -12,15 +12,15 @@ import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import chess.io.Command; import chess.controller.Command;
import chess.io.Command.CommandResult; import chess.controller.CommandExecutor;
import chess.io.CommandExecutor; import chess.controller.OutputSystem;
import chess.io.OutputSystem; import chess.controller.Command.CommandResult;
import chess.io.commands.GetAllowedMovesCommand; import chess.controller.commands.GetAllowedMovesCommand;
import chess.io.commands.GetPieceAtCommand; import chess.controller.commands.GetPieceAtCommand;
import chess.io.commands.MoveCommand; import chess.controller.commands.MoveCommand;
import chess.io.commands.PromoteCommand; import chess.controller.commands.PromoteCommand;
import chess.io.commands.PromoteCommand.PromoteType; import chess.controller.commands.PromoteCommand.PromoteType;
import chess.model.Coordinate; import chess.model.Coordinate;
import chess.model.Move; import chess.model.Move;
import chess.model.Piece; import chess.model.Piece;