Compare commits

..

No commits in common. "a45a306cb9bf25626750424c14957d945ccfd50e" and "9558edfc9de1c2f4e36a07034a43296acef1a104" have entirely different histories.

19 changed files with 299 additions and 244 deletions

View File

@ -1,39 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
<!-- JRE System Library --> <!-- JRE System Library -->
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
<attributes> <attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<!-- JUnit 5 Library --> <!-- JUnit Library -->
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<!-- Source Folders --> <!-- Main Source Folder -->
<classpathentry kind="src" path="src/main/java"> <classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
<output>target/classes</output>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="src/test/java">
<!-- Test Source Folder -->
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/> <attribute name="test" value="true"/>
</attributes> </attributes>
<output>target/test-classes</output>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="src/main/java/resources" excluding="**">
<!-- Test Resources -->
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/main/java/resources">
<attributes> <attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/> <attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes> </attributes>
<output>target/test-classes</output>
</classpathentry> </classpathentry>
<!-- Maven Dependencies --> <!-- Maven Dependencies -->
@ -43,6 +44,42 @@
</attributes> </attributes>
</classpathentry> </classpathentry>
<!-- Output Directory --> <!-- Output Folder -->
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/main/java/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="lib" path="src/main/java/de/hs_mannheim/informatik/mvn/domain/HitoriMain2.java"/>
<classpathentry kind="output" path="bin"/>
</classpathentry>
</classpath> </classpath>

View File

@ -50,6 +50,11 @@
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version> <version>3.6.0</version>
<configuration> <configuration>
<archive>
<manifest>
<mainClass>de.hs_mannheim.informatik.mvn.HitoriMain2</mainClass>
</manifest>
</archive>
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
</configuration> </configuration>
<executions> <executions>
@ -61,7 +66,7 @@
<configuration> <configuration>
<transformers> <transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>de.hs_mannheim.informatik.mvn.domain.HitoriMain</mainClass> <mainClass>src.main.java</mainClass>
</transformer> </transformer>
</transformers> </transformers>
</configuration> </configuration>
@ -113,7 +118,7 @@
<directory>src/test/java</directory> <directory>src/test/java</directory>
</resource> </resource>
<resource> <resource>
<directory>src/main/resources</directory> <directory>src/main/java/resources</directory>
</resource> </resource>
</resources> </resources>
<testSourceDirectory>src/test/java</testSourceDirectory> <testSourceDirectory>src/test/java</testSourceDirectory>

View File

