contoller
This commit is contained in:
@@ -7,7 +7,7 @@ import chess.model.pieces.*;
|
||||
public class PieceFileName implements PieceVisitor {
|
||||
|
||||
private String pieceName;
|
||||
private static final String BASE = "app/src/main/ressources/pieces2D/";
|
||||
private static final String BASE = "app/src/main/resources/pieces2D/";
|
||||
|
||||
PieceFileName(Piece piece) {
|
||||
visit(piece);
|
||||
|
||||
@@ -18,21 +18,6 @@ public enum Pieces {
|
||||
BLACK_PAWN;
|
||||
|
||||
public static ImageIcon getIcon(String path) {
|
||||
/*return switch (this) {
|
||||
case WHITE_KING -> new ImageIcon(new ImageIcon(path + "white-king.png").getImage().getScaledInstance(100,100, Image.SCALE_SMOOTH));
|
||||
case WHITE_QUEEN -> new ImageIcon(new ImageIcon(path + "white-queen.png").getImage().getScaledInstance(100,100, Image.SCALE_SMOOTH));
|
||||
case WHITE_KNIGHT -> new ImageIcon(new ImageIcon(path + "white-knight.png").getImage().getScaledInstance(100,100, Image.SCALE_SMOOTH));
|
||||
case WHITE_BISHOP -> new ImageIcon(new ImageIcon(path + "white-bishop.png").getImage().getScaledInstance(100,100, Image.SCALE_SMOOTH));
|
||||
case WHITE_ROOK -> new ImageIcon(new ImageIcon(path + "white-rook.png").getImage().getScaledInstance(100,100, Image.SCALE_SMOOTH));
|
||||
case WHITE_PAWN -> new ImageIcon(new ImageIcon(path + "white-pawn.png").getImage().getScaledInstance(100,100, Image.SCALE_SMOOTH));
|
||||
case BLACK_KING -> new ImageIcon(new ImageIcon(path + "black-king.png").getImage().getScaledInstance(100,100, Image.SCALE_SMOOTH));
|
||||
case BLACK_QUEEN -> new ImageIcon(new ImageIcon(path + "black-queen.png").getImage().getScaledInstance(100,100, Image.SCALE_SMOOTH));
|
||||
case BLACK_KNIGHT -> new ImageIcon(new ImageIcon(path + "black-knight.png").getImage().getScaledInstance(100,100, Image.SCALE_SMOOTH));
|
||||
case BLACK_BISHOP -> new ImageIcon(new ImageIcon(path + "black-bishop.png").getImage().getScaledInstance(100,100, Image.SCALE_SMOOTH));
|
||||
case BLACK_ROOK -> new ImageIcon(new ImageIcon(path + "black-rook.png").getImage().getScaledInstance(100,100, Image.SCALE_SMOOTH));
|
||||
case BLACK_PAWN -> new ImageIcon(new ImageIcon(path + "black-pawn.png").getImage().getScaledInstance(100,100, Image.SCALE_SMOOTH));
|
||||
default -> null;
|
||||
};*/
|
||||
return new ImageIcon(new ImageIcon(path).getImage().getScaledInstance(100,100, Image.SCALE_SMOOTH));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package chess.view.render2D;
|
||||
|
||||
import chess.controller.Controller;
|
||||
import chess.model.Coordinates;
|
||||
import chess.model.Game;
|
||||
import chess.model.Piece;
|
||||
@@ -13,18 +14,27 @@ import java.util.Observer;
|
||||
|
||||
public class Window extends JFrame implements Observer {
|
||||
private final Game game;
|
||||
private final Controller controller;
|
||||
private final JLabel[][] tab;
|
||||
private static final String path = "app/src/main/ressources/pieces2D/";
|
||||
private static final String path = "app/src/main/resources/pieces2D/";
|
||||
Coordinates mouseClick = null;
|
||||
Coordinates mouseRelease = null;
|
||||
|
||||
public Window(Game game) {
|
||||
this.game = game;
|
||||
game.addObserver(this);
|
||||
this.controller = new Controller(game, this);
|
||||
tab = new JLabel[game.getSize()][game.getSize()];
|
||||
build();
|
||||
showBoard();
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
new Window(new Game()).build();
|
||||
Game game = new Game();
|
||||
Thread gameThread = new Thread(game);
|
||||
gameThread.start();
|
||||
Window f = new Window(game);
|
||||
f.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,14 +57,12 @@ public class Window extends JFrame implements Observer {
|
||||
jl.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (mouseClick == null) {
|
||||
System.out.println("Click on (" + xx + ";" + yy + ")");
|
||||
mouseClick = new Coordinates(xx, yy);
|
||||
}
|
||||
else {
|
||||
System.out.println("Release on (" + xx + ";" + yy + ")");
|
||||
mouseRelease = new Coordinates(xx, yy);
|
||||
if (!mouseClick.equals(mouseRelease)) {
|
||||
game.move(mouseClick, mouseRelease);
|
||||
controller.sendMove(mouseClick, mouseRelease);
|
||||
update();
|
||||
}
|
||||
mouseClick = null;
|
||||
@@ -67,11 +75,8 @@ public class Window extends JFrame implements Observer {
|
||||
}
|
||||
}
|
||||
setSize(800,800);
|
||||
setVisible(true);
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
public void showBoard(){
|
||||
for (int y = 0; y < game.getSize(); y++){
|
||||
for (int x = 0; x < game.getSize(); x++){
|
||||
@@ -95,7 +100,6 @@ public class Window extends JFrame implements Observer {
|
||||
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
System.out.println("Update.");
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user