diff --git a/PR2Projekt/.classpath b/PR2Projekt/.classpath
index 2cc4e66..ea3904f 100644
--- a/PR2Projekt/.classpath
+++ b/PR2Projekt/.classpath
@@ -1,40 +1,39 @@
-
+
-
+
-
-
+
+
+
-
-
-
+
+
-
-
-
+
-
-
+
+
+
@@ -44,42 +43,6 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/PR2Projekt/Klassendiagramm.png b/PR2Projekt/Klassendiagramm.png
new file mode 100644
index 0000000..d6c7fc2
Binary files /dev/null and b/PR2Projekt/Klassendiagramm.png differ
diff --git a/PR2Projekt/pom.xml b/PR2Projekt/pom.xml
index 7f0ffd7..607057c 100644
--- a/PR2Projekt/pom.xml
+++ b/PR2Projekt/pom.xml
@@ -50,11 +50,6 @@
maven-shade-plugin
3.6.0
-
-
-de.hs_mannheim.informatik.mvn.HitoriMain2
-
-
false
@@ -66,7 +61,7 @@
-src.main.java
+de.hs_mannheim.informatik.mvn.domain.HitoriMain
@@ -118,7 +113,7 @@
src/test/java
- src/main/java/resources
+ src/main/resources
src/test/java
diff --git a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/domain/HitoriMain2.java b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/domain/HitoriMain.java
similarity index 88%
rename from PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/domain/HitoriMain2.java
rename to PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/domain/HitoriMain.java
index d602538..579c27c 100644
--- a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/domain/HitoriMain2.java
+++ b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/domain/HitoriMain.java
@@ -1,8 +1,6 @@
package de.hs_mannheim.informatik.mvn.domain;
import java.awt.CardLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
@@ -28,7 +26,7 @@ import javax.swing.JPanel;
import java.time.format.DateTimeFormatterBuilder;
import de.hs_mannheim.informatik.mvn.gui.*;
-public class HitoriMain2 extends JFrame implements ActionListener{
+public class HitoriMain {
private static byte[] gameData;
@@ -43,8 +41,8 @@ public class HitoriMain2 extends JFrame implements ActionListener{
String[][] data = getData(newStream, rows);
String[][] colors = makeColorArray(data.length);
JButton[][] buttons = makeButtonArray(data);
- InputStream newStream1 = new ByteArrayInputStream(gameData);
- GameGUI.paintGame(newStream1, cl, main, buttons, colors, madeMoves, data, path);
+ InputStream gameStream = new ByteArrayInputStream(gameData);
+ GameGUI.paintGame(gameStream, cl, main, buttons, colors, madeMoves, data, path);
}
public static ArrayList readFromFile(InputStream inputStream){
@@ -90,8 +88,8 @@ public class HitoriMain2 extends JFrame implements ActionListener{
for(int i=0;i madeMoves,String[][] data,String path) throws FileNotFoundException{
+ public static void totalResetButton(InputStream inputStream, CardLayout cl, JPanel main, JButton[][] buttonArray, String[][] colors,Stack madeMoves,String[][] data,String path) throws FileNotFoundException{
madeMoves.clear();
for(int i = 0; i highscores = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(
@@ -260,21 +267,16 @@ public class HitoriMain2 extends JFrame implements ActionListener{
}
}
}
-
- @Override
- public void actionPerformed(ActionEvent e) {
- }
- public static JLabel getAvgTime(byte[] data, String filename) throws IOException {
- String text = "Durchschnittszeit: ";
+ public static String getAvgTime(byte[] data, String filename) throws IOException {
int totalSeconds = 0;
int count = 0;
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(new ByteArrayInputStream(data), StandardCharsets.UTF_8))) {
String line;
DateTimeFormatter dtf = new DateTimeFormatterBuilder()
- .appendPattern("mm:ss") // we only have minutes and seconds
- .parseDefaulting(ChronoField.HOUR_OF_DAY, 0) // default hour = 0
+ .appendPattern("mm:ss")
+ .parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
.toFormatter();
while ((line = reader.readLine()) != null) {
line = line.trim();
@@ -291,9 +293,8 @@ public class HitoriMain2 extends JFrame implements ActionListener{
int timeInt = totalSeconds/count;
int minutes = timeInt/60;
int seconds = timeInt%60;
- String time= minutes+":"+seconds;
- JLabel avgTime = new JLabel(text + time);
- return avgTime;
+ String timeString= "Durchschnittszeit: " + minutes+":"+seconds;
+ return timeString;
}
}
}
diff --git a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/GameGUI.java b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/GameGUI.java
index 40b79f0..b2bf3b7 100644
--- a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/GameGUI.java
+++ b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/GameGUI.java
@@ -7,8 +7,9 @@ import java.util.Stack;
import java.util.Timer;
import java.util.TimerTask;
import java.io.*;
-import javax.swing.*;
-import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
+import javax.swing.*;
+
+import de.hs_mannheim.informatik.mvn.domain.HitoriMain;
import de.hs_mannheim.informatik.mvn.domain.LogHighscores;
public class GameGUI extends JFrame implements ActionListener {
@@ -34,28 +35,28 @@ public class GameGUI extends JFrame implements ActionListener {
b.setFocusPainted(false);
b.setBackground(Color.WHITE);
gameGrid.add(b);
- String[] pos = HitoriMain2.getCords(i,j);
+ String[] pos = HitoriMain.getCords(i,j);
b.addActionListener(e -> {paintButton(cl, main, b, pos, colors , madeMoves);});
}
}
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(gameGrid, BorderLayout.CENTER);
JPanel buttonGrid = new JPanel(new GridLayout(1,4,10,10));
- JButton b0 = new JButton("Aufgeben");
- b0.addActionListener(e -> {
+ JButton aufgebenButton = new JButton("Aufgeben");
+ aufgebenButton.addActionListener(e -> {
filepath[0] = "";
filepath[1] = "";
cl.show(main, "HAUPT");
});
- JButton b1 = new JButton("Zurück");
- b1.addActionListener(e -> {backOneStep(cl, main, madeMoves, buttons, colors, gameGrid);});
- JButton b2 = new JButton("Zurücksetzen");
- b2.addActionListener(e -> {try {
- HitoriMain2.totalResetButton(inputStream, cl, main, buttons, colors, madeMoves, data, path0);
+ JButton zurückButton = new JButton("Zurück");
+ zurückButton.addActionListener(e -> {backOneStep(cl, main, madeMoves, buttons, colors, gameGrid);});
+ JButton resetButton = new JButton("Zurücksetzen");
+ resetButton.addActionListener(e -> {try {
+ HitoriMain.totalResetButton(inputStream, cl, main, buttons, colors, madeMoves, data, path0);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}});
- JButton b3 = new JButton("Abgeben");
+ JButton abgebenButton = new JButton("Abgeben");
boolean[] levelFinished = {false};
JPanel topGrid = new JPanel(new GridLayout(1,2,10,10));
mainPanel.add(topGrid, BorderLayout.NORTH);
@@ -63,7 +64,7 @@ public class GameGUI extends JFrame implements ActionListener {
topGrid.add(timeLabel);
topGrid.revalidate();
topGrid.repaint();
- boolean isOkay = HitoriMain2.abgabeMöglich(inputStream, data, colors);
+ boolean isOkay = HitoriMain.abgabeMöglich(inputStream, data, colors);
levelFinished[0] = isOkay;
Timer timer = new Timer();
startTimer();
@@ -82,14 +83,12 @@ public class GameGUI extends JFrame implements ActionListener {
});
}
}, 0, 1000);
-
- JLabel luecke = new JLabel("");
- topGrid.add(luecke);
-
- b3.addActionListener(e -> {
+ JLabel platzhalter = new JLabel("");
+ topGrid.add(platzhalter);
+ abgebenButton.addActionListener(e -> {
try {
InputStream newStream = new ByteArrayInputStream(gameData);
- levelFinished[0] = HitoriMain2.abgabeMöglich(newStream, data, colors);
+ levelFinished[0] = HitoriMain.abgabeMöglich(newStream, data, colors);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
@@ -102,115 +101,81 @@ public class GameGUI extends JFrame implements ActionListener {
e1.printStackTrace();
}
} else {
- luecke.setText("Abgabe nicht richtig!");
+ platzhalter.setText("Abgabe nicht richtig!");
mainPanel.revalidate();
mainPanel.repaint();
}
});
-
- buttonGrid.add(b0);buttonGrid.add(b1);buttonGrid.add(b2);buttonGrid.add(b3);
+ buttonGrid.add(aufgebenButton);
+ buttonGrid.add(zurückButton);
+ buttonGrid.add(resetButton);
+ buttonGrid.add(abgebenButton);
mainPanel.add(buttonGrid, BorderLayout.SOUTH);
mainPanel.setVisible(true);
main.add(mainPanel, "GAME");
cl.show(main, "GAME");
}
- public static void paintButton(CardLayout cl, JPanel main, JButton b, String[] pos, String[][] colors, Stack madeMoves){
+ public static void paintButton(CardLayout cl, JPanel main, JButton button, String[] pos, String[][] colors, Stack madeMoves){
int i = Integer.parseInt(pos[0]);
int j = Integer.parseInt(pos[1]);
- String col = colors[Integer.parseInt(pos[0])][Integer.parseInt(pos[1])];
- if(col.endsWith("W")){
- b.setOpaque(true);
- b.setForeground(Color.BLACK);
- b.setContentAreaFilled(true);
- b.setBorderPainted(false);
- b.setFocusPainted(false);
- b.setBackground(Color.lightGray);
- colors[i][j] += "G";
- String logEntrance = i+"."+j+"."+"G";
- madeMoves.push(logEntrance);
- }
- if(col.endsWith("G")){
- b.setOpaque(true);
- b.setForeground(Color.WHITE);
- b.setContentAreaFilled(true);
- b.setBorderPainted(false);
- b.setFocusPainted(false);
- b.setBackground(Color.BLACK);
- colors[i][j] += "B";
- String logEntrance = i+"."+j+"."+"B";
- madeMoves.push(logEntrance);
- }
- if(col.endsWith("B")){
- b.setOpaque(true);
- b.setForeground(Color.BLACK);
- b.setContentAreaFilled(true);
- b.setBorderPainted(false);
- b.setFocusPainted(false);
- b.setBackground(Color.WHITE);
- colors[i][j] += "W";
- String logEntrance = i+"."+j+"."+"W";
- madeMoves.push(logEntrance);
- }
+ String col = colors[i][j];
+ String lastLetterString = String.valueOf(col.charAt(col.length()-1));
+ button.setOpaque(true);
+ button.setContentAreaFilled(true);
+ button.setBorderPainted(false);
+ button.setFocusPainted(false);
+ switch(lastLetterString) {
+ case "W":
+ button.setForeground(Color.BLACK);
+ button.setBackground(Color.lightGray);
+ break;
+ case "G":
+ button.setForeground(Color.WHITE);
+ button.setBackground(Color.BLACK);
+ break;
+ case "B":
+ button.setForeground(Color.BLACK);
+ button.setBackground(Color.WHITE);
+ break;
+ default:
+ System.exit(0);
+ }
+ colors[i][j] += lastLetterString;
+ String newMove = i+"."+j+"."+lastLetterString;
+ madeMoves.push(newMove);
}
-
+
public static void backOneStep(CardLayout cl, JPanel main, Stack movesMade, JButton[][] buttons, String[][] colors, JPanel grid){
- try {
String move = movesMade.pop();
String[] line = move.split("\\.");
- String y = line[0];
- String x = line[1];
+ int i = Integer.parseInt(line[0]);
+ int j = Integer.parseInt(line[1]);
String color = line[2];
- if(color.equals("W")){
- int i = Integer.parseInt(y);
- int j = Integer.parseInt(x);
- JButton b0 = buttons[i][j];
- b0.setOpaque(true);
- b0.setForeground(Color.WHITE);
- b0.setContentAreaFilled(true);
- b0.setBorderPainted(false);
- b0.setFocusPainted(false);
- b0.setBackground(Color.BLACK);
- buttons[i][j] = b0;
- String str = colors[i][j];
- String str0 = str.substring(0, str.length() - 1);
- colors[i][j] = str0;
- grid.repaint();
- gridUpdate(grid, buttons);
- }else if(color.equals("G")){
- int i = Integer.parseInt(y);
- int j = Integer.parseInt(x);
- JButton b0 = buttons[i][j];
- b0.setOpaque(true);
- b0.setForeground(Color.BLACK);
- b0.setContentAreaFilled(true);
- b0.setBorderPainted(false);
- b0.setFocusPainted(false);
- b0.setBackground(Color.WHITE);
- buttons[i][j] = b0;
- String str = colors[i][j];
- String str0 = str.substring(0, str.length() - 1);
- colors[i][j] = str0;
- gridUpdate(grid, buttons);
- } else if(color.equals("B")){
- int i = Integer.parseInt(y);
- int j = Integer.parseInt(x);
- JButton b0 = buttons[i][j];
- b0.setOpaque(true);
- b0.setForeground(Color.BLACK);
- b0.setContentAreaFilled(true);
- b0.setBorderPainted(false);
- b0.setFocusPainted(false);
- b0.setBackground(Color.lightGray);
- buttons[i][j] = b0;
- String str = colors[i][j];
- String str0 = str.substring(0, str.length() - 1);
- colors[i][j] = str0;
- gridUpdate(grid, buttons);
- }
- } catch(EmptyStackException e) {
- e.getStackTrace();
- }
+ JButton button = buttons[i][j];
+ button.setOpaque(true);
+ button.setContentAreaFilled(true);
+ button.setBorderPainted(false);
+ button.setFocusPainted(false);
+ switch(color) {
+ case "W":
+ button.setForeground(Color.WHITE);
+ button.setBackground(Color.BLACK);
+ break;
+ case "G":
+ button.setForeground(Color.BLACK);
+ button.setBackground(Color.WHITE);
+ break;
+ case "B":
+ button.setForeground(Color.BLACK);
+ button.setBackground(Color.lightGray);
+ break;
+ }
+ String colorString = colors[i][j];
+ String colorStringWithoutLastElement = colorString.substring(0, colorString.length() - 1);
+ colors[i][j] = colorStringWithoutLastElement;
+ grid.repaint();
+ gridUpdate(grid, buttons);
}
public static void gridUpdate(JPanel grid, JButton[][] buttons){
@@ -218,8 +183,8 @@ public class GameGUI extends JFrame implements ActionListener {
grid.repaint();
for(int i = 0; i {
+ addHighscoreButton.addActionListener(e -> {
String username = field.getText();
try {
LogHighscores.newRecord(path, username, endtime);
diff --git a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/HighscoreGUI.java b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/HighscoreGUI.java
index 7c045ed..ddae127 100644
--- a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/HighscoreGUI.java
+++ b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/HighscoreGUI.java
@@ -21,7 +21,8 @@ import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
-import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
+
+import de.hs_mannheim.informatik.mvn.domain.HitoriMain;
public class HighscoreGUI extends JFrame implements ActionListener {
@@ -46,12 +47,11 @@ public class HighscoreGUI extends JFrame implements ActionListener {
public HighscoreGUI(CardLayout cl, JPanel main) {
JPanel highscorePanel = new JPanel(new BorderLayout());
JPanel buttonPanel = new JPanel(new GridLayout(7, 1, 10, 10));
-
for (int i = 0; i < buttons.length; i++) {
- JButton b0 = new JButton(buttons[i]);
- buttonPanel.add(b0);
+ JButton button = new JButton(buttons[i]);
+ buttonPanel.add(button);
final int index = i;
- b0.addActionListener(e -> {
+ button.addActionListener(e -> {
String resourcePathInJar = paths[index];
String localFileName = resourcePathInJar.substring(resourcePathInJar.lastIndexOf('/') + 1);
File outFile = new File("resources/Hitori_Highscores", localFileName);
@@ -59,20 +59,20 @@ public class HighscoreGUI extends JFrame implements ActionListener {
copyResourceIfNotExists(resourcePathInJar, outFile);
byte[] data = Files.readAllBytes(outFile.toPath());
showHighscores(cl, main, data, outFile.getPath());
- } catch (IOException ex1) {
- ex1.printStackTrace();
+ } catch (IOException e1) {
+ e1.printStackTrace();
empty(cl, main);
}
});
}
- JButton b = new JButton("Zurück");
- b.addActionListener(e -> cl.show(main, "HAUPT"));
- buttonPanel.add(b);
+ JButton zurückButton = new JButton("Zurück");
+ zurückButton.addActionListener(e -> cl.show(main, "HAUPT"));
+ buttonPanel.add(zurückButton);
highscorePanel.setVisible(true);
highscorePanel.setSize(600, 600);
highscorePanel.add(buttonPanel, BorderLayout.CENTER);
- JLabel text0 = new JLabel("Level für Highscore Liste auswählen!");
- highscorePanel.add(text0, BorderLayout.NORTH);
+ JLabel topText = new JLabel("Level für Highscore Liste auswählen!");
+ highscorePanel.add(topText, BorderLayout.NORTH);
main.add(highscorePanel, "HIGHSCORES");
cl.show(main, "HIGHSCORES");
}
@@ -97,19 +97,19 @@ public class HighscoreGUI extends JFrame implements ActionListener {
public static void empty(CardLayout cl, JPanel main) {
JPanel panel = new JPanel(new BorderLayout());
- JButton b = new JButton("Zurück");
- JLabel text = new JLabel("Noch kein Highscore eingetragen.");
- panel.add(text, BorderLayout.CENTER);
- panel.add(b, BorderLayout.SOUTH);
- b.addActionListener(e -> cl.show(main, "HIGHSCORES"));
+ JButton zurückButton = new JButton("Zurück");
+ JLabel topText = new JLabel("Noch kein Highscore eingetragen.");
+ panel.add(topText, BorderLayout.CENTER);
+ panel.add(zurückButton);
+ zurückButton.addActionListener(e -> cl.show(main, "HIGHSCORES"));
main.add(panel, "EMPTY");
cl.show(main, "EMPTY");
}
public static void showHighscores(CardLayout cl, JPanel main, byte[] data, String filename) throws IOException {
- HitoriMain2.sortByTime(data, filename);
+ HitoriMain.sortByTime(data, filename);
data = Files.readAllBytes(new File(filename).toPath());
- JPanel highscorePanel1 = new JPanel(new BorderLayout());
+ JPanel highscorePanel = new JPanel(new BorderLayout());
List lines = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(new ByteArrayInputStream(data), StandardCharsets.UTF_8))) {
@@ -120,38 +120,21 @@ public class HighscoreGUI extends JFrame implements ActionListener {
} catch (IOException e) {
e.printStackTrace();
}
-
- boolean hasContent = false;
- for (String l : lines) {
- if (!l.trim().isEmpty()) {
- hasContent = true;
- break;
- }
+ JPanel entryPanel = new JPanel(new GridLayout(lines.size(), 1, 10, 10));
+ for (String s : lines) {
+ JLabel text = new JLabel(s);
+ entryPanel.add(text);
}
-
- if (hasContent) {
- JPanel entryPanel = new JPanel(new GridLayout(lines.size(), 1, 10, 10));
- for (String s : lines) {
- if (!s.trim().isEmpty()) {
- JLabel text = new JLabel(s);
- entryPanel.add(text);
- }
- }
- highscorePanel1.add(entryPanel, BorderLayout.CENTER);
- JLabel avgTime = HitoriMain2.getAvgTime(data, filename);
- highscorePanel1.add(avgTime, BorderLayout.NORTH);
- } else {
- JLabel text = new JLabel("Noch kein Highscore eingetragen.");
- highscorePanel1.add(text, BorderLayout.CENTER);
- }
-
- JButton b = new JButton("OK");
- highscorePanel1.add(b, BorderLayout.SOUTH);
- b.addActionListener(e -> cl.show(main, "HIGHSCORES"));
-
- highscorePanel1.setVisible(true);
- highscorePanel1.setSize(600, 600);
- main.add(highscorePanel1, "HIGHSCOREEINTRAG");
+ highscorePanel.add(entryPanel, BorderLayout.CENTER);
+ String avgTime = HitoriMain.getAvgTime(data, filename);
+ JLabel avgTimeJLabel = new JLabel(avgTime);
+ highscorePanel.add(avgTimeJLabel, BorderLayout.NORTH);
+ JButton okButton = new JButton("OK");
+ highscorePanel.add(okButton, BorderLayout.SOUTH);
+ okButton.addActionListener(e -> cl.show(main, "HIGHSCORES"));
+ highscorePanel.setVisible(true);
+ highscorePanel.setSize(600, 600);
+ main.add(highscorePanel, "HIGHSCOREEINTRAG");
cl.show(main, "HIGHSCOREEINTRAG");
}
diff --git a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/MenuGUI.java b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/MenuGUI.java
index 2ed15a9..f8b6dc0 100644
--- a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/MenuGUI.java
+++ b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/MenuGUI.java
@@ -12,7 +12,8 @@ import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
-import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
+
+import de.hs_mannheim.informatik.mvn.domain.HitoriMain;
public class MenuGUI extends JFrame implements ActionListener {
@@ -40,18 +41,18 @@ public class MenuGUI extends JFrame implements ActionListener {
"/Hitori_Spielfelder/Hitori15x15_medium.csv"
};
for(int i=0;i {
+ button.addActionListener(e -> {
int j = count[0];
filepath[0] = paths[j];
filepath[1] = num[0];
try (InputStream inputStream = getClass().getResourceAsStream(filepath[0])) {
if (inputStream != null) {
String path=filepath[0];
- HitoriMain2.ablauf(cl, main, inputStream, Integer.parseInt(filepath[1]), path);
+ HitoriMain.ablauf(cl, main, inputStream, Integer.parseInt(filepath[1]), path);
} else {
throw new FileNotFoundException("Resource not found: " + filepath[0]);
}
@@ -60,14 +61,14 @@ public class MenuGUI extends JFrame implements ActionListener {
}
});
}
- JButton b = new JButton("Highscores");
- b.addActionListener(e -> {
+ JButton highscoreButton = new JButton("Highscores");
+ highscoreButton.addActionListener(e -> {
new HighscoreGUI(cl, main);
});
- buttonPanel.add(b);
+ buttonPanel.add(highscoreButton);
menuPanel.add(buttonPanel, BorderLayout.CENTER);
- JLabel text0 = new JLabel("Wählen Sie ein Level aus!");
- menuPanel.add(text0, BorderLayout.NORTH);
+ JLabel topText = new JLabel("Wählen Sie ein Level aus!");
+ menuPanel.add(topText, BorderLayout.NORTH);
setVisible(true);
setSize(600, 600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
diff --git a/PR2Projekt/src/test/java/de/hs_mannheim/informatik/mvn/test/HitoriTest.java b/PR2Projekt/src/test/java/de/hs_mannheim/informatik/mvn/test/HitoriTest.java
index 1d18275..20fda25 100644
--- a/PR2Projekt/src/test/java/de/hs_mannheim/informatik/mvn/test/HitoriTest.java
+++ b/PR2Projekt/src/test/java/de/hs_mannheim/informatik/mvn/test/HitoriTest.java
@@ -1,60 +1,43 @@
package de.hs_mannheim.informatik.mvn.test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.time.LocalTime;
-import java.time.format.DateTimeFormatter;
-import java.time.format.DateTimeFormatterBuilder;
-import java.time.temporal.ChronoField;
import java.util.ArrayList;
import java.util.Arrays;
-
-import javax.swing.JButton;
-import javax.swing.JLabel;
-
-import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
+import de.hs_mannheim.informatik.mvn.domain.HitoriMain;
import de.hs_mannheim.informatik.mvn.gui.GameGUI;
class HitoriTest{
@Test
- void test1() {
+ void makeColorArrayTest1() {
String[][] array3x3 = {
{"W", "W", "W"},
{"W", "W", "W"},
{"W", "W", "W"}
};
- assertTrue(Arrays.deepEquals(array3x3, HitoriMain2.makeColorArray(3)));
+ assertTrue(Arrays.deepEquals(array3x3, HitoriMain.makeColorArray(3)));
}
@Test
- void test2() {
+ void makeColorArrayTest2() {
String[][] array3x2 = {
{"W", "W", "W"},
{"W", "W", "W"},
};
- assertFalse(Arrays.deepEquals(array3x2, HitoriMain2.makeColorArray(3)));
+ assertFalse(Arrays.deepEquals(array3x2, HitoriMain.makeColorArray(3)));
}
@Test
- void test3() {
+ void checkStartTimeTest() {
assertEquals("Zeit: 00:00", GameGUI.startTimer());
}
@Test
- void test4() {
+ void checkArraySameTest1() {
String[][] data = {
{"W", "B", "W", "W"},
{"W", "W", "W", "B"},
@@ -65,11 +48,11 @@ class HitoriTest{
{"W", "W", "W", "B"},
{"W", "B", "W", "W"},
{"B", "W", "W", "B"}};
- assertFalse(HitoriMain2.checkArraySame(data, colors));
+ assertFalse(HitoriMain.checkArraySame(data, colors));
}
@Test
- void test5() {
+ void checkArraySameTest2() {
String[][] data = {
{"W", "B", "W", "W"},
{"W", "W", "W", "B"},
@@ -81,11 +64,11 @@ class HitoriTest{
{"W", "B", "W", "W"},
{"B", "W", "W", "B"}};
- assertTrue(HitoriMain2.checkArraySame(data, colors));
+ assertTrue(HitoriMain.checkArraySame(data, colors));
}
@Test
- void test6() {
+ void checkArraySameTest3() {
String[][] data = {
{"B", "W", "W", "B", "W"},
{"W", "W", "B", "W", "W"},
@@ -98,11 +81,11 @@ class HitoriTest{
{"W", "B", "W", "W", "W"},
{"W", "B", "W", "W", "W"},
{"W", "B", "W", "W", "W"}};
- assertFalse(HitoriMain2.checkArraySame(data, colors));
+ assertFalse(HitoriMain.checkArraySame(data, colors));
}
@Test
- void test7() {
+ void checkArraySameTest4() {
String[][] data = {
{"B", "W", "W", "B", "W"},
{"W", "W", "B", "W", "W"},
@@ -115,23 +98,23 @@ class HitoriTest{
{"B", "W", "W", "B", "W"},
{"W", "W", "B", "W", "W"},
{"B", "W", "W", "W", "B"}};
- assertTrue(HitoriMain2.checkArraySame(data, colors));
+ assertTrue(HitoriMain.checkArraySame(data, colors));
}
@Test
- void test8() {
+ void getCordsTest1() {
String[] array = {"3", "4"};
- assertFalse(Arrays.deepEquals(array, HitoriMain2.getCords(3, 3)));
+ assertFalse(Arrays.deepEquals(array, HitoriMain.getCords(3, 3)));
}
@Test
- void test9() {
+ void getCordsTest2() {
String[] array = {"3", "4"};
- assertTrue(Arrays.deepEquals(array, HitoriMain2.getCords(3, 4)));
+ assertTrue(Arrays.deepEquals(array, HitoriMain.getCords(3, 4)));
}
@Test
- void test10() throws FileNotFoundException {
+ void checkArraySameTest5() throws FileNotFoundException {
String[][] data = {
{"B", "W", "B", "W", "W", "B", "W", "W", "W", "B"},
{"W", "W", "W", "B", "W", "W", "B", "W", "W", "W"},
@@ -154,11 +137,11 @@ class HitoriTest{
{"B", "W", "B", "W", "W", "B", "W", "W", "W", "W"},
{"W", "W", "W", "B", "W", "W", "B", "W", "B", "W"},
{"B", "W", "B", "W", "W", "W", "W", "W", "W", "B"}};
- assertTrue(HitoriMain2.checkArraySame(data, colors));
+ assertTrue(HitoriMain.checkArraySame(data, colors));
}
@Test
- void test11() {
+ void checkArraySameTest6() {
String[][] data = {
{"B", "W", "B", "W", "W", "B", "W", "W", "W", "B"},
{"W", "W", "W", "B", "W", "W", "B", "W", "W", "W"},
@@ -181,11 +164,11 @@ class HitoriTest{
{"B", "W", "B", "W", "W", "B", "W", "W", "W", "W"},
{"W", "W", "W", "B", "W", "W", "B", "W", "B", "W"},
{"B", "W", "B", "W", "W", "W", "W", "W", "W", "W"}};
- assertFalse(HitoriMain2.checkArraySame(data, colors));
+ assertFalse(HitoriMain.checkArraySame(data, colors));
}
@Test
- void test12() {
+ void getResultTest1() {
String[][] data = {
{"W", "G", "B", "W"},
{"G", "B", "W", "G"},
@@ -201,11 +184,11 @@ class HitoriTest{
{"W", "B", "W", "W"},
{"B", "W", "W", "B"},
{"W", "W", "B", "W"}};
- assertTrue(Arrays.deepEquals(array, HitoriMain2.getResult(data, colors)));
+ assertTrue(Arrays.deepEquals(array, HitoriMain.getResult(data, colors)));
}
@Test
- void test13() {
+ void getResultTest2() {
String[][] data = {
{"W", "G", "B", "W"},
{"G", "B", "W", "G"},
@@ -221,15 +204,15 @@ class HitoriTest{
{"G", "B", "W", "W"},
{"B", "W", "W", "B"},
{"W", "W", "B", "W"}};
- assertFalse(Arrays.deepEquals(array, HitoriMain2.getResult(data, colors)));
+ assertFalse(Arrays.deepEquals(array, HitoriMain.getResult(data, colors)));
}
@Test
- void test14() throws FileNotFoundException {
+ void getSolutionTest1() throws FileNotFoundException {
String[] ergebnis4x4 = {"0,1", "1,3", "2,1", "3,0", "3,3"};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path);
- ArrayList filteredData = HitoriMain2.getSolution(inputStream);
+ ArrayList filteredData = HitoriMain.getSolution(inputStream);
assertEquals(5, filteredData.size());
assertEquals(ergebnis4x4[0], filteredData.get(0));
assertEquals(ergebnis4x4[1], filteredData.get(1));
@@ -239,11 +222,11 @@ class HitoriTest{
}
@Test
- void test15() throws FileNotFoundException {
+ void getSolutionTest2() throws FileNotFoundException {
String[] ergebnis4x4 = {"0,0"};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path);
- ArrayList filteredData = HitoriMain2.getSolution(inputStream);
+ ArrayList filteredData = HitoriMain.getSolution(inputStream);
assertNotEquals(1, filteredData.size());
assertNotEquals(ergebnis4x4[0], filteredData.get(0));
assertNotEquals(ergebnis4x4[0], filteredData.get(1));
@@ -253,27 +236,27 @@ class HitoriTest{
}
@Test
- void test16() {
+ void makeColorArrayTest3() {
String[][] colors = {
{"W", "W", "W", "W"},
{"W", "W", "W", "W"},
{"W", "W", "W", "W"},
{"W", "W", "W", "W"}};
- assertTrue(Arrays.deepEquals(colors, HitoriMain2.makeColorArray(4)));
+ assertTrue(Arrays.deepEquals(colors, HitoriMain.makeColorArray(4)));
}
@Test
- void test17() {
+ void makeColorArrayTest4() {
String[][] colors = {
{"B", "W", "W", "W"},
{"B", "W", "W", "W"},
{"B", "W", "W", "W"},
{"B", "W", "W", "W"}};
- assertFalse(Arrays.deepEquals(colors, HitoriMain2.makeColorArray(4)));
+ assertFalse(Arrays.deepEquals(colors, HitoriMain.makeColorArray(4)));
}
@Test
- void test18() throws FileNotFoundException {
+ void getDataTest1() throws FileNotFoundException {
String[][] data = {
{"3", "3", "1", "4"},
{"4", "3", "2", "2"},
@@ -281,11 +264,11 @@ class HitoriTest{
{"3", "4", "3", "2"}};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path);
- assertTrue(Arrays.deepEquals(data, HitoriMain2.getData(inputStream, 4)));
+ assertTrue(Arrays.deepEquals(data, HitoriMain.getData(inputStream, 4)));
}
@Test
- void test19() throws FileNotFoundException {
+ void getDataTest2() throws FileNotFoundException {
String[][] data = {
{"3", "0", "1", "4"},
{"4", "0", "2", "2"},
@@ -293,11 +276,11 @@ class HitoriTest{
{"3", "0", "3", "2"}};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path);
- assertFalse(Arrays.deepEquals(data, HitoriMain2.getData(inputStream, 4)));
+ assertFalse(Arrays.deepEquals(data, HitoriMain.getData(inputStream, 4)));
}
@Test
- void test20() {
+ void readFromFileTest1() {
String[] file = {
"3,3,1,4",
"4,3,2,2",
@@ -316,12 +299,12 @@ class HitoriTest{
}
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path);
- ArrayList ergebnisList = HitoriMain2.readFromFile(inputStream);
+ ArrayList ergebnisList = HitoriMain.readFromFile(inputStream);
assertEquals(fileEntry, ergebnisList);
}
@Test
- void test21() {
+ void readFromFileTest2() {
String[] file = {
"3,3,1,0",
"4,3,2,0",
@@ -340,7 +323,7 @@ class HitoriTest{
}
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path);
- ArrayList ergebnisList = HitoriMain2.readFromFile(inputStream);
+ ArrayList ergebnisList = HitoriMain.readFromFile(inputStream);
assertNotEquals(fileEntry, ergebnisList);
}
@@ -353,11 +336,11 @@ class HitoriTest{
{"B", "W", "W", "B"}};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path);
- ArrayList filteredData = HitoriMain2.getSolution(inputStream);
+ ArrayList filteredData = HitoriMain.getSolution(inputStream);
InputStream newStream = getClass().getResourceAsStream(path);
int rows = 4;
- String[][] data = HitoriMain2.getData(newStream, rows);
- assertTrue(Arrays.deepEquals(ergebnis1, HitoriMain2.getErgebnisArray(data, filteredData)));
+ String[][] data = HitoriMain.getData(newStream, rows);
+ assertTrue(Arrays.deepEquals(ergebnis1, HitoriMain.getErgebnisArray(data, filteredData)));
}
@Test
@@ -369,11 +352,11 @@ class HitoriTest{
{"W", "W", "W", "W"}};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path);
- ArrayList filteredData = HitoriMain2.getSolution(inputStream);
+ ArrayList filteredData = HitoriMain.getSolution(inputStream);
InputStream newStream = getClass().getResourceAsStream(path);
int rows = 4;
- String[][] data = HitoriMain2.getData(newStream, rows);
- assertFalse(Arrays.deepEquals(ergebnis1, HitoriMain2.getErgebnisArray(data, filteredData)));
+ String[][] data = HitoriMain.getData(newStream, rows);
+ assertFalse(Arrays.deepEquals(ergebnis1, HitoriMain.getErgebnisArray(data, filteredData)));
}
@Test
@@ -385,6 +368,45 @@ class HitoriTest{
void test25() throws IOException {
}
-
-
+
+ @Test
+ void getErgebnisArrayTest1() throws IOException {
+ String[][] ergebnis1 = {
+ {"W", "B", "W", "W"},
+ {"W", "W", "W", "B"},
+ {"W", "B", "W", "W"},
+ {"B", "W", "W", "B"}};
+ String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
+ InputStream inputStream = getClass().getResourceAsStream(path);
+ ArrayList filteredData = HitoriMain.getSolution(inputStream);
+ InputStream newStream = getClass().getResourceAsStream(path);
+ int rows = 4;
+ String[][] data = HitoriMain.getData(newStream, rows);
+ assertTrue(Arrays.deepEquals(ergebnis1, HitoriMain.getErgebnisArray(data, filteredData)));
+ }
+
+
+ @Test
+ void getErgebnisArrayTest2() throws IOException {
+ String[][] ergebnis1 = {
+ {"W", "W", "W", "W"},
+ {"W", "W", "W", "W"},
+ {"W", "W", "W", "W"},
+ {"W", "W", "W", "W"}};
+ String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
+ InputStream inputStream = getClass().getResourceAsStream(path);
+ ArrayList filteredData = HitoriMain.getSolution(inputStream);
+ InputStream newStream = getClass().getResourceAsStream(path);
+ int rows = 4;
+ String[][] data = HitoriMain.getData(newStream, rows);
+ assertFalse(Arrays.deepEquals(ergebnis1, HitoriMain.getErgebnisArray(data, filteredData)));
+ }
+
}
+
+
+
+
+
+
+