Modeselection Fenster hinzugefügt + kleinere Codeoptimierungen + #7
18
pom.xml
18
pom.xml
|
|
@ -21,6 +21,18 @@
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
<version>2.24.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-api</artifactId>
|
||||||
|
<version>2.24.2</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
|
@ -35,12 +47,6 @@
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
|
||||||
<artifactId>log4j-core</artifactId>
|
|
||||||
<version>2.24.2</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.bhlangonijr</groupId>
|
<groupId>com.github.bhlangonijr</groupId>
|
||||||
<artifactId>chesslib</artifactId>
|
<artifactId>chesslib</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@ package de.mannheim.th.chess.domain;
|
||||||
import com.github.bhlangonijr.chesslib.Board;
|
import com.github.bhlangonijr.chesslib.Board;
|
||||||
import com.github.bhlangonijr.chesslib.Square;
|
import com.github.bhlangonijr.chesslib.Square;
|
||||||
import com.github.bhlangonijr.chesslib.move.Move;
|
import com.github.bhlangonijr.chesslib.move.Move;
|
||||||
import com.github.bhlangonijr.chesslib.move.MoveList;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame;
|
||||||
import de.mannheim.th.chess.utl.Clock;
|
import de.mannheim.th.chess.utl.Clock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -18,12 +18,16 @@ public class Game{
|
||||||
|
|
||||||
private Board board;
|
private Board board;
|
||||||
private Clock clock;
|
private Clock clock;
|
||||||
|
private SpielFrame sp;
|
||||||
private ArrayList<String> moves;
|
private ArrayList<String> moves;
|
||||||
private ArrayList<Move> movelist = new ArrayList<>();
|
private ArrayList<Move> movelist = new ArrayList<>();
|
||||||
|
|
||||||
public Game() {
|
public Game(String modus) {
|
||||||
board = new Board();
|
board = new Board();
|
||||||
clock = new Clock("blitz");
|
clock = new Clock(modus);
|
||||||
|
|
||||||
|
//SpielFrame erstellen anhand Modus
|
||||||
|
sp = new SpielFrame(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import de.mannheim.th.chess.domain.Game;
|
||||||
*/
|
*/
|
||||||
public class GameWindow{
|
public class GameWindow{
|
||||||
|
|
||||||
private Game gamelogic = new Game();
|
//private Game gamelogic = new Game();
|
||||||
|
|
||||||
public GameWindow() {
|
public GameWindow() {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,54 +1,29 @@
|
||||||
package de.mannheim.th.chess.ui;
|
package de.mannheim.th.chess.ui;
|
||||||
|
|
||||||
import java.awt.EventQueue;
|
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.JTextField;
|
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import java.awt.GridLayout;
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
public class MainFrame extends JFrame {
|
public class MainFrame extends JFrame {
|
||||||
|
|
||||||
private ArrayList<SpielFrame> spiele = new ArrayList<>();
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
|
|
||||||
/**
|
|
||||||
* Launch the application.
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
EventQueue.invokeLater(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
MainFrame frame = new MainFrame();
|
|
||||||
frame.setVisible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the frame.
|
* Create the frame.
|
||||||
*/
|
*/
|
||||||
|
|
@ -98,12 +73,12 @@ public class MainFrame extends JFrame {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
SpielFrame sp = new SpielFrame();
|
ModeSelectionFrame msf = new ModeSelectionFrame();
|
||||||
spiele.add(sp);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
contentPane.add(btnNewButton);
|
contentPane.add(btnNewButton);
|
||||||
|
|
||||||
contentPane.add(Box.createVerticalStrut(15));
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
package de.mannheim.th.chess.ui;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.EventQueue;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
|
||||||
|
public class ModeSelectionFrame extends JFrame {
|
||||||
|
|
||||||
|
private ArrayList<Game> spiele = new ArrayList<>();
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private JPanel contentPane;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the frame.
|
||||||
|
*/
|
||||||
|
public ModeSelectionFrame() {
|
||||||
|
|
||||||
|
setBackground(Color.LIGHT_GRAY);
|
||||||
|
setResizable(true);
|
||||||
|
setAlwaysOnTop(true);
|
||||||
|
setTitle("Modeselection");
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setBounds(100, 100, 400, 200);
|
||||||
|
|
||||||
|
contentPane = new JPanel();
|
||||||
|
contentPane.setBackground(new Color(90, 90, 90));
|
||||||
|
contentPane.setForeground(Color.BLACK);
|
||||||
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
|
||||||
|
setContentPane(contentPane);
|
||||||
|
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JLabel jl = new JLabel("Welchen Modus wollen Sie spielen?");
|
||||||
|
jl.setFont(new Font("Calibri", Font.ITALIC, 24));
|
||||||
|
jl.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
contentPane.add(jl);
|
||||||
|
|
||||||
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
|
//Moduseingabe
|
||||||
|
String[] moeglichkeiten = { "Blitz", "Schnellschach", "Klassisch"};
|
||||||
|
JComboBox jcb1 = new JComboBox<String>(moeglichkeiten);
|
||||||
|
jcb1.setMaximumSize(new Dimension(100, 24));
|
||||||
|
contentPane.add(jcb1);
|
||||||
|
|
||||||
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
|
JButton btnNewButton = new JButton("Spiel starten");
|
||||||
|
|
||||||
|
btnNewButton.setBackground(Color.LIGHT_GRAY);
|
||||||
|
btnNewButton.setForeground(Color.BLACK);
|
||||||
|
btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||||
|
btnNewButton.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
btnNewButton.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
|
//Moduslogik
|
||||||
|
String modus = String.valueOf(jcb1.getSelectedItem());
|
||||||
|
Game g = new Game(modus);
|
||||||
|
|
||||||
|
spiele.add(g);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
contentPane.add(btnNewButton);
|
||||||
|
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -11,7 +11,6 @@ import com.github.bhlangonijr.chesslib.Square;
|
||||||
import de.mannheim.th.chess.App;
|
import de.mannheim.th.chess.App;
|
||||||
import de.mannheim.th.chess.domain.Game;
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
|
||||||
import java.awt.EventQueue;
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
|
|
@ -53,28 +52,11 @@ public class SpielFrame extends JFrame {
|
||||||
private boolean playerWhite = true;
|
private boolean playerWhite = true;
|
||||||
private boolean moveFinished = false;
|
private boolean moveFinished = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Launch the application. Die Main-Methode für den WindowBuilder.
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
EventQueue.invokeLater(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
SpielFrame frame = new SpielFrame();
|
|
||||||
frame.setVisible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the frame.
|
* Create the frame.
|
||||||
*/
|
*/
|
||||||
public SpielFrame() {
|
public SpielFrame(Game g) {
|
||||||
|
this.game = g;
|
||||||
game = new Game();
|
|
||||||
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
setBounds(100, 100, 1920, 1080);
|
setBounds(100, 100, 1920, 1080);
|
||||||
|
|
@ -157,12 +139,12 @@ public class SpielFrame extends JFrame {
|
||||||
// filtert möglichen Züge heraus
|
// filtert möglichen Züge heraus
|
||||||
int position = positions.get(buttonChoosed);
|
int position = positions.get(buttonChoosed);
|
||||||
|
|
||||||
clickableButtons = game
|
clickableButtons = game.getLegalMoves(
|
||||||
.getLegalMoves(
|
Square.encode(Rank.allRanks[7 - position / 8], File.allFiles[position % 8]))
|
||||||
Square.encode(Rank.allRanks[7 - position / 8], File.allFiles[position % 8]))
|
.stream().peek(System.out::println).map(m -> m.getTo()).peek(System.out::println)
|
||||||
.stream().peek(System.out::println).map(m -> m.getTo()).peek(System.out::println)
|
.map(s -> 56 - s.getRank().ordinal() * 8 + s.getFile().ordinal())
|
||||||
.map(s -> 56 - s.getRank().ordinal() * 8 + s.getFile().ordinal())
|
.collect(Collectors.toList());
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
//filtert mögliche Züge und nicht mögliche Züge in eine Map aus Listen
|
//filtert mögliche Züge und nicht mögliche Züge in eine Map aus Listen
|
||||||
Map<Boolean, List<JButton>> buttonsSeperated = buttons.stream()
|
Map<Boolean, List<JButton>> buttonsSeperated = buttons.stream()
|
||||||
|
|
@ -203,6 +185,8 @@ public class SpielFrame extends JFrame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// wenn gerade Figur ausgewählt wird...
|
// wenn gerade Figur ausgewählt wird...
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Configuration status="WARN">
|
||||||
|
<Appenders>
|
||||||
|
<Console name="Console" target="SYSTEM_OUT">
|
||||||
|
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||||
|
</Console>
|
||||||
|
</Appenders>
|
||||||
|
<Loggers>
|
||||||
|
<Root level="info">
|
||||||
|
<AppenderRef ref="Console"/>
|
||||||
|
</Root>
|
||||||
|
</Loggers>
|
||||||
|
</Configuration>
|
||||||
Binary file not shown.
|
|
@ -1 +0,0 @@
|
||||||
de\mannheim\th\chess\App.class
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
C:\Users\matia\git\Schach\src\main\java\de\mannheim\th\chess\App.java
|
/home/matias-mas-viehl/git/Schach/src/main/java/de/mannheim/th/chess/App.java
|
||||||
C:\Users\matia\git\Schach\src\main\java\de\mannheim\th\chess\domain\Game.java
|
/home/matias-mas-viehl/git/Schach/src/main/java/de/mannheim/th/chess/domain/Game.java
|
||||||
C:\Users\matia\git\Schach\src\main\java\de\mannheim\th\chess\domain\MoveChecker.java
|
/home/matias-mas-viehl/git/Schach/src/main/java/de/mannheim/th/chess/domain/MoveChecker.java
|
||||||
C:\Users\matia\git\Schach\src\main\java\de\mannheim\th\chess\domain\MoveReader.java
|
/home/matias-mas-viehl/git/Schach/src/main/java/de/mannheim/th/chess/domain/MoveReader.java
|
||||||
C:\Users\matia\git\Schach\src\main\java\de\mannheim\th\chess\model\Database.java
|
/home/matias-mas-viehl/git/Schach/src/main/java/de/mannheim/th/chess/model/Database.java
|
||||||
C:\Users\matia\git\Schach\src\main\java\de\mannheim\th\chess\ui\Creator.java
|
/home/matias-mas-viehl/git/Schach/src/main/java/de/mannheim/th/chess/ui/Creator.java
|
||||||
C:\Users\matia\git\Schach\src\main\java\de\mannheim\th\chess\ui\GameWindow.java
|
/home/matias-mas-viehl/git/Schach/src/main/java/de/mannheim/th/chess/ui/GameWindow.java
|
||||||
C:\Users\matia\git\Schach\src\main\java\de\mannheim\th\chess\ui\Ui.java
|
/home/matias-mas-viehl/git/Schach/src/main/java/de/mannheim/th/chess/ui/MainFrame.java
|
||||||
C:\Users\matia\git\Schach\src\main\java\de\mannheim\th\chess\utl\Clock.java
|
/home/matias-mas-viehl/git/Schach/src/main/java/de/mannheim/th/chess/ui/ModeSelectionFrame.java
|
||||||
C:\Users\matia\git\Schach\src\main\java\de\mannheim\th\chess\utl\GameReader.java
|
/home/matias-mas-viehl/git/Schach/src/main/java/de/mannheim/th/chess/ui/SpielFrame.java
|
||||||
|
/home/matias-mas-viehl/git/Schach/src/main/java/de/mannheim/th/chess/utl/Clock.java
|
||||||
|
/home/matias-mas-viehl/git/Schach/src/main/java/de/mannheim/th/chess/utl/GameReader.java
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in New Issue