From f11253511a745d2801447044a22c47ab9f354f21 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 17 Jun 2025 12:02:22 +0200 Subject: [PATCH] =?UTF-8?q?Modeselection=20Fenster=20hinzugef=C3=BCgt=20+?= =?UTF-8?q?=20kleinere=20Codeoptimierungen=20+=20Logger-xml=20hinzugef?= =?UTF-8?q?=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 18 ++-- .../de/mannheim/th/chess/domain/Game.java | 10 +- .../de/mannheim/th/chess/ui/GameWindow.java | 2 +- .../de/mannheim/th/chess/ui/MainFrame.java | 29 +----- .../th/chess/ui/ModeSelectionFrame.java | 91 ++++++++++++++++++ .../de/mannheim/th/chess/ui/SpielFrame.java | 38 +++----- src/main/resources/log4j2.xml | 13 +++ target/classes/de/mannheim/th/chess/App.class | Bin 885 -> 873 bytes .../compile/default-compile/createdFiles.lst | 1 - .../compile/default-compile/inputFiles.lst | 22 +++-- .../de/mannheim/th/chess/AppTest.class | Bin 515 -> 515 bytes 11 files changed, 149 insertions(+), 75 deletions(-) create mode 100644 src/main/java/de/mannheim/th/chess/ui/ModeSelectionFrame.java create mode 100644 src/main/resources/log4j2.xml diff --git a/pom.xml b/pom.xml index 777d54d..87b8451 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,18 @@ + + + org.apache.logging.log4j + log4j-core + 2.24.2 + + + + org.apache.logging.log4j + log4j-api + 2.24.2 + org.junit.jupiter junit-jupiter-api @@ -35,12 +47,6 @@ test - - org.apache.logging.log4j - log4j-core - 2.24.2 - - com.github.bhlangonijr chesslib diff --git a/src/main/java/de/mannheim/th/chess/domain/Game.java b/src/main/java/de/mannheim/th/chess/domain/Game.java index 6a888b4..8d30394 100644 --- a/src/main/java/de/mannheim/th/chess/domain/Game.java +++ b/src/main/java/de/mannheim/th/chess/domain/Game.java @@ -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 moves; private ArrayList 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); } diff --git a/src/main/java/de/mannheim/th/chess/ui/GameWindow.java b/src/main/java/de/mannheim/th/chess/ui/GameWindow.java index d220a5c..7fa393f 100644 --- a/src/main/java/de/mannheim/th/chess/ui/GameWindow.java +++ b/src/main/java/de/mannheim/th/chess/ui/GameWindow.java @@ -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() { diff --git a/src/main/java/de/mannheim/th/chess/ui/MainFrame.java b/src/main/java/de/mannheim/th/chess/ui/MainFrame.java index 96235ee..f864964 100644 --- a/src/main/java/de/mannheim/th/chess/ui/MainFrame.java +++ b/src/main/java/de/mannheim/th/chess/ui/MainFrame.java @@ -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 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)); diff --git a/src/main/java/de/mannheim/th/chess/ui/ModeSelectionFrame.java b/src/main/java/de/mannheim/th/chess/ui/ModeSelectionFrame.java new file mode 100644 index 0000000..36918f1 --- /dev/null +++ b/src/main/java/de/mannheim/th/chess/ui/ModeSelectionFrame.java @@ -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 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(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); + } + +} diff --git a/src/main/java/de/mannheim/th/chess/ui/SpielFrame.java b/src/main/java/de/mannheim/th/chess/ui/SpielFrame.java index 926ae2c..61c65d0 100644 --- a/src/main/java/de/mannheim/th/chess/ui/SpielFrame.java +++ b/src/main/java/de/mannheim/th/chess/ui/SpielFrame.java @@ -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,29 +52,12 @@ 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); setTitle("Schach"); @@ -157,12 +139,12 @@ public class SpielFrame extends JFrame { // filtert möglichen Züge heraus int position = positions.get(buttonChoosed); - 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()); + 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> buttonsSeperated = buttons.stream() @@ -202,6 +184,8 @@ public class SpielFrame extends JFrame { b.setEnabled(false); } } + + } else { diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 0000000..ab8a49f --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/target/classes/de/mannheim/th/chess/App.class b/target/classes/de/mannheim/th/chess/App.class index 920e2cbf29513b2a6b9c549fa41bff426f0c1783..a8d459d6237b53f48fea76f54af35805d305cd49 100644 GIT binary patch delta 457 zcmYjMOG^S_6g}TK&dV7!bMi5jkIK|icR?UR2-PBKSG1gTsIf`GtZlzx80deL3wuD& zwp~9XXdASO?iiGd@7&k<&OP^2co()`zaO6gY@w=vLqG(tA_##Y+BL7tnq&4(YWv4s zt36~8>UPf_HW&iM(t!*KvIs>*2&$_YZljWs5N1$!Eyw9+5BmeBQw<@C84)oRvxs|d zEbo1>96!g9bECR(Y1dk&-P<0R=avE;0bewwA`Qbm+t3s&U{ORyMV9z41^1&VGVslQ z$MQB=N#=*A_60+F&y6O%8vG1mL`Q*M+ILBr;%ie3fca+<=BcVt zWE6wtG1x679F_?EF`!|YQ2ixf1qG^PtfELA|ML#9eV%>?F{V8r!r=+}(HMyltmMC1 un3e(wvXDd^sVP+*C6s9V$wb4M-Y7>Hf1Y9)jIV!RDJ-`&_4kH delta 500 zcmYjMJ5Rz;6#j037Rp7XilCyR_yUD)E)o(Si4GbE6OD1YLc=4qXd$lt0*9u*!$f7k zN8%4~ar8GhI=C87s|nuWeD|E3?{PllFS-2s{qzE014RWAL#k@%XTq}TM&nHH)b&c; zXt(wC^K%73hM}go6uK#_n!bP9G%6iO6x=zsnq>%=DrUoKbjl2YrQ9JyaI;l4RKzf- zV1Oa(+@|@Sutd$UIff8-ui2&=0mCpy2(tUma&fujOQ;AS#W4!i{bpO^VN5ab9m6zR znWL6%R*O+&Fsoq3xtR@dWHINw&9DXMb0I&El&6{FP!OgN!mhQ+;$*j<{GekutlFB} zlqRkyEFCXl+>1az)uRyxs79z`h*DP|^j<_`58z#BchpE2p{f!BgR~w;!k>bcDfu5& zC-lgnd=JS!P4w!zJ diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index ebf066f..e69de29 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -1 +0,0 @@ -de\mannheim\th\chess\App.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index 15c463f..d271d64 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -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 diff --git a/target/test-classes/de/mannheim/th/chess/AppTest.class b/target/test-classes/de/mannheim/th/chess/AppTest.class index b602933bd1408dfffd12b22f6c66b21cec7dd56c..4e6415eb8850f5be7a7972d3f84565ba4a36bd3e 100644 GIT binary patch delta 17 YcmZo>X=dR#^>5cc1_lPljU2xj0Xe+}O#lD@ delta 17 YcmZo>X=dR#^>5cc1_lPFjU2xj0Xf13P5=M^ -- 2.43.0