@ -1,6 +1,8 @@
package de.hs_mannheim.informatik.mvn.domain; package de.hs_mannheim.informatik.mvn.domain;
import java.awt.CardLayout; import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -26,7 +28,7 @@ import javax.swing.JPanel;
import java.time.format.DateTimeFormatterBuilder; import java.time.format.DateTimeFormatterBuilder;
import de.hs_mannheim.informatik.mvn.gui.*; import de.hs_mannheim.informatik.mvn.gui.*;
public class HitoriMain { public class HitoriMain2 extends JFrame implements ActionListener{
private static byte[] gameData; private static byte[] gameData;
@ -41,8 +43,8 @@ public class HitoriMain {
String[][] data = getData(newStream, rows); String[][] data = getData(newStream, rows);
String[][] colors = makeColorArray(data.length); String[][] colors = makeColorArray(data.length);
JButton[][] buttons = makeButtonArray(data); JButton[][] buttons = makeButtonArray(data);
InputStream gameStream = new ByteArrayInputStream(gameData); InputStream newStream1 = new ByteArrayInputStream(gameData);
GameGUI.paintGame(gameStream, cl, main, buttons, colors, madeMoves, data, path); GameGUI.paintGame(newStream1, cl, main, buttons, colors, madeMoves, data, path);
} }
public static ArrayList<String> readFromFile(InputStream inputStream){ public static ArrayList<String> readFromFile(InputStream inputStream){
@ -88,8 +90,8 @@ public class HitoriMain {
for(int i=0;i<data.length;i++){ for(int i=0;i<data.length;i++){
for(int j=0;j<data.length;j++){ for(int j=0;j<data.length;j++){
String number = data[i][j]; String number = data[i][j];
JButton button = new JButton(number); JButton b = new JButton(number);
buttons[i][j] = button; buttons[i][j] = b;
} }
} }
return buttons; return buttons;
@ -126,20 +128,20 @@ public class HitoriMain {
public static String[] getCords(int i, int j){ public static String[] getCords(int i, int j){
String yKoordinate = String.valueOf(i); String yKoordinate = String.valueOf(i);
String xKoordinate = String.valueOf(j); String xKoordinate = String.valueOf(j);
String[] position = {yKoordinate, xKoordinate}; String[] pos = {yKoordinate, xKoordinate};
return position; return pos;
} }
public static void totalResetButton(InputStream inputStream, CardLayout cl, JPanel main, JButton[][] buttonArray, String[][] colors,Stack<String> madeMoves,String[][] data,String path) throws FileNotFoundException{ public static void totalResetButton(InputStream inputStream, CardLayout cl, JPanel main, JButton[][] buttons, String[][] colors,Stack<String> madeMoves,String[][] data,String path) throws FileNotFoundException{
madeMoves.clear(); madeMoves.clear();
for(int i = 0; i<data.length;i++){ for(int i = 0; i<data.length;i++){
for(int j = 0; j<data.length;j++){ for(int j = 0; j<data.length;j++){
colors[i][j] = "W"; colors[i][j] = "W";
buttonArray[i][j] = null; buttons[i][j] = null;
} }
JButton[][] buttons = makeButtonArray(data); JButton[][] buttons0 = makeButtonArray(data);
try { try {
GameGUI.paintGame(inputStream, cl, main, buttons, colors, madeMoves, data, path); GameGUI.paintGame(inputStream, cl, main, buttons0, colors, madeMoves, data, path);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -174,11 +176,11 @@ public class HitoriMain {
} }
if (isUnderComment && !line.isEmpty()) { if (isUnderComment && !line.isEmpty()) {
String[] lineArray = line.split(","); String[] lineArray = line.split(",");
int firstNumn = Integer.parseInt(lineArray[0]); int num1 = Integer.parseInt(lineArray[0]);
int secondNum = Integer.parseInt(lineArray[1]); int num2 = Integer.parseInt(lineArray[1]);
String firstNumAsString = String.valueOf(firstNumn - 1); String newNum1 = String.valueOf(num1 - 1);
String secondNumAsString = String.valueOf(secondNum - 1); String newNum2 = String.valueOf(num2 - 1);
String newLine = firstNumAsString + "," + secondNumAsString; String newLine = newNum1 + "," + newNum2;
filteredData.add(newLine); filteredData.add(newLine);
} }
} }
@ -206,15 +208,6 @@ public class HitoriMain {
return ergebnis; return ergebnis;
} }
public static void printArray(String[][] ergebnis) {
for(int i=0;i<ergebnis.length;i++) {
for(int j=0;j<ergebnis.length;j++) {
System.out.print(" " + ergebnis[i][j]);
}
System.out.println();
}
}
public static void sortByTime(byte[] data, String filename) throws IOException { public static void sortByTime(byte[] data, String filename) throws IOException {
ArrayList<HighscoreEintrag> highscores = new ArrayList<>(); ArrayList<HighscoreEintrag> highscores = new ArrayList<>();
try (BufferedReader reader = new BufferedReader( try (BufferedReader reader = new BufferedReader(
@ -268,15 +261,20 @@ public class HitoriMain {
} }
} }
public static String getAvgTime(byte[] data, String filename) throws IOException { @Override
public void actionPerformed(ActionEvent e) {
}
public static JLabel getAvgTime(byte[] data, String filename) throws IOException {
String text = "Durchschnittszeit: ";
int totalSeconds = 0; int totalSeconds = 0;
int count = 0; int count = 0;
try (BufferedReader reader = new BufferedReader( try (BufferedReader reader = new BufferedReader(
new InputStreamReader(new ByteArrayInputStream(data), StandardCharsets.UTF_8))) { new InputStreamReader(new ByteArrayInputStream(data), StandardCharsets.UTF_8))) {
String line; String line;
DateTimeFormatter dtf = new DateTimeFormatterBuilder() DateTimeFormatter dtf = new DateTimeFormatterBuilder()
.appendPattern("mm:ss") .appendPattern("mm:ss") // we only have minutes and seconds
.parseDefaulting(ChronoField.HOUR_OF_DAY, 0) .parseDefaulting(ChronoField.HOUR_OF_DAY, 0) // default hour = 0
.toFormatter(); .toFormatter();
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
line = line.trim(); line = line.trim();
@ -293,8 +291,9 @@ public class HitoriMain {
int timeInt = totalSeconds/count; int timeInt = totalSeconds/count;
int minutes = timeInt/60; int minutes = timeInt/60;
int seconds = timeInt%60; int seconds = timeInt%60;
String timeString= "Durchschnittszeit: " + minutes+":"+seconds; String time= minutes+":"+seconds;
return timeString; JLabel avgTime = new JLabel(text + time);
return avgTime;
} }
} }
} }

View File

@ -8,8 +8,7 @@ import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.io.*; import java.io.*;
import javax.swing.*; import javax.swing.*;
import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
import de.hs_mannheim.informatik.mvn.domain.HitoriMain;
import de.hs_mannheim.informatik.mvn.domain.LogHighscores; import de.hs_mannheim.informatik.mvn.domain.LogHighscores;
public class GameGUI extends JFrame implements ActionListener { public class GameGUI extends JFrame implements ActionListener {
@ -35,28 +34,28 @@ public class GameGUI extends JFrame implements ActionListener {
b.setFocusPainted(false); b.setFocusPainted(false);
b.setBackground(Color.WHITE); b.setBackground(Color.WHITE);
gameGrid.add(b); gameGrid.add(b);
String[] pos = HitoriMain.getCords(i,j); String[] pos = HitoriMain2.getCords(i,j);
b.addActionListener(e -> {paintButton(cl, main, b, pos, colors , madeMoves);}); b.addActionListener(e -> {paintButton(cl, main, b, pos, colors , madeMoves);});
} }
} }
JPanel mainPanel = new JPanel(new BorderLayout()); JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(gameGrid, BorderLayout.CENTER); mainPanel.add(gameGrid, BorderLayout.CENTER);
JPanel buttonGrid = new JPanel(new GridLayout(1,4,10,10)); JPanel buttonGrid = new JPanel(new GridLayout(1,4,10,10));
JButton aufgebenButton = new JButton("Aufgeben"); JButton b0 = new JButton("Aufgeben");
aufgebenButton.addActionListener(e -> { b0.addActionListener(e -> {
filepath[0] = ""; filepath[0] = "";
filepath[1] = ""; filepath[1] = "";
cl.show(main, "HAUPT"); cl.show(main, "HAUPT");
}); });
JButton zurückButton = new JButton("Zurück"); JButton b1 = new JButton("Zurück");
zurückButton.addActionListener(e -> {backOneStep(cl, main, madeMoves, buttons, colors, gameGrid);}); b1.addActionListener(e -> {backOneStep(cl, main, madeMoves, buttons, colors, gameGrid);});
JButton resetButton = new JButton("Zurücksetzen"); JButton b2 = new JButton("Zurücksetzen");
resetButton.addActionListener(e -> {try { b2.addActionListener(e -> {try {
HitoriMain.totalResetButton(inputStream, cl, main, buttons, colors, madeMoves, data, path0); HitoriMain2.totalResetButton(inputStream, cl, main, buttons, colors, madeMoves, data, path0);
} catch (FileNotFoundException e1) { } catch (FileNotFoundException e1) {
e1.printStackTrace(); e1.printStackTrace();
}}); }});
JButton abgebenButton = new JButton("Abgeben"); JButton b3 = new JButton("Abgeben");
boolean[] levelFinished = {false}; boolean[] levelFinished = {false};
JPanel topGrid = new JPanel(new GridLayout(1,2,10,10)); JPanel topGrid = new JPanel(new GridLayout(1,2,10,10));
mainPanel.add(topGrid, BorderLayout.NORTH); mainPanel.add(topGrid, BorderLayout.NORTH);
@ -64,7 +63,7 @@ public class GameGUI extends JFrame implements ActionListener {
topGrid.add(timeLabel); topGrid.add(timeLabel);
topGrid.revalidate(); topGrid.revalidate();
topGrid.repaint(); topGrid.repaint();
boolean isOkay = HitoriMain.abgabeMöglich(inputStream, data, colors); boolean isOkay = HitoriMain2.abgabeMöglich(inputStream, data, colors);
levelFinished[0] = isOkay; levelFinished[0] = isOkay;
Timer timer = new Timer(); Timer timer = new Timer();
startTimer(); startTimer();
@ -83,12 +82,14 @@ public class GameGUI extends JFrame implements ActionListener {
}); });
} }
}, 0, 1000); }, 0, 1000);
JLabel platzhalter = new JLabel("");
topGrid.add(platzhalter); JLabel luecke = new JLabel("");
abgebenButton.addActionListener(e -> { topGrid.add(luecke);
b3.addActionListener(e -> {
try { try {
InputStream newStream = new ByteArrayInputStream(gameData); InputStream newStream = new ByteArrayInputStream(gameData);
levelFinished[0] = HitoriMain.abgabeMöglich(newStream, data, colors); levelFinished[0] = HitoriMain2.abgabeMöglich(newStream, data, colors);
} catch (FileNotFoundException e1) { } catch (FileNotFoundException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
@ -101,81 +102,115 @@ public class GameGUI extends JFrame implements ActionListener {
e1.printStackTrace(); e1.printStackTrace();
} }
} else { } else {
platzhalter.setText("Abgabe nicht richtig!"); luecke.setText("Abgabe nicht richtig!");
mainPanel.revalidate(); mainPanel.revalidate();
mainPanel.repaint(); mainPanel.repaint();
} }
}); });
buttonGrid.add(aufgebenButton);
buttonGrid.add(zurückButton); buttonGrid.add(b0);buttonGrid.add(b1);buttonGrid.add(b2);buttonGrid.add(b3);
buttonGrid.add(resetButton);
buttonGrid.add(abgebenButton);
mainPanel.add(buttonGrid, BorderLayout.SOUTH); mainPanel.add(buttonGrid, BorderLayout.SOUTH);
mainPanel.setVisible(true); mainPanel.setVisible(true);
main.add(mainPanel, "GAME"); main.add(mainPanel, "GAME");
cl.show(main, "GAME"); cl.show(main, "GAME");
} }
public static void paintButton(CardLayout cl, JPanel main, JButton button, String[] pos, String[][] colors, Stack<String> madeMoves){ public static void paintButton(CardLayout cl, JPanel main, JButton b, String[] pos, String[][] colors, Stack<String> madeMoves){
int i = Integer.parseInt(pos[0]); int i = Integer.parseInt(pos[0]);
int j = Integer.parseInt(pos[1]); int j = Integer.parseInt(pos[1]);
String col = colors[i][j]; String col = colors[Integer.parseInt(pos[0])][Integer.parseInt(pos[1])];
String lastLetterString = String.valueOf(col.charAt(col.length()-1)); if(col.endsWith("W")){
button.setOpaque(true); b.setOpaque(true);
button.setContentAreaFilled(true); b.setForeground(Color.BLACK);
button.setBorderPainted(false); b.setContentAreaFilled(true);
button.setFocusPainted(false); b.setBorderPainted(false);
switch(lastLetterString) { b.setFocusPainted(false);
case "W": b.setBackground(Color.lightGray);
button.setForeground(Color.BLACK); colors[i][j] += "G";
button.setBackground(Color.lightGray); String logEntrance = i+"."+j+"."+"G";
break; madeMoves.push(logEntrance);
case "G": }
button.setForeground(Color.WHITE); if(col.endsWith("G")){
button.setBackground(Color.BLACK); b.setOpaque(true);
break; b.setForeground(Color.WHITE);
case "B": b.setContentAreaFilled(true);
button.setForeground(Color.BLACK); b.setBorderPainted(false);
button.setBackground(Color.WHITE); b.setFocusPainted(false);
break; b.setBackground(Color.BLACK);
default: colors[i][j] += "B";
System.exit(0); 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);
} }
colors[i][j] += lastLetterString;
String newMove = i+"."+j+"."+lastLetterString;
madeMoves.push(newMove);
} }
public static void backOneStep(CardLayout cl, JPanel main, Stack<String> movesMade, JButton[][] buttons, String[][] colors, JPanel grid){ public static void backOneStep(CardLayout cl, JPanel main, Stack<String> movesMade, JButton[][] buttons, String[][] colors, JPanel grid){
try {
String move = movesMade.pop(); String move = movesMade.pop();
String[] line = move.split("\\."); String[] line = move.split("\\.");
int i = Integer.parseInt(line[0]); String y = line[0];
int j = Integer.parseInt(line[1]); String x = line[1];
String color = line[2]; String color = line[2];
JButton button = buttons[i][j]; if(color.equals("W")){
button.setOpaque(true); int i = Integer.parseInt(y);
button.setContentAreaFilled(true); int j = Integer.parseInt(x);
button.setBorderPainted(false); JButton b0 = buttons[i][j];
button.setFocusPainted(false); b0.setOpaque(true);
switch(color) { b0.setForeground(Color.WHITE);
case "W": b0.setContentAreaFilled(true);
button.setForeground(Color.WHITE); b0.setBorderPainted(false);
button.setBackground(Color.BLACK); b0.setFocusPainted(false);
break; b0.setBackground(Color.BLACK);
case "G": buttons[i][j] = b0;
button.setForeground(Color.BLACK); String str = colors[i][j];
button.setBackground(Color.WHITE); String str0 = str.substring(0, str.length() - 1);
break; colors[i][j] = str0;
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(); grid.repaint();
gridUpdate(grid, buttons); 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();
}
} }
public static void gridUpdate(JPanel grid, JButton[][] buttons){ public static void gridUpdate(JPanel grid, JButton[][] buttons){
@ -183,8 +218,8 @@ public class GameGUI extends JFrame implements ActionListener {
grid.repaint(); grid.repaint();
for(int i = 0; i<buttons.length; i++){ for(int i = 0; i<buttons.length; i++){
for(int j = 0; j<buttons.length;j++){ for(int j = 0; j<buttons.length;j++){
JButton button = buttons[i][j]; JButton b0 = buttons[i][j];
grid.add(button); grid.add(b0);
grid.repaint(); grid.repaint();
} }
} }
@ -201,21 +236,21 @@ public class GameGUI extends JFrame implements ActionListener {
long minutes = elapsedSeconds % 3600 / 60; long minutes = elapsedSeconds % 3600 / 60;
long seconds = elapsedSeconds % 60; long seconds = elapsedSeconds % 60;
String endtime = String.format("Zeit: %02d:%02d", minutes, seconds); String endtime = String.format("Zeit: %02d:%02d", minutes, seconds);
elapsedSeconds = 0; elapsedSeconds = 0; // Reset so the next start begins at zero
return endtime; return endtime;
} }
public static void finish(CardLayout cl, JPanel main, String endtime, String[] filepath, String path) throws FileNotFoundException{ public static void finish(CardLayout cl, JPanel main, String endtime, String[] filepath, String path) throws FileNotFoundException{
JPanel mainPanel = new JPanel(new BorderLayout()); JPanel mainPanel = new JPanel(new BorderLayout());
JLabel topText = new JLabel("Geben Sie unten Ihren Namen an um sich in der Highscore Liste einzutragen."); JLabel text = new JLabel("Geben Sie unten Ihren Namen an um sich in der Highscore Liste einzutragen.");
mainPanel.add(topText, BorderLayout.NORTH); mainPanel.add(text, BorderLayout.NORTH);
JTextField field = new JTextField(20); JTextField field = new JTextField(20);
mainPanel.add(field, BorderLayout.CENTER); mainPanel.add(field, BorderLayout.CENTER);
JButton addHighscoreButton = new JButton("In der Highscore Liste eintragen"); JButton b = new JButton("In der Highscore Liste eintragen");
mainPanel.add(addHighscoreButton, BorderLayout.SOUTH); mainPanel.add(b, BorderLayout.SOUTH);
mainPanel.setVisible(true); mainPanel.setVisible(true);
mainPanel.setSize(600,600); mainPanel.setSize(600,600);
addHighscoreButton.addActionListener(e -> { b.addActionListener(e -> {
String username = field.getText(); String username = field.getText();
try { try {
LogHighscores.newRecord(path, username, endtime); LogHighscores.newRecord(path, username, endtime);

View File

@ -21,8 +21,7 @@ import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; 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 { public class HighscoreGUI extends JFrame implements ActionListener {
@ -47,11 +46,12 @@ public class HighscoreGUI extends JFrame implements ActionListener {
public HighscoreGUI(CardLayout cl, JPanel main) { public HighscoreGUI(CardLayout cl, JPanel main) {
JPanel highscorePanel = new JPanel(new BorderLayout()); JPanel highscorePanel = new JPanel(new BorderLayout());
JPanel buttonPanel = new JPanel(new GridLayout(7, 1, 10, 10)); JPanel buttonPanel = new JPanel(new GridLayout(7, 1, 10, 10));
for (int i = 0; i < buttons.length; i++) { for (int i = 0; i < buttons.length; i++) {
JButton button = new JButton(buttons[i]); JButton b0 = new JButton(buttons[i]);
buttonPanel.add(button); buttonPanel.add(b0);
final int index = i; final int index = i;
button.addActionListener(e -> { b0.addActionListener(e -> {
String resourcePathInJar = paths[index]; String resourcePathInJar = paths[index];
String localFileName = resourcePathInJar.substring(resourcePathInJar.lastIndexOf('/') + 1); String localFileName = resourcePathInJar.substring(resourcePathInJar.lastIndexOf('/') + 1);
File outFile = new File("resources/Hitori_Highscores", localFileName); File outFile = new File("resources/Hitori_Highscores", localFileName);
@ -59,20 +59,20 @@ public class HighscoreGUI extends JFrame implements ActionListener {
copyResourceIfNotExists(resourcePathInJar, outFile); copyResourceIfNotExists(resourcePathInJar, outFile);
byte[] data = Files.readAllBytes(outFile.toPath()); byte[] data = Files.readAllBytes(outFile.toPath());
showHighscores(cl, main, data, outFile.getPath()); showHighscores(cl, main, data, outFile.getPath());
} catch (IOException e1) { } catch (IOException ex1) {
e1.printStackTrace(); ex1.printStackTrace();
empty(cl, main); empty(cl, main);
} }
}); });
} }
JButton zurückButton = new JButton("Zurück"); JButton b = new JButton("Zurück");
zurückButton.addActionListener(e -> cl.show(main, "HAUPT")); b.addActionListener(e -> cl.show(main, "HAUPT"));
buttonPanel.add(zurückButton); buttonPanel.add(b);
highscorePanel.setVisible(true); highscorePanel.setVisible(true);
highscorePanel.setSize(600, 600); highscorePanel.setSize(600, 600);
highscorePanel.add(buttonPanel, BorderLayout.CENTER); highscorePanel.add(buttonPanel, BorderLayout.CENTER);
JLabel topText = new JLabel("Level für Highscore Liste auswählen!"); JLabel text0 = new JLabel("Level für Highscore Liste auswählen!");
highscorePanel.add(topText, BorderLayout.NORTH); highscorePanel.add(text0, BorderLayout.NORTH);
main.add(highscorePanel, "HIGHSCORES"); main.add(highscorePanel, "HIGHSCORES");
cl.show(main, "HIGHSCORES"); cl.show(main, "HIGHSCORES");
} }
@ -97,19 +97,19 @@ public class HighscoreGUI extends JFrame implements ActionListener {
public static void empty(CardLayout cl, JPanel main) { public static void empty(CardLayout cl, JPanel main) {
JPanel panel = new JPanel(new BorderLayout()); JPanel panel = new JPanel(new BorderLayout());
JButton zurückButton = new JButton("Zurück"); JButton b = new JButton("Zurück");
JLabel topText = new JLabel("Noch kein Highscore eingetragen."); JLabel text = new JLabel("Noch kein Highscore eingetragen.");
panel.add(topText, BorderLayout.CENTER); panel.add(text, BorderLayout.CENTER);
panel.add(zurückButton); panel.add(b, BorderLayout.SOUTH);
zurückButton.addActionListener(e -> cl.show(main, "HIGHSCORES")); b.addActionListener(e -> cl.show(main, "HIGHSCORES"));
main.add(panel, "EMPTY"); main.add(panel, "EMPTY");
cl.show(main, "EMPTY"); cl.show(main, "EMPTY");
} }
public static void showHighscores(CardLayout cl, JPanel main, byte[] data, String filename) throws IOException { public static void showHighscores(CardLayout cl, JPanel main, byte[] data, String filename) throws IOException {
HitoriMain.sortByTime(data, filename); HitoriMain2.sortByTime(data, filename);
data = Files.readAllBytes(new File(filename).toPath()); data = Files.readAllBytes(new File(filename).toPath());
JPanel highscorePanel = new JPanel(new BorderLayout()); JPanel highscorePanel1 = new JPanel(new BorderLayout());
List<String> lines = new ArrayList<>(); List<String> lines = new ArrayList<>();
try (BufferedReader reader = new BufferedReader( try (BufferedReader reader = new BufferedReader(
new InputStreamReader(new ByteArrayInputStream(data), StandardCharsets.UTF_8))) { new InputStreamReader(new ByteArrayInputStream(data), StandardCharsets.UTF_8))) {
@ -120,21 +120,38 @@ public class HighscoreGUI extends JFrame implements ActionListener {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
boolean hasContent = false;
for (String l : lines) {
if (!l.trim().isEmpty()) {
hasContent = true;
break;
}
}
if (hasContent) {
JPanel entryPanel = new JPanel(new GridLayout(lines.size(), 1, 10, 10)); JPanel entryPanel = new JPanel(new GridLayout(lines.size(), 1, 10, 10));
for (String s : lines) { for (String s : lines) {
if (!s.trim().isEmpty()) {
JLabel text = new JLabel(s); JLabel text = new JLabel(s);
entryPanel.add(text); entryPanel.add(text);
} }
highscorePanel.add(entryPanel, BorderLayout.CENTER); }
String avgTime = HitoriMain.getAvgTime(data, filename); highscorePanel1.add(entryPanel, BorderLayout.CENTER);
JLabel avgTimeJLabel = new JLabel(avgTime); JLabel avgTime = HitoriMain2.getAvgTime(data, filename);
highscorePanel.add(avgTimeJLabel, BorderLayout.NORTH); highscorePanel1.add(avgTime, BorderLayout.NORTH);
JButton okButton = new JButton("OK"); } else {
highscorePanel.add(okButton, BorderLayout.SOUTH); JLabel text = new JLabel("Noch kein Highscore eingetragen.");
okButton.addActionListener(e -> cl.show(main, "HIGHSCORES")); highscorePanel1.add(text, BorderLayout.CENTER);
highscorePanel.setVisible(true); }
highscorePanel.setSize(600, 600);
main.add(highscorePanel, "HIGHSCOREEINTRAG"); 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");
cl.show(main, "HIGHSCOREEINTRAG"); cl.show(main, "HIGHSCOREEINTRAG");
} }

View File

@ -12,8 +12,7 @@ import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; 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 { public class MenuGUI extends JFrame implements ActionListener {
@ -41,18 +40,18 @@ public class MenuGUI extends JFrame implements ActionListener {
"/Hitori_Spielfelder/Hitori15x15_medium.csv" "/Hitori_Spielfelder/Hitori15x15_medium.csv"
}; };
for(int i=0;i<buttons.length;i++){ for(int i=0;i<buttons.length;i++){
JButton button = new JButton(buttons[i]); JButton b0 = new JButton(buttons[i]);
buttonPanel.add(button); buttonPanel.add(b0);
int[] count = {i}; int[] count = {i};
String[] num = buttons[i].split("x"); String[] num = buttons[i].split("x");
button.addActionListener(e -> { b0.addActionListener(e -> {
int j = count[0]; int j = count[0];
filepath[0] = paths[j]; filepath[0] = paths[j];
filepath[1] = num[0]; filepath[1] = num[0];
try (InputStream inputStream = getClass().getResourceAsStream(filepath[0])) { try (InputStream inputStream = getClass().getResourceAsStream(filepath[0])) {
if (inputStream != null) { if (inputStream != null) {
String path=filepath[0]; String path=filepath[0];
HitoriMain.ablauf(cl, main, inputStream, Integer.parseInt(filepath[1]), path); HitoriMain2.ablauf(cl, main, inputStream, Integer.parseInt(filepath[1]), path);
} else { } else {
throw new FileNotFoundException("Resource not found: " + filepath[0]); throw new FileNotFoundException("Resource not found: " + filepath[0]);
} }
@ -61,14 +60,14 @@ public class MenuGUI extends JFrame implements ActionListener {
} }
}); });
} }
JButton highscoreButton = new JButton("Highscores"); JButton b = new JButton("Highscores");
highscoreButton.addActionListener(e -> { b.addActionListener(e -> {
new HighscoreGUI(cl, main); new HighscoreGUI(cl, main);
}); });
buttonPanel.add(highscoreButton); buttonPanel.add(b);
menuPanel.add(buttonPanel, BorderLayout.CENTER); menuPanel.add(buttonPanel, BorderLayout.CENTER);
JLabel topText = new JLabel("Wählen Sie ein Level aus!"); JLabel text0 = new JLabel("Wählen Sie ein Level aus!");
menuPanel.add(topText, BorderLayout.NORTH); menuPanel.add(text0, BorderLayout.NORTH);
setVisible(true); setVisible(true);
setSize(600, 600); setSize(600, 600);
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);

View File

@ -1,13 +1,16 @@
package de.hs_mannheim.informatik.mvn.test; 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 static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import de.hs_mannheim.informatik.mvn.domain.HitoriMain; import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
import de.hs_mannheim.informatik.mvn.gui.GameGUI; import de.hs_mannheim.informatik.mvn.gui.GameGUI;
class HitoriTest{ class HitoriTest{
@ -19,7 +22,7 @@ class HitoriTest{
{"W", "W", "W"}, {"W", "W", "W"},
{"W", "W", "W"} {"W", "W", "W"}
}; };
assertTrue(Arrays.deepEquals(array3x3, HitoriMain.makeColorArray(3))); assertTrue(Arrays.deepEquals(array3x3, HitoriMain2.makeColorArray(3)));
} }
@Test @Test
@ -28,7 +31,7 @@ class HitoriTest{
{"W", "W", "W"}, {"W", "W", "W"},
{"W", "W", "W"}, {"W", "W", "W"},
}; };
assertFalse(Arrays.deepEquals(array3x2, HitoriMain.makeColorArray(3))); assertFalse(Arrays.deepEquals(array3x2, HitoriMain2.makeColorArray(3)));
} }
@Test @Test
@ -48,7 +51,7 @@ class HitoriTest{
{"W", "W", "W", "B"}, {"W", "W", "W", "B"},
{"W", "B", "W", "W"}, {"W", "B", "W", "W"},
{"B", "W", "W", "B"}}; {"B", "W", "W", "B"}};
assertFalse(HitoriMain.checkArraySame(data, colors)); assertFalse(HitoriMain2.checkArraySame(data, colors));
} }
@Test @Test
@ -64,7 +67,7 @@ class HitoriTest{
{"W", "B", "W", "W"}, {"W", "B", "W", "W"},
{"B", "W", "W", "B"}}; {"B", "W", "W", "B"}};
assertTrue(HitoriMain.checkArraySame(data, colors)); assertTrue(HitoriMain2.checkArraySame(data, colors));
} }
@Test @Test
@ -81,7 +84,7 @@ class HitoriTest{
{"W", "B", "W", "W", "W"}, {"W", "B", "W", "W", "W"},
{"W", "B", "W", "W", "W"}, {"W", "B", "W", "W", "W"},
{"W", "B", "W", "W", "W"}}; {"W", "B", "W", "W", "W"}};
assertFalse(HitoriMain.checkArraySame(data, colors)); assertFalse(HitoriMain2.checkArraySame(data, colors));
} }
@Test @Test
@ -98,19 +101,19 @@ class HitoriTest{
{"B", "W", "W", "B", "W"}, {"B", "W", "W", "B", "W"},
{"W", "W", "B", "W", "W"}, {"W", "W", "B", "W", "W"},
{"B", "W", "W", "W", "B"}}; {"B", "W", "W", "W", "B"}};
assertTrue(HitoriMain.checkArraySame(data, colors)); assertTrue(HitoriMain2.checkArraySame(data, colors));
} }
@Test @Test
void getCordsTest1() { void getCordsTest1() {
String[] array = {"3", "4"}; String[] array = {"3", "4"};
assertFalse(Arrays.deepEquals(array, HitoriMain.getCords(3, 3))); assertFalse(Arrays.deepEquals(array, HitoriMain2.getCords(3, 3)));
} }
@Test @Test
void getCordsTest2() { void getCordsTest2() {
String[] array = {"3", "4"}; String[] array = {"3", "4"};
assertTrue(Arrays.deepEquals(array, HitoriMain.getCords(3, 4))); assertTrue(Arrays.deepEquals(array, HitoriMain2.getCords(3, 4)));
} }
@Test @Test
@ -137,7 +140,7 @@ class HitoriTest{
{"B", "W", "B", "W", "W", "B", "W", "W", "W", "W"}, {"B", "W", "B", "W", "W", "B", "W", "W", "W", "W"},
{"W", "W", "W", "B", "W", "W", "B", "W", "B", "W"}, {"W", "W", "W", "B", "W", "W", "B", "W", "B", "W"},
{"B", "W", "B", "W", "W", "W", "W", "W", "W", "B"}}; {"B", "W", "B", "W", "W", "W", "W", "W", "W", "B"}};
assertTrue(HitoriMain.checkArraySame(data, colors)); assertTrue(HitoriMain2.checkArraySame(data, colors));
} }
@Test @Test
@ -164,7 +167,7 @@ class HitoriTest{
{"B", "W", "B", "W", "W", "B", "W", "W", "W", "W"}, {"B", "W", "B", "W", "W", "B", "W", "W", "W", "W"},
{"W", "W", "W", "B", "W", "W", "B", "W", "B", "W"}, {"W", "W", "W", "B", "W", "W", "B", "W", "B", "W"},
{"B", "W", "B", "W", "W", "W", "W", "W", "W", "W"}}; {"B", "W", "B", "W", "W", "W", "W", "W", "W", "W"}};
assertFalse(HitoriMain.checkArraySame(data, colors)); assertFalse(HitoriMain2.checkArraySame(data, colors));
} }
@Test @Test
@ -184,7 +187,7 @@ class HitoriTest{
{"W", "B", "W", "W"}, {"W", "B", "W", "W"},
{"B", "W", "W", "B"}, {"B", "W", "W", "B"},
{"W", "W", "B", "W"}}; {"W", "W", "B", "W"}};
assertTrue(Arrays.deepEquals(array, HitoriMain.getResult(data, colors))); assertTrue(Arrays.deepEquals(array, HitoriMain2.getResult(data, colors)));
} }
@Test @Test
@ -204,7 +207,7 @@ class HitoriTest{
{"G", "B", "W", "W"}, {"G", "B", "W", "W"},
{"B", "W", "W", "B"}, {"B", "W", "W", "B"},
{"W", "W", "B", "W"}}; {"W", "W", "B", "W"}};
assertFalse(Arrays.deepEquals(array, HitoriMain.getResult(data, colors))); assertFalse(Arrays.deepEquals(array, HitoriMain2.getResult(data, colors)));
} }
@Test @Test
@ -212,7 +215,7 @@ class HitoriTest{
String[] ergebnis4x4 = {"0,1", "1,3", "2,1", "3,0", "3,3"}; String[] ergebnis4x4 = {"0,1", "1,3", "2,1", "3,0", "3,3"};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
ArrayList<String> filteredData = HitoriMain.getSolution(inputStream); ArrayList<String> filteredData = HitoriMain2.getSolution(inputStream);
assertEquals(5, filteredData.size()); assertEquals(5, filteredData.size());
assertEquals(ergebnis4x4[0], filteredData.get(0)); assertEquals(ergebnis4x4[0], filteredData.get(0));
assertEquals(ergebnis4x4[1], filteredData.get(1)); assertEquals(ergebnis4x4[1], filteredData.get(1));
@ -226,7 +229,7 @@ class HitoriTest{
String[] ergebnis4x4 = {"0,0"}; String[] ergebnis4x4 = {"0,0"};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
ArrayList<String> filteredData = HitoriMain.getSolution(inputStream); ArrayList<String> filteredData = HitoriMain2.getSolution(inputStream);
assertNotEquals(1, filteredData.size()); assertNotEquals(1, filteredData.size());
assertNotEquals(ergebnis4x4[0], filteredData.get(0)); assertNotEquals(ergebnis4x4[0], filteredData.get(0));
assertNotEquals(ergebnis4x4[0], filteredData.get(1)); assertNotEquals(ergebnis4x4[0], filteredData.get(1));
@ -236,23 +239,23 @@ class HitoriTest{
} }
@Test @Test
void makeColorArrayTest3() { void makeColorArrayTest1() {
String[][] colors = { String[][] colors = {
{"W", "W", "W", "W"}, {"W", "W", "W", "W"},
{"W", "W", "W", "W"}, {"W", "W", "W", "W"},
{"W", "W", "W", "W"}, {"W", "W", "W", "W"},
{"W", "W", "W", "W"}}; {"W", "W", "W", "W"}};
assertTrue(Arrays.deepEquals(colors, HitoriMain.makeColorArray(4))); assertTrue(Arrays.deepEquals(colors, HitoriMain2.makeColorArray(4)));
} }
@Test @Test
void makeColorArrayTest4() { void makeColorArrayTest2() {
String[][] colors = { String[][] colors = {
{"B", "W", "W", "W"}, {"B", "W", "W", "W"},
{"B", "W", "W", "W"}, {"B", "W", "W", "W"},
{"B", "W", "W", "W"}, {"B", "W", "W", "W"},
{"B", "W", "W", "W"}}; {"B", "W", "W", "W"}};
assertFalse(Arrays.deepEquals(colors, HitoriMain.makeColorArray(4))); assertFalse(Arrays.deepEquals(colors, HitoriMain2.makeColorArray(4)));
} }
@Test @Test
@ -264,7 +267,7 @@ class HitoriTest{
{"3", "4", "3", "2"}}; {"3", "4", "3", "2"}};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
assertTrue(Arrays.deepEquals(data, HitoriMain.getData(inputStream, 4))); assertTrue(Arrays.deepEquals(data, HitoriMain2.getData(inputStream, 4)));
} }
@Test @Test
@ -276,7 +279,7 @@ class HitoriTest{
{"3", "0", "3", "2"}}; {"3", "0", "3", "2"}};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
assertFalse(Arrays.deepEquals(data, HitoriMain.getData(inputStream, 4))); assertFalse(Arrays.deepEquals(data, HitoriMain2.getData(inputStream, 4)));
} }
@Test @Test
@ -299,7 +302,7 @@ class HitoriTest{
} }
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
ArrayList<String> ergebnisList = HitoriMain.readFromFile(inputStream); ArrayList<String> ergebnisList = HitoriMain2.readFromFile(inputStream);
assertEquals(fileEntry, ergebnisList); assertEquals(fileEntry, ergebnisList);
} }
@ -323,51 +326,11 @@ class HitoriTest{
} }
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
ArrayList<String> ergebnisList = HitoriMain.readFromFile(inputStream); ArrayList<String> ergebnisList = HitoriMain2.readFromFile(inputStream);
assertNotEquals(fileEntry, ergebnisList); assertNotEquals(fileEntry, ergebnisList);
} }
@Test
void test22() 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<String> 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 test23() 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<String> 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)));
}
@Test
void test24() throws IOException {
}
@Test
void test25() throws IOException {
}
@Test @Test
void getErgebnisArrayTest1() throws IOException { void getErgebnisArrayTest1() throws IOException {
@ -378,11 +341,11 @@ class HitoriTest{
{"B", "W", "W", "B"}}; {"B", "W", "W", "B"}};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
ArrayList<String> filteredData = HitoriMain.getSolution(inputStream); ArrayList<String> filteredData = HitoriMain2.getSolution(inputStream);
InputStream newStream = getClass().getResourceAsStream(path); InputStream newStream = getClass().getResourceAsStream(path);
int rows = 4; int rows = 4;
String[][] data = HitoriMain.getData(newStream, rows); String[][] data = HitoriMain2.getData(newStream, rows);
assertTrue(Arrays.deepEquals(ergebnis1, HitoriMain.getErgebnisArray(data, filteredData))); assertTrue(Arrays.deepEquals(ergebnis1, HitoriMain2.getErgebnisArray(data, filteredData)));
} }
@ -395,11 +358,11 @@ class HitoriTest{
{"W", "W", "W", "W"}}; {"W", "W", "W", "W"}};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
ArrayList<String> filteredData = HitoriMain.getSolution(inputStream); ArrayList<String> filteredData = HitoriMain2.getSolution(inputStream);
InputStream newStream = getClass().getResourceAsStream(path); InputStream newStream = getClass().getResourceAsStream(path);
int rows = 4; int rows = 4;
String[][] data = HitoriMain.getData(newStream, rows); String[][] data = HitoriMain2.getData(newStream, rows);
assertFalse(Arrays.deepEquals(ergebnis1, HitoriMain.getErgebnisArray(data, filteredData))); assertFalse(Arrays.deepEquals(ergebnis1, HitoriMain2.getErgebnisArray(data, filteredData)));
} }
} }