Compare commits
2 Commits
63a1e261e8
...
9af06e36f8
| Author | SHA1 | Date | |
|---|---|---|---|
| 9af06e36f8 | |||
| a0af8caf57 |
@@ -3,11 +3,11 @@
|
||||
*/
|
||||
package chess;
|
||||
|
||||
import chess.io.CommandExecutor;
|
||||
import chess.io.commands.NewGameCommand;
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.commands.NewGameCommand;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Game;
|
||||
import chess.simplerender.Window;
|
||||
import chess.view.simplerender.Window;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package chess.io;
|
||||
package chess.controller;
|
||||
|
||||
import chess.model.Game;
|
||||
|
||||
@@ -16,4 +16,6 @@ public abstract class Command {
|
||||
}
|
||||
|
||||
public abstract CommandResult execute(Game game, OutputSystem outputSystem);
|
||||
|
||||
public void postExec(Game game, OutputSystem outputSystem) {}
|
||||
}
|
||||
@@ -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.GameStatus;
|
||||
|
||||
@@ -24,6 +24,7 @@ public class CommandExecutor {
|
||||
assert result != CommandResult.Moved || command instanceof PlayerCommand;
|
||||
|
||||
processResult(command, result);
|
||||
command.postExec(game, outputSystem);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package chess.io;
|
||||
package chess.controller;
|
||||
|
||||
import chess.model.Color;
|
||||
import chess.model.Coordinate;
|
||||
@@ -1,4 +1,4 @@
|
||||
package chess.io;
|
||||
package chess.controller;
|
||||
|
||||
import chess.model.Game;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package chess.io.commands;
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.io.OutputSystem;
|
||||
import chess.io.PlayerCommand;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.PlayerCommand;
|
||||
import chess.model.Game;
|
||||
|
||||
public class CastlingCommand extends PlayerCommand {
|
||||
@@ -1,10 +1,10 @@
|
||||
package chess.io.commands;
|
||||
package chess.controller.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import chess.io.Command;
|
||||
import chess.io.OutputSystem;
|
||||
import chess.controller.Command;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Game;
|
||||
@@ -1,7 +1,7 @@
|
||||
package chess.io.commands;
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.io.Command;
|
||||
import chess.io.OutputSystem;
|
||||
import chess.controller.Command;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Game;
|
||||
import chess.model.Piece;
|
||||
@@ -1,7 +1,7 @@
|
||||
package chess.io.commands;
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.io.OutputSystem;
|
||||
import chess.io.PlayerCommand;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.PlayerCommand;
|
||||
import chess.model.Game;
|
||||
|
||||
public class GrandCastlingCommand extends PlayerCommand {
|
||||
@@ -1,7 +1,7 @@
|
||||
package chess.io.commands;
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.io.OutputSystem;
|
||||
import chess.io.PlayerCommand;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.PlayerCommand;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Game;
|
||||
@@ -50,7 +50,7 @@ public class MoveCommand extends PlayerCommand {
|
||||
return CommandResult.NotAllowed;
|
||||
}
|
||||
|
||||
if (shouldPromote(game, outputSystem))
|
||||
if (game.pawnShouldBePromoted())
|
||||
return CommandResult.ActionNeeded;
|
||||
|
||||
return CommandResult.Moved;
|
||||
@@ -63,14 +63,18 @@ public class MoveCommand extends PlayerCommand {
|
||||
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();
|
||||
|
||||
if (pawnPos == null)
|
||||
return false;
|
||||
return;
|
||||
|
||||
outputSystem.promotePawn(pawnPos);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package chess.io.commands;
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.io.Command;
|
||||
import chess.io.OutputSystem;
|
||||
import chess.controller.Command;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Color;
|
||||
import chess.model.Coordinate;
|
||||
@@ -1,7 +1,7 @@
|
||||
package chess.io.commands;
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.io.OutputSystem;
|
||||
import chess.io.PlayerCommand;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.PlayerCommand;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Color;
|
||||
import chess.model.Coordinate;
|
||||
@@ -1,7 +1,7 @@
|
||||
package chess.io.commands;
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.io.Command;
|
||||
import chess.io.OutputSystem;
|
||||
import chess.controller.Command;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.model.Color;
|
||||
import chess.model.Game;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package chess.io.commands;
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.io.Command;
|
||||
import chess.io.OutputSystem;
|
||||
import chess.controller.Command;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.model.Game;
|
||||
|
||||
public class UndoCommand extends Command{
|
||||
@@ -1,4 +1,4 @@
|
||||
package chess.render;
|
||||
package chess.view.render;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
@@ -1,4 +1,4 @@
|
||||
package chess.render;
|
||||
package chess.view.render;
|
||||
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package chess.render;
|
||||
package chess.view.render;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
import chess.view.render.shader.BoardShader;
|
||||
|
||||
import static org.lwjgl.opengl.GL30.*;
|
||||
import chess.render.shader.BoardShader;
|
||||
|
||||
public class Renderer {
|
||||
private BoardShader shader;
|
||||
@@ -1,4 +1,4 @@
|
||||
package chess.render;
|
||||
package chess.view.render;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -1,4 +1,4 @@
|
||||
package chess.render;
|
||||
package chess.view.render;
|
||||
|
||||
public record VertexAttribPointer(int index, int size, int offset) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package chess.render;
|
||||
package chess.view.render;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.GL_FLOAT;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package chess.render;
|
||||
package chess.view.render;
|
||||
|
||||
import org.lwjgl.*;
|
||||
import org.lwjgl.glfw.*;
|
||||
@@ -1,4 +1,4 @@
|
||||
package chess.render.shader;
|
||||
package chess.view.render.shader;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package chess.render.shader;
|
||||
package chess.view.render.shader;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
@@ -1,4 +1,4 @@
|
||||
package chess.simplerender;
|
||||
package chess.view.simplerender;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.util.HashMap;
|
||||
@@ -1,4 +1,4 @@
|
||||
package chess.simplerender;
|
||||
package chess.view.simplerender;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GridLayout;
|
||||
@@ -12,15 +12,15 @@ import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import chess.io.Command;
|
||||
import chess.io.Command.CommandResult;
|
||||
import chess.io.CommandExecutor;
|
||||
import chess.io.OutputSystem;
|
||||
import chess.io.commands.GetAllowedMovesCommand;
|
||||
import chess.io.commands.GetPieceAtCommand;
|
||||
import chess.io.commands.MoveCommand;
|
||||
import chess.io.commands.PromoteCommand;
|
||||
import chess.io.commands.PromoteCommand.PromoteType;
|
||||
import chess.controller.Command;
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.Command.CommandResult;
|
||||
import chess.controller.commands.GetAllowedMovesCommand;
|
||||
import chess.controller.commands.GetPieceAtCommand;
|
||||
import chess.controller.commands.MoveCommand;
|
||||
import chess.controller.commands.PromoteCommand;
|
||||
import chess.controller.commands.PromoteCommand.PromoteType;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Move;
|
||||
import chess.model.Piece;
|
||||
Reference in New Issue
Block a user