Modeselection Fenster hinzugefügt + kleinere Codeoptimierungen + #7

Open
3020772 wants to merge 1 commits from modeSelectionUi into main
11 changed files with 149 additions and 75 deletions

18
pom.xml
View File

@ -21,6 +21,18 @@
</repositories>
<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>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
@ -35,12 +47,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.24.2</version>
</dependency>
<dependency>
<groupId>com.github.bhlangonijr</groupId>
<artifactId>chesslib</artifactId>

View File

@ -3,12 +3,12 @@ package de.mannheim.th.chess.domain;
import com.github.bhlangonijr.chesslib.Board;
import com.github.bhlangonijr.chesslib.Square;
import com.github.bhlangonijr.chesslib.move.Move;
import com.github.bhlangonijr.chesslib.move.MoveList;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import de.mannheim.th.chess.ui.SpielFrame;
import de.mannheim.th.chess.utl.Clock;
/**
@ -18,12 +18,16 @@ public class Game{
private Board board;
private Clock clock;
private SpielFrame sp;
private ArrayList<String> moves;
private ArrayList<Move> movelist = new ArrayList<>();
public Game() {
public Game(String modus) {
board = new Board();
clock = new Clock("blitz");
clock = new Clock(modus);
//SpielFrame erstellen anhand Modus
sp = new SpielFrame(this);
}

View File

@ -7,7 +7,7 @@ import de.mannheim.th.chess.domain.Game;
*/
public class GameWindow{
private Game gamelogic = new Game();
//private Game gamelogic = new Game();
public GameWindow() {

View File

@ -1,54 +1,29 @@
package de.mannheim.th.chess.ui;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Color;
public class MainFrame extends JFrame {
private ArrayList<SpielFrame> spiele = new ArrayList<>();
private static final long serialVersionUID = 1L;
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.
*/
@ -98,12 +73,12 @@ public class MainFrame extends JFrame {
@Override
public void actionPerformed(ActionEvent e) {
SpielFrame sp = new SpielFrame();
spiele.add(sp);
ModeSelectionFrame msf = new ModeSelectionFrame();
}
});
contentPane.add(btnNewButton);
contentPane.add(Box.createVerticalStrut(15));

View File

@ -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);
}
}

View File

@ -11,7 +11,6 @@ import com.github.bhlangonijr.chesslib.Square;
import de.mannheim.th.chess.App;
import de.mannheim.th.chess.domain.Game;
import java.awt.EventQueue;
import java.awt.Font;
import javax.swing.BorderFactory;
@ -53,28 +52,11 @@ public class SpielFrame extends JFrame {
private boolean playerWhite = true;
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.
*/
public SpielFrame() {
game = new Game();
public SpielFrame(Game g) {
this.game = g;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 1920, 1080);
@ -157,13 +139,13 @@ public class SpielFrame extends JFrame {
// filtert möglichen Züge heraus
int position = positions.get(buttonChoosed);
clickableButtons = game
.getLegalMoves(
clickableButtons = game.getLegalMoves(
Square.encode(Rank.allRanks[7 - position / 8], File.allFiles[position % 8]))
.stream().peek(System.out::println).map(m -> m.getTo()).peek(System.out::println)
.map(s -> 56 - s.getRank().ordinal() * 8 + s.getFile().ordinal())
.collect(Collectors.toList());
//filtert mögliche Züge und nicht mögliche Züge in eine Map aus Listen
Map<Boolean, List<JButton>> buttonsSeperated = buttons.stream()
.collect(Collectors.partitioningBy(b -> clickableButtons.contains(buttons.indexOf(b))));
@ -203,6 +185,8 @@ public class SpielFrame extends JFrame {
}
}
} else {
// wenn gerade Figur ausgewählt wird...

View File

@ -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>

View File

@ -1 +0,0 @@
de\mannheim\th\chess\App.class

View File

@ -1,10 +1,12 @@
C:\Users\matia\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
C:\Users\matia\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
C:\Users\matia\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
C:\Users\matia\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
C:\Users\matia\git\Schach\src\main\java\de\mannheim\th\chess\utl\Clock.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/App.java
/home/matias-mas-viehl/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/MoveChecker.java
/home/matias-mas-viehl/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/model/Database.java
/home/matias-mas-viehl/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/GameWindow.java
/home/matias-mas-viehl/git/Schach/src/main/java/de/mannheim/th/chess/ui/MainFrame.java
/home/matias-mas-viehl/git/Schach/src/main/java/de/mannheim/th/chess/ui/ModeSelectionFrame.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