Compare commits
52 Commits
domainBran
...
main
| Author | SHA1 | Date |
|---|---|---|
|
|
a4efd0a563 | |
|
|
76021dbe7f | |
|
|
5265f0f085 | |
|
|
4d23a86eca | |
|
|
785ed0f459 | |
|
|
a77ef30fcd | |
|
|
b760cd4982 | |
|
|
df2947faef | |
|
|
22af3815ad | |
|
|
47779b0b60 | |
|
|
1912b74034 | |
|
|
a45a306cb9 | |
|
|
fda2097eea | |
|
|
9558edfc9d | |
|
|
529b892f4c | |
|
|
aa9e5a3620 | |
|
|
4ae7dab07f | |
|
|
e131950044 | |
|
|
da1104718f | |
|
|
b4d3ee05d6 | |
|
|
9625a02631 | |
|
|
f4de80f801 | |
|
|
39f106f1bd | |
|
|
b1d744e10f | |
|
|
7e47bca18c | |
|
|
b2d94176da | |
|
|
a7eab9a0b3 | |
|
|
15dab1e2b2 | |
|
|
b4a7429374 | |
|
|
fc875a069c | |
|
|
12c0c1fa30 | |
|
|
598c6ae7e7 | |
|
|
d3cb2550ce | |
|
|
fa7718f668 | |
|
|
a0cc6306e4 | |
|
|
567f7f13a3 | |
|
|
f63e15985f | |
|
|
e873e54073 | |
|
|
18d440bdbc | |
|
|
19fe8fee34 | |
|
|
75ff9c92a3 | |
|
|
181f68c485 | |
|
|
f140fb5905 | |
|
|
214dc0e286 | |
|
|
593ae9901a | |
|
|
8171a410cc | |
|
|
8dcb29d701 | |
|
|
6a505ef34d | |
|
|
1e640026f7 | |
|
|
cf38b86df1 | |
|
|
2aaac10f48 | |
|
|
093c9bf601 |
11
.project
11
.project
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>PR2Projekt</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
/target/
|
||||
/.DS_Store
|
||||
/.classpath
|
||||
/.project
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>PR2Gruppenprojekt</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 245 KiB |
|
|
@ -0,0 +1,141 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.hs_mannheim.informatik</groupId>
|
||||
<artifactId>Hitori</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.24.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.24.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Compiler -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- JAR creation -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>de.hs_mannheim.informatik.main.Main</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Code coverage, cf.: target/site/jacoco -->
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.12</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>report</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Static code analysis, cf: target/site/pmd.html -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-pmd-plugin</artifactId>
|
||||
<version>3.26.0</version>
|
||||
<configuration>
|
||||
<failOnViolation>false</failOnViolation>
|
||||
<printFailingErrors>true</printFailingErrors>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/test/java</directory>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<testSourceDirectory>src/test/java</testSourceDirectory>
|
||||
</build>
|
||||
<reporting>
|
||||
<plugins>
|
||||
<!-- generate Javadocs via "mvn site" and find them in the site
|
||||
folder -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.11.2</version>
|
||||
<configuration>
|
||||
<show>private</show>
|
||||
<nohelp>true</nohelp>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
</project>
|
||||
|
|
@ -1,231 +0,0 @@
|
|||
package de.hs_mannheim.informatik.pr2projekt.domain;
|
||||
|
||||
public class HitoriMain extends JFrame implements AcrtionListener{
|
||||
|
||||
private static String[] filepath = new String[2];
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException{
|
||||
filepath[0] = "";
|
||||
filepath[1] = "";
|
||||
new HitoriMain();
|
||||
}
|
||||
|
||||
public HitoriMain() throws FileNotFoundException {
|
||||
Stack<String> madeMoves = new Stack<>();
|
||||
MenuGUI.getPath(filepath);
|
||||
int i = 0;
|
||||
while(filepath[0].equals("")){
|
||||
System.out.println();
|
||||
}
|
||||
String[][] data = getData(filepath[0], Integer.parseInt(filepath[1]));
|
||||
String[][] colors = makeColorArray(data.length);
|
||||
JButton[][] buttons = makeButtonArray(data);
|
||||
GameGUI.paintGame(buttons, colors, madeMoves, data);
|
||||
}
|
||||
|
||||
public static ArrayList<String> readFromFile(String path){
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
lines.add(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
public static String[][] getData(String filepath, int rows) throws FileNotFoundException{
|
||||
String filepath0 = filepath;
|
||||
Scanner sc = new Scanner(new File(filepath0));
|
||||
String[][] data = new String[rows][rows];
|
||||
int rowInt = 0;
|
||||
while (sc.hasNextLine() && rowInt < rows) {
|
||||
String line = sc.nextLine();
|
||||
data[rowInt] = line.split(",");
|
||||
rowInt++;
|
||||
}
|
||||
sc.close();
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
public static String[][] makeColorArray(int size){
|
||||
String[][] colors = new String[size][size];
|
||||
for(int i=0;i<size;i++){
|
||||
for(int j=0;j<size;j++){
|
||||
colors[i][j] = "W";
|
||||
}
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
public static JButton[][] makeButtonArray(String[][] data){
|
||||
JButton[][] buttons = new JButton[data.length][data.length];
|
||||
for(int i=0;i<data.length;i++){
|
||||
for(int j=0;j<data.length;j++){
|
||||
String number = data[i][j];
|
||||
JButton b0 = new JButton(number);
|
||||
buttons[i][j] = b0;
|
||||
}
|
||||
}
|
||||
return buttons;
|
||||
}
|
||||
|
||||
public static boolean abgabeMöglich(String path, String[][] data, String[][] colors) throws FileNotFoundException{
|
||||
boolean abgabeMöglich = false;
|
||||
String[][] result = getResult(data, colors);
|
||||
ArrayList<String> filteredData = getSolution(path, result);
|
||||
String[][] ergebnis1 = getErgebnisArray(result, filteredData);
|
||||
|
||||
int count = 0;
|
||||
for(int i=0;i<result.length;i++){
|
||||
for(int j=0;j<result.length;j++){
|
||||
if(result[i][j].equals(ergebnis1[i][j])){
|
||||
} else {
|
||||
count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(count <0){
|
||||
abgabeMöglich = false;
|
||||
} else {
|
||||
abgabeMöglich = true;
|
||||
}
|
||||
return abgabeMöglich;
|
||||
}
|
||||
|
||||
public static String[] getCords(int i, int j){
|
||||
String yKoordinate = String.valueOf(i);
|
||||
String xKoordinate = String.valueOf(j);
|
||||
String[] pos = {yKoordinate, xKoordinate};
|
||||
return pos;
|
||||
}
|
||||
|
||||
public static void backOneStep(Stack<String> movesMade, JButton[][] buttons, String[][] colors, JPanel grid){
|
||||
try {
|
||||
String move = movesMade.pop();
|
||||
String[] line = move.split("\\.");
|
||||
String y = line[0];
|
||||
String x = 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) {}
|
||||
}
|
||||
|
||||
public static void totalResetButton(JButton[][] buttons, String[][] colors,Stack<String> madeMoves,String[][] data){
|
||||
madeMoves.clear();
|
||||
for(int i = 0; i<data.length;i++){
|
||||
for(int j = 0; j<data.length;j++){
|
||||
colors[i][j] = "W";
|
||||
buttons[i][j] = null;
|
||||
}
|
||||
JButton[][] buttons0 = makeButtonArray(data);
|
||||
GameGUI.paintGame(buttons0, colors, madeMoves, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static String[][] getResult(String[][] data, String[][] colors){
|
||||
String[][] result = new String[data.length][data.length];
|
||||
for(int i=0;i<data.length;i++){
|
||||
for(int j=0;j<data.length;j++){
|
||||
String farben = colors[i][j];
|
||||
String lastColor = String.valueOf(farben.charAt(farben.length() - 1));
|
||||
if(lastColor.equals("G")){
|
||||
lastColor = "W";
|
||||
}
|
||||
result[i][j] = lastColor;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getSolution(String path, String[][] result) throws FileNotFoundException{
|
||||
Scanner sc = new Scanner(new File(path));
|
||||
ArrayList<String> filteredData = new ArrayList<>();
|
||||
boolean isUnderComment = false;
|
||||
while (sc.hasNextLine()) {
|
||||
String line = sc.nextLine().trim();
|
||||
if (line.equals("//Lösung (schwarze Felder)")) {
|
||||
isUnderComment = true;
|
||||
continue;
|
||||
}
|
||||
if (isUnderComment && !line.isEmpty()) {
|
||||
String[] lineArray = line.split(",");
|
||||
int num1 = Integer.parseInt(lineArray[0]);
|
||||
int num2 = Integer.parseInt(lineArray[1]);
|
||||
String newNum1 = String.valueOf(num1-1);
|
||||
String newNum2 = String.valueOf(num2-1);
|
||||
String newLine = newNum1+","+newNum2;
|
||||
filteredData.add(newLine);
|
||||
}
|
||||
}
|
||||
sc.close();
|
||||
return filteredData;
|
||||
}
|
||||
|
||||
public static String[][] getErgebnisArray(String[][] result, ArrayList<String> filteredData){
|
||||
String[][] ergebnis = new String[result.length][result.length];
|
||||
for(int i=0;i<result.length;i++){
|
||||
for(int j=0;j<result.length;j++){
|
||||
ergebnis[i][j] = "W";
|
||||
}
|
||||
}
|
||||
for (String index : filteredData) {
|
||||
String[] parts = index.split(",");
|
||||
int row = Integer.parseInt(parts[0].trim());
|
||||
int col = Integer.parseInt(parts[1].trim());
|
||||
if (row >= 0 && row < ergebnis.length && col >= 0 && col < ergebnis[row].length) {
|
||||
ergebnis[row][col] = "B";
|
||||
}
|
||||
}
|
||||
return ergebnis;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package de.hs_mannheim.informatik.pr2projekt.gui;
|
||||
|
||||
public class GameGUI {
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package de.hs_mannheim.informatik.pr2projekt.gui;
|
||||
|
||||
public class HighscoreGUI {
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package de.hs_mannheim.informatik.pr2projekt.gui;
|
||||
|
||||
public class MenuGUI {
|
||||
//ABC
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package de.hs_mannheim.informatik.domain;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CSVReader {
|
||||
|
||||
public ArrayList<String> readFromFile(InputStream inputStream){
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
lines.add(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.getMessage();
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
public ArrayList<String> getSolution(InputStream inputStream) throws FileNotFoundException{
|
||||
ArrayList<String> filteredData = new ArrayList<>();
|
||||
boolean isUnderComment = false;
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if (line.equals("//Lösung (schwarze Felder)")) {
|
||||
isUnderComment = true;
|
||||
continue;
|
||||
}
|
||||
if (isUnderComment && !line.isEmpty()) {
|
||||
String[] lineArray = line.split(",");
|
||||
int firstNumn = Integer.parseInt(lineArray[0]);
|
||||
int secondNum = Integer.parseInt(lineArray[1]);
|
||||
String firstNumAsString = String.valueOf(firstNumn - 1);
|
||||
String secondNumAsString = String.valueOf(secondNum - 1);
|
||||
String newLine = firstNumAsString + "," + secondNumAsString;
|
||||
filteredData.add(newLine);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.getMessage();
|
||||
}
|
||||
return filteredData;
|
||||
}
|
||||
|
||||
public String[][] getData(InputStream inputStream, int rows) throws FileNotFoundException{
|
||||
String[][] data = new String[rows][rows];
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String line;
|
||||
int rowInt = 0;
|
||||
while ((line = reader.readLine()) != null && rowInt < rows) {
|
||||
data[rowInt] = line.split(",");
|
||||
rowInt++;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package de.hs_mannheim.informatik.domain;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class FieldDataResult {
|
||||
private final String[][] data;
|
||||
private final String[][] colors;
|
||||
private final InputStream gameStream;
|
||||
|
||||
public FieldDataResult(String[][] data, String[][] colors, InputStream gameStream) {
|
||||
this.data = data;
|
||||
this.colors = colors;
|
||||
this.gameStream = gameStream;
|
||||
}
|
||||
|
||||
public String[][] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public String[][] getColors() {
|
||||
return colors;
|
||||
}
|
||||
|
||||
public InputStream getGameStream() {
|
||||
return gameStream;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package de.hs_mannheim.informatik.domain;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Stack;
|
||||
import de.hs_mannheim.informatik.facade.HitoriAPI;
|
||||
|
||||
public class GameBoard {
|
||||
|
||||
public FieldDataResult initializeFieldData(byte[] gameData, int rows, Stack<String> madeMoves, String path) throws IOException {
|
||||
InputStream newStream = new ByteArrayInputStream(gameData);
|
||||
String[][] data = new CSVReader().getData(newStream, rows);
|
||||
System.out.println(data.length + " FNABLKJFABW");
|
||||
String[][] colors = new HitoriLogic().makeColorArray(data.length);
|
||||
InputStream gameStream = new ByteArrayInputStream(gameData);
|
||||
return new FieldDataResult(data, colors, gameStream);
|
||||
}
|
||||
|
||||
public String[] getGameButtonNames() {
|
||||
String[] buttonNames = {
|
||||
"4x4 - leicht",
|
||||
"5x5 - leicht",
|
||||
"8x8 - leicht",
|
||||
"8x8 - medium",
|
||||
"10x10 - medium",
|
||||
"15x15 - medium"
|
||||
};
|
||||
return buttonNames;
|
||||
}
|
||||
|
||||
public String[] getGamePath() {
|
||||
String[] buttonPaths = {
|
||||
"/Hitori_Spielfelder/Hitori4x4_leicht.csv",
|
||||
"/Hitori_Spielfelder/Hitori5x5leicht.csv",
|
||||
"/Hitori_Spielfelder/Hitori8x8leicht.csv",
|
||||
"/Hitori_Spielfelder/Hitori8x8medium.csv",
|
||||
"/Hitori_Spielfelder/Hitori10x10medium.csv",
|
||||
"/Hitori_Spielfelder/Hitori15x15_medium.csv"
|
||||
};
|
||||
return buttonPaths;
|
||||
}
|
||||
|
||||
public String[] getHighscorePathNames() {
|
||||
String[] buttonPaths = {
|
||||
"resources/Hitori_Highscores/Hitori4x4_leicht.txt",
|
||||
"resources/Hitori_Highscores/Hitori5x5leicht.txt",
|
||||
"resources/Hitori_Highscores/Hitori8x8leicht.txt",
|
||||
"resources/Hitori_Highscores/Hitori8x8medium.txt",
|
||||
"resources/Hitori_Highscores/Hitori10x10medium.txt",
|
||||
"resources/Hitori_Highscores/Hitori15x15_medium.txt"
|
||||
};
|
||||
return buttonPaths;
|
||||
}
|
||||
|
||||
public String[] getHighscoreButtonNames() {
|
||||
String[] buttonNames = {
|
||||
"Highscore 4x4 - leicht",
|
||||
"Highscore 5x5 - leicht",
|
||||
"Highscore 8x8 - leicht",
|
||||
"Highscore 8x8 - medium",
|
||||
"Highscore 10x10 - medium",
|
||||
"Highscore 15x15 - medium"
|
||||
};
|
||||
return buttonNames;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package de.hs_mannheim.informatik.domain;
|
||||
|
||||
import java.time.LocalTime;
|
||||
|
||||
public class HighscoreEintrag {
|
||||
LocalTime time;
|
||||
String name;
|
||||
|
||||
public HighscoreEintrag(LocalTime time, String name) {
|
||||
this.time = time;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public LocalTime getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
package de.hs_mannheim.informatik.domain;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.DateTimeException;
|
||||
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.Comparator;
|
||||
|
||||
import de.hs_mannheim.informatik.gui.HighscoreMenuGUI;
|
||||
|
||||
public class HighscoreManager {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new HighscoreManager();
|
||||
}
|
||||
|
||||
public void sortByTime(byte[] data, String filename) throws IOException {
|
||||
ArrayList<HighscoreEintrag> highscores = new ArrayList<>();
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(new ByteArrayInputStream(data), StandardCharsets.UTF_8))) {
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
try {
|
||||
String[] parts = line.split(" ", 2);
|
||||
String timeStr = parts[0];
|
||||
String name = (parts.length > 1) ? parts[1].trim() : "";
|
||||
String[] timeParts = timeStr.split(":");
|
||||
if (timeParts.length != 2) {
|
||||
System.err.println("Invalid time format: " + timeStr);
|
||||
continue;
|
||||
}
|
||||
int hour = Integer.parseInt(timeParts[0]);
|
||||
int minute = Integer.parseInt(timeParts[1]);
|
||||
|
||||
if (hour < 0 || hour > 23 || minute < 0 || minute > 59) {
|
||||
System.err.println("Invalid time values: " + timeStr);
|
||||
continue;
|
||||
}
|
||||
LocalTime time = LocalTime.of(hour, minute);
|
||||
highscores.add(new HighscoreEintrag(time, name));
|
||||
} catch (NumberFormatException | DateTimeException ex) {
|
||||
System.err.println("Error parsing line: " + line);
|
||||
System.err.println("Error details: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
highscores.sort(Comparator.comparing(HighscoreEintrag::getTime));
|
||||
ArrayList<String> formattedHighscores = new ArrayList<>();
|
||||
for (HighscoreEintrag e : highscores) {
|
||||
String formattedTime = String.format("%02d:%02d", e.getTime().getHour(), e.getTime().getMinute());
|
||||
String line = formattedTime + " " + e.getName();
|
||||
formattedHighscores.add(line);
|
||||
}
|
||||
String fileName = filename.substring(filename.lastIndexOf('/') + 1);
|
||||
File file = new File(fileName);
|
||||
overwriteContentOfFile(formattedHighscores, file);
|
||||
}
|
||||
|
||||
private void overwriteContentOfFile(ArrayList<String> formattedHighscores, File file) throws FileNotFoundException, IOException {
|
||||
try (BufferedWriter writer = new BufferedWriter(
|
||||
new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) {
|
||||
for (String entry : formattedHighscores) {
|
||||
writer.write(entry);
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public 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")
|
||||
.parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
|
||||
.toFormatter();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if (line.isEmpty()) continue;
|
||||
String[] parts = line.split("\\s+", 2);
|
||||
String timePart = parts[0];
|
||||
LocalTime localTime = LocalTime.parse(timePart, dtf);
|
||||
int minutes = localTime.getMinute();
|
||||
int seconds = localTime.getSecond();
|
||||
int totalSecThisLine = minutes * 60 + seconds;
|
||||
totalSeconds += totalSecThisLine;
|
||||
count++;
|
||||
}
|
||||
int timeInt = totalSeconds/count;
|
||||
int minutes = timeInt/60;
|
||||
int seconds = timeInt%60;
|
||||
String timeString= "Durchschnittszeit: " + minutes+":"+seconds;
|
||||
return timeString;
|
||||
}
|
||||
}
|
||||
|
||||
public void copyResourceIfNotExists(String resourcePathInJar, File outFile) throws IOException {
|
||||
if (outFile.exists()) {
|
||||
return;
|
||||
}
|
||||
outFile.getParentFile().mkdirs();
|
||||
try (InputStream in = HighscoreMenuGUI.class.getResourceAsStream(resourcePathInJar);
|
||||
FileOutputStream fos = new FileOutputStream(outFile)) {
|
||||
if (in == null) {
|
||||
throw new FileNotFoundException("Resource not found in JAR: " + resourcePathInJar);
|
||||
}
|
||||
byte[] buffer = new byte[4096];
|
||||
int bytesRead;
|
||||
while ((bytesRead = in.read(buffer)) != -1) {
|
||||
fos.write(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package de.hs_mannheim.informatik.domain;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import java.io.*;
|
||||
|
||||
public class Highscores {
|
||||
private static final Logger logger = LogManager.getLogger(Highscores.class);
|
||||
|
||||
public static void newRecord(String resourcePath, String username, String time) throws IOException {
|
||||
String timePart = time.substring("Zeit: ".length()).trim();
|
||||
String[] parts = resourcePath.split("/");
|
||||
String jarFileName = parts[parts.length - 1];
|
||||
String newName = jarFileName.replace(".csv", ".txt");
|
||||
|
||||
File localFolder = new File("resources/Hitori_Highscores");
|
||||
if (!localFolder.exists() && !localFolder.mkdirs()) {
|
||||
logger.error("Failed to create output folder: {}", localFolder.getAbsolutePath());
|
||||
throw new IOException("Failed to create output folder: " + localFolder);
|
||||
}
|
||||
|
||||
File localFile = new File(localFolder, newName);
|
||||
|
||||
try (InputStream inputStream = Highscores.class.getResourceAsStream(resourcePath)) {
|
||||
if (inputStream == null) {
|
||||
logger.warn("Resource not found in JAR: {}", resourcePath);
|
||||
} else {
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
logger.debug("Existing JAR record: {}", line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String entry = timePart + " " + username;
|
||||
logger.info("Adding new record: {} to file: {}", entry, localFile.getAbsolutePath());
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(localFile, true))) {
|
||||
writer.write(entry);
|
||||
writer.newLine();
|
||||
} catch (IOException e) {
|
||||
logger.error("Error handling local highscore file: {}", localFile.getAbsolutePath(), e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
package de.hs_mannheim.informatik.domain;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Stack;
|
||||
|
||||
public class HitoriLogic {
|
||||
|
||||
public String[][] makeColorArray(int size){
|
||||
String[][] colors = new String[size][size];
|
||||
for(int i=0;i<size;i++){
|
||||
for(int j=0;j<size;j++){
|
||||
colors[i][j] = "W";
|
||||
}
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
public boolean checkArraySame(String[][] ergebnis,String[][] result){
|
||||
if(Arrays.deepEquals(ergebnis, result)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean abgabeMöglich(InputStream inputStream, String[][] data, String[][] colors) throws FileNotFoundException{
|
||||
String[][] result = getResult(data, colors);
|
||||
ArrayList<String> filteredData = new CSVReader().getSolution(inputStream);
|
||||
String[][] ergebnis = getErgebnisArray(result, filteredData);
|
||||
boolean abgabeMöglich = checkArraySame(result, ergebnis);
|
||||
return abgabeMöglich;
|
||||
}
|
||||
|
||||
public void addMove(String[][] colors, int i, int j, String lastLetterString, Stack<String> madeMoves){
|
||||
colors[i][j] += lastLetterString;
|
||||
String newMove = i+"."+j+"."+lastLetterString;
|
||||
madeMoves.push(newMove);
|
||||
}
|
||||
|
||||
public String[] getCords(int i, int j){
|
||||
String yKoordinate = String.valueOf(i);
|
||||
String xKoordinate = String.valueOf(j);
|
||||
String[] position = {yKoordinate, xKoordinate};
|
||||
return position;
|
||||
}
|
||||
|
||||
public String[][] getResult(String[][] data, String[][] colors){
|
||||
String[][] result = new String[data.length][data.length];
|
||||
for(int i=0;i<data.length;i++){
|
||||
for(int j=0;j<data.length;j++){
|
||||
String farben = colors[i][j];
|
||||
String lastColor = String.valueOf(farben.charAt(farben.length() - 1));
|
||||
if(lastColor.equals("G")){
|
||||
lastColor = "W";
|
||||
}
|
||||
result[i][j] = lastColor;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String[][] getErgebnisArray(String[][] result, ArrayList<String> filteredData){
|
||||
String[][] ergebnis = new String[result.length][result.length];
|
||||
for(int i=0;i<result.length;i++){
|
||||
for(int j=0;j<result.length;j++){
|
||||
ergebnis[i][j] = "W";
|
||||
}
|
||||
}
|
||||
for (String index : filteredData) {
|
||||
String[] parts = index.split(",");
|
||||
int row = Integer.parseInt(parts[0].trim());
|
||||
int col = Integer.parseInt(parts[1].trim());
|
||||
if (row >= 0 && row < ergebnis.length && col >= 0 && col < ergebnis[row].length) {
|
||||
ergebnis[row][col] = "B";
|
||||
}
|
||||
}
|
||||
return ergebnis;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
package de.hs_mannheim.informatik.facade;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Stack;
|
||||
import de.hs_mannheim.informatik.domain.*;
|
||||
|
||||
public class HitoriAPI {
|
||||
|
||||
public static String[] getCordsCatcher(int i, int j) {
|
||||
String[] pos = new HitoriLogic().getCords(i,j);
|
||||
return pos;
|
||||
}
|
||||
|
||||
public boolean abgabeMöglichCatcher(InputStream newStream, String[][] data, String[][] colors) throws FileNotFoundException {
|
||||
boolean abgabeMöglich = new HitoriLogic().abgabeMöglich(newStream, data, colors);
|
||||
return abgabeMöglich;
|
||||
}
|
||||
|
||||
public void sortByTimeCatcher(byte[] data, String filename) throws IOException {
|
||||
new HighscoreManager().sortByTime(data, filename);
|
||||
}
|
||||
|
||||
public String getAvgTimeCatcher(byte[] data, String filename) throws IOException {
|
||||
String avgTime = new HighscoreManager().getAvgTime(data, filename);
|
||||
return avgTime;
|
||||
}
|
||||
|
||||
public void copyResourceIfNotExistsCatcher(String resourcePathInJar, File outFile) throws IOException {
|
||||
new HighscoreManager().copyResourceIfNotExists(resourcePathInJar, outFile);
|
||||
}
|
||||
|
||||
public String[] getGameButtonNamesCatcher() {
|
||||
String[] buttonNames = new GameBoard().getGameButtonNames();
|
||||
return buttonNames;
|
||||
}
|
||||
|
||||
public String[] getGamePathCatcher() {
|
||||
String[] pathNames = new GameBoard().getGamePath();
|
||||
return pathNames;
|
||||
}
|
||||
|
||||
public String[] getHighscorePathNamesCatcher() {
|
||||
String[] pathNames = new GameBoard().getHighscorePathNames();
|
||||
return pathNames;
|
||||
}
|
||||
|
||||
public String[] getHighscoreButtonNamesCatcher() {
|
||||
String[] buttonNames = new GameBoard().getHighscoreButtonNames();
|
||||
return buttonNames;
|
||||
}
|
||||
|
||||
public Object[] loadHighscore(int index, String[] pathNames) {
|
||||
Object[] arr = new Object[2];
|
||||
String resourcePathInJar = pathNames[index];
|
||||
String localFileName = resourcePathInJar.substring(resourcePathInJar.lastIndexOf('/') + 1);
|
||||
File outFile = new File("resources/Hitori_Highscores", localFileName);
|
||||
try {
|
||||
copyResourceIfNotExistsCatcher(resourcePathInJar, outFile);
|
||||
byte[] data = Files.readAllBytes(outFile.toPath());
|
||||
arr[0] = data;
|
||||
arr[1] = outFile.getPath();
|
||||
return arr;
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static void addMoveCatcher(String[][] colors, int i, int j, String lastLetterString,
|
||||
Stack<String> madeMoves) {
|
||||
new HitoriLogic().addMove(colors, i, j, lastLetterString, madeMoves);
|
||||
}
|
||||
|
||||
public FieldDataResult initializeFieldDataPass(byte[] gameData, int rows, Stack<String> madeMoves, String path) throws IOException {
|
||||
FieldDataResult fdr = new GameBoard().initializeFieldData(gameData, rows, madeMoves, path);
|
||||
return fdr;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,247 @@
|
|||
package de.hs_mannheim.informatik.gui;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Stack;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.io.*;
|
||||
import javax.swing.*;
|
||||
|
||||
import de.hs_mannheim.informatik.facade.HitoriAPI;
|
||||
|
||||
public class GameGUI extends JFrame {
|
||||
|
||||
private Timer timer = new Timer();
|
||||
private long startTime;
|
||||
private long elapsedSeconds;
|
||||
private byte[] gameData;
|
||||
|
||||
public Object[] giveFrame(CardLayout cl, JPanel main){
|
||||
Object[] frameArray = new Object[2];
|
||||
frameArray[0] = cl;
|
||||
frameArray[1] = main;
|
||||
return frameArray;
|
||||
}
|
||||
|
||||
public void paintGame(CardLayout cl, JPanel main, InputStream inputStream, Stack<String> madeMoves, String[][] data, String path0, String[][] colors) throws IOException{
|
||||
elapsedSeconds = 0;
|
||||
gameData = inputStream.readAllBytes();
|
||||
JButton[][] buttons = makeButtonArray(data);
|
||||
String[] filepath = new String[2];
|
||||
int num = buttons.length;
|
||||
JPanel gameGrid = new JPanel(new GridLayout(num,num,0,0));
|
||||
for(int i=0;i<num;i++){
|
||||
for(int j=0;j<num;j++){
|
||||
JButton button = buttons[i][j];
|
||||
Color foreground = Color.BLACK;
|
||||
Color background = Color.WHITE;
|
||||
changeButtonColor(button, foreground, background);
|
||||
gameGrid.add(button);
|
||||
String[] pos = HitoriAPI.getCordsCatcher(i,j);
|
||||
button.addActionListener(e -> {paintButton(cl, main, button, pos, colors , madeMoves, gameGrid, buttons);});
|
||||
}
|
||||
}
|
||||
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||
mainPanel.add(gameGrid, BorderLayout.CENTER);
|
||||
JPanel buttonGrid = new JPanel(new GridLayout(1,4,10,10));
|
||||
JButton aufgebenButton = new JButton("Aufgeben");
|
||||
aufgebenButton.addActionListener(e -> {
|
||||
filepath[0] = "";
|
||||
filepath[1] = "";
|
||||
cl.show(main, "HAUPT");
|
||||
});
|
||||
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 {
|
||||
totalResetButton(inputStream, cl, main, buttons, colors, madeMoves, data, path0);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}});
|
||||
JButton abgebenButton = new JButton("Abgeben");
|
||||
boolean[] levelFinished = {false};
|
||||
JPanel topGrid = new JPanel(new GridLayout(1,2,10,10));
|
||||
mainPanel.add(topGrid, BorderLayout.NORTH);
|
||||
JLabel timeLabel = new JLabel("Zeit: 00:00");
|
||||
topGrid.add(timeLabel);
|
||||
topGrid.revalidate();
|
||||
topGrid.repaint();
|
||||
boolean isOkay = new HitoriAPI().abgabeMöglichCatcher(inputStream, data, colors);
|
||||
levelFinished[0] = isOkay;
|
||||
Timer timer = new Timer();
|
||||
startTimer();
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
elapsedSeconds = (System.currentTimeMillis() - startTime) / 1000;
|
||||
long minutes = elapsedSeconds % 3600 / 60;
|
||||
long seconds = elapsedSeconds % 60;
|
||||
String newTime = String.format("Zeit: %02d:%02d", minutes, seconds);
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
timeLabel.setText(newTime);
|
||||
timeLabel.revalidate();
|
||||
timeLabel.repaint();
|
||||
});
|
||||
}
|
||||
}, 0, 1000);
|
||||
JLabel platzhalter = new JLabel("");
|
||||
topGrid.add(platzhalter);
|
||||
abgebenButton.addActionListener(e -> {
|
||||
try {
|
||||
InputStream newStream = new ByteArrayInputStream(gameData);
|
||||
levelFinished[0] = new HitoriAPI().abgabeMöglichCatcher(newStream, data, colors);
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
if (levelFinished[0] == true) {
|
||||
String endtime = stopTimer();
|
||||
timer.cancel();
|
||||
try {
|
||||
NewEntryGUI.finish(cl, main, endtime, filepath, path0);
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
platzhalter.setText("Abgabe nicht richtig!");
|
||||
mainPanel.revalidate();
|
||||
mainPanel.repaint();
|
||||
}
|
||||
});
|
||||
buttonGrid.add(aufgebenButton);
|
||||
buttonGrid.add(zurückButton);
|
||||
buttonGrid.add(resetButton);
|
||||
buttonGrid.add(abgebenButton);
|
||||
mainPanel.add(buttonGrid, BorderLayout.SOUTH);
|
||||
mainPanel.setVisible(true);
|
||||
mainPanel.setSize(700,700);
|
||||
main.add(mainPanel, "GAME");
|
||||
cl.show(main, "GAME");
|
||||
}
|
||||
|
||||
private void changeButtonColor(JButton button, Color foreground, Color background) {
|
||||
button.setOpaque(true);
|
||||
button.setForeground(foreground);
|
||||
button.setContentAreaFilled(true);
|
||||
button.setBorderPainted(false);
|
||||
button.setFocusPainted(false);
|
||||
button.setBackground(background);
|
||||
}
|
||||
|
||||
public void paintButton(CardLayout cl, JPanel main, JButton button, String[] pos, String[][] colors, Stack<String> madeMoves, JPanel grid, JButton[][] buttons){
|
||||
int i = Integer.parseInt(pos[0]);
|
||||
int j = Integer.parseInt(pos[1]);
|
||||
String col = colors[i][j];
|
||||
String lastLetterString = String.valueOf(col.charAt(col.length()-1));
|
||||
Color foreground;
|
||||
Color background;
|
||||
switch(lastLetterString) {
|
||||
case "W":
|
||||
foreground = Color.BLACK;
|
||||
background = Color.lightGray;
|
||||
lastLetterString = "G";
|
||||
changeButtonColor(button, foreground, background);
|
||||
break;
|
||||
case "G":
|
||||
foreground = Color.WHITE;
|
||||
background = Color.BLACK;
|
||||
lastLetterString = "B";
|
||||
changeButtonColor(button, foreground, background);
|
||||
break;
|
||||
case "B":
|
||||
foreground = Color.BLACK;
|
||||
background = Color.WHITE;
|
||||
lastLetterString = "W";
|
||||
changeButtonColor(button, foreground, background);
|
||||
break;
|
||||
}
|
||||
HitoriAPI.addMoveCatcher(colors, i,j,lastLetterString,madeMoves);
|
||||
}
|
||||
|
||||
public void backOneStep(CardLayout cl, JPanel main, Stack<String> movesMade, JButton[][] buttons, String[][] colors, JPanel grid){
|
||||
String move = movesMade.pop();
|
||||
String[] line = move.split("\\.");
|
||||
int i = Integer.parseInt(line[0]);
|
||||
int j = Integer.parseInt(line[1]);
|
||||
String color = line[2];
|
||||
JButton button = buttons[i][j];
|
||||
Color foreground;
|
||||
Color background;
|
||||
switch(color) {
|
||||
case "W":
|
||||
foreground = Color.WHITE;
|
||||
background = Color.BLACK;
|
||||
changeButtonColor(button, foreground, background);
|
||||
break;
|
||||
case "G":
|
||||
foreground = Color.BLACK;
|
||||
background = Color.WHITE;
|
||||
changeButtonColor(button, foreground, background);
|
||||
break;
|
||||
case "B":
|
||||
foreground = Color.BLACK;
|
||||
background = Color.lightGray;
|
||||
changeButtonColor(button, foreground, background);
|
||||
break;
|
||||
}
|
||||
removeMove(colors, i, j, grid, buttons);
|
||||
}
|
||||
|
||||
private void removeMove(String[][] colors, int i, int j, JPanel grid, JButton[][] buttons) {
|
||||
String colorString = colors[i][j];
|
||||
String colorStringWithoutLastElement = colorString.substring(0, colorString.length() - 1);
|
||||
colors[i][j] = colorStringWithoutLastElement;
|
||||
grid.repaint();
|
||||
gridUpdate(grid, buttons);
|
||||
}
|
||||
|
||||
public void gridUpdate(JPanel grid, JButton[][] buttons){
|
||||
grid.removeAll();
|
||||
grid.repaint();
|
||||
for(int i = 0; i<buttons.length; i++){
|
||||
for(int j = 0; j<buttons.length;j++){
|
||||
JButton button = buttons[i][j];
|
||||
grid.add(button);
|
||||
grid.repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String startTimer() {
|
||||
startTime = System.currentTimeMillis();
|
||||
elapsedSeconds = 0;
|
||||
return "Zeit: 00:00";
|
||||
}
|
||||
|
||||
public String stopTimer() {
|
||||
timer.cancel();
|
||||
long minutes = elapsedSeconds % 3600 / 60;
|
||||
long seconds = elapsedSeconds % 60;
|
||||
String endtime = String.format("Zeit: %02d:%02d", minutes, seconds);
|
||||
elapsedSeconds = 0;
|
||||
return endtime;
|
||||
}
|
||||
|
||||
public JButton[][] makeButtonArray(String[][] data){
|
||||
JButton[][] buttons = new JButton[data.length][data.length];
|
||||
for(int i=0;i<data.length;i++){
|
||||
for(int j=0;j<data.length;j++){
|
||||
String number = data[i][j];
|
||||
JButton button = new JButton(number);
|
||||
buttons[i][j] = button;
|
||||
}
|
||||
}
|
||||
return buttons;
|
||||
}
|
||||
|
||||
public void totalResetButton(InputStream inputStream, CardLayout cl, JPanel main, JButton[][] buttonArray, String[][] colors,Stack<String> madeMoves,String[][] data,String path) throws IOException{
|
||||
madeMoves.clear();
|
||||
for(int i = 0; i<data.length;i++){
|
||||
for(int j = 0; j<data.length;j++){
|
||||
colors[i][j] = "W";
|
||||
buttonArray[i][j] = null;
|
||||
}
|
||||
paintGame(cl, main, inputStream, madeMoves, data, path, colors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package de.hs_mannheim.informatik.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.CardLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import de.hs_mannheim.informatik.facade.HitoriAPI;
|
||||
|
||||
public class HighscoreMenuGUI extends JFrame {
|
||||
final String[] pathNames = new HitoriAPI().getHighscorePathNamesCatcher();
|
||||
final String[] buttonNames = new HitoriAPI().getHighscoreButtonNamesCatcher();
|
||||
|
||||
public HighscoreMenuGUI(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 < buttonNames.length; i++) {
|
||||
JButton button = new JButton(buttonNames[i]);
|
||||
buttonPanel.add(button);
|
||||
final int index = i;
|
||||
button.addActionListener(e -> {
|
||||
Object[] arr = new HitoriAPI().loadHighscore(index, pathNames);
|
||||
byte[] data = (byte[]) arr[0];
|
||||
String filename = (String) arr[1];
|
||||
try {
|
||||
new HighscoreTableGUI().showHighscores(cl, main, data, filename);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
JButton zurückButton = new JButton("Zurück");
|
||||
zurückButton.addActionListener(e -> cl.show(main, "HAUPT"));
|
||||
buttonPanel.add(zurückButton);
|
||||
highscorePanel.setVisible(true);
|
||||
highscorePanel.setSize(700,700);
|
||||
highscorePanel.add(buttonPanel, BorderLayout.CENTER);
|
||||
JLabel topText = new JLabel("Level für Highscore Liste auswählen!");
|
||||
highscorePanel.add(topText, BorderLayout.NORTH);
|
||||
main.add(highscorePanel, "HIGHSCORES");
|
||||
cl.show(main, "HIGHSCORES");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package de.hs_mannheim.informatik.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.CardLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import de.hs_mannheim.informatik.facade.HitoriAPI;
|
||||
|
||||
public class HighscoreTableGUI {
|
||||
public void showHighscores(CardLayout cl, JPanel main, byte[] data, String filename) throws IOException {
|
||||
new HitoriAPI().sortByTimeCatcher(data,filename);
|
||||
data = Files.readAllBytes(new File(filename).toPath());
|
||||
JPanel highscorePanel = new JPanel(new BorderLayout());
|
||||
List<String> lines = new ArrayList<>();
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(new ByteArrayInputStream(data), StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
lines.add(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
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));
|
||||
for (String s : lines) {
|
||||
JLabel text = new JLabel(s);
|
||||
entryPanel.add(text);
|
||||
}
|
||||
highscorePanel.add(entryPanel, BorderLayout.CENTER);
|
||||
|
||||
String avgString = new HitoriAPI().getAvgTimeCatcher(data,filename);
|
||||
JLabel avgTime = new JLabel(avgString);
|
||||
highscorePanel.add(avgTime, BorderLayout.NORTH);
|
||||
} else {
|
||||
JLabel text = new JLabel("Noch kein Highscore eingetragen.");
|
||||
highscorePanel.add(text, BorderLayout.CENTER);
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
package de.hs_mannheim.informatik.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.CardLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Stack;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import de.hs_mannheim.informatik.domain.FieldDataResult;
|
||||
import de.hs_mannheim.informatik.facade.HitoriAPI;
|
||||
|
||||
public class MenuGUI extends JFrame {
|
||||
|
||||
private CardLayout cl = new CardLayout();
|
||||
private JPanel main = new JPanel(cl);
|
||||
private String[] filepath = {"", ""};
|
||||
private byte[] gameData;
|
||||
|
||||
public MenuGUI(){
|
||||
JPanel menuPanel = new JPanel(new BorderLayout());
|
||||
JPanel buttonPanel = new JPanel(new GridLayout(7,1,10,10));
|
||||
|
||||
final String[] buttonNames = new HitoriAPI().getGameButtonNamesCatcher();
|
||||
final String[] buttonPaths = new HitoriAPI().getGamePathCatcher();
|
||||
|
||||
for(int i=0;i<buttonNames.length;i++){
|
||||
JButton button = new JButton(buttonNames[i]);
|
||||
buttonPanel.add(button);
|
||||
int[] count = {i};
|
||||
String[] num = buttonNames[i].split("x");
|
||||
button.addActionListener(e -> {
|
||||
int j = count[0];
|
||||
filepath[0] = buttonPaths[j];
|
||||
filepath[1] = num[0];
|
||||
loadGame(filepath, cl, main, gameData);
|
||||
});
|
||||
}
|
||||
JButton highscoreButton = new JButton("Highscores");
|
||||
highscoreButton.addActionListener(e -> {
|
||||
new HighscoreMenuGUI(cl, main);
|
||||
});
|
||||
buttonPanel.add(highscoreButton);
|
||||
menuPanel.add(buttonPanel, BorderLayout.CENTER);
|
||||
JLabel topText = new JLabel("Wählen Sie ein Level aus!");
|
||||
menuPanel.add(topText, BorderLayout.NORTH);
|
||||
setVisible(true);
|
||||
setSize(700,700);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
add(main);
|
||||
main.add(menuPanel, "HAUPT");
|
||||
cl.show(main, "HAUPT");
|
||||
}
|
||||
|
||||
public void loadGame(String[] filepath, CardLayout cl, JPanel main, byte[] gameData) {
|
||||
try (InputStream inputStream = GameGUI.class.getResourceAsStream(filepath[0])) {
|
||||
if (inputStream != null) {
|
||||
String path=filepath[0];
|
||||
ablauf(cl, main, inputStream, Integer.parseInt(filepath[1]), path);
|
||||
} else {
|
||||
throw new FileNotFoundException("Resource not found: " + filepath[0]);
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
e1.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public void passOn(String[][] data, String[][] colors, InputStream gameStream) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void ablauf(CardLayout cl, JPanel main, InputStream inputStream, int rows, String path) throws IOException {
|
||||
Stack<String> madeMoves = new Stack<>();
|
||||
byte[] gameData = inputStream.readAllBytes();
|
||||
FieldDataResult fdrDTO = new HitoriAPI().initializeFieldDataPass(gameData, rows, madeMoves, path);
|
||||
String[][] data = fdrDTO.getData();
|
||||
String[][] colors =fdrDTO.getColors();
|
||||
InputStream gameStream = fdrDTO.getGameStream();
|
||||
new GameGUI().paintGame(cl, main, gameStream, madeMoves, data, path, colors);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package de.hs_mannheim.informatik.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.CardLayout;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import de.hs_mannheim.informatik.domain.Highscores;
|
||||
|
||||
public class NewEntryGUI {
|
||||
public static void finish(CardLayout cl, JPanel main, String endtime, String[] filepath, String path) throws FileNotFoundException{
|
||||
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||
JLabel topText = new JLabel("Geben Sie unten Ihren Namen an um sich in der Highscore Liste einzutragen.");
|
||||
mainPanel.add(topText, BorderLayout.NORTH);
|
||||
JTextField field = new JTextField(20);
|
||||
mainPanel.add(field, BorderLayout.CENTER);
|
||||
JButton addHighscoreButton = new JButton("In der Highscore Liste eintragen");
|
||||
mainPanel.add(addHighscoreButton, BorderLayout.SOUTH);
|
||||
mainPanel.setVisible(true);
|
||||
mainPanel.setSize(700,700);
|
||||
addHighscoreButton.addActionListener(e -> {
|
||||
String username = field.getText();
|
||||
try {
|
||||
Highscores.newRecord(path, username, endtime);
|
||||
filepath[0] = "";
|
||||
filepath[1] = "";
|
||||
cl.show(main, "HAUPT");
|
||||
} catch (IOException e1) {
|
||||
e1.getMessage();
|
||||
}
|
||||
});
|
||||
main.add(mainPanel, "HIGHSCORENEU");
|
||||
cl.show(main, "HIGHSCORENEU");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package de.hs_mannheim.informatik.main;
|
||||
|
||||
import de.hs_mannheim.informatik.gui.MenuGUI;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
new MenuGUI();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
00:15 Berat
|
||||
11:00 Emre
|
||||
08:11 Mark
|
||||
07:11 Thomas
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
7,1,2,9,12,15,8,11,11,9,11,14,13,6,3
|
||||
2,3,8,1,2,11,10,9,5,8,14,3,12,13,15
|
||||
4,14,13,9,4,15,9,10,12,6,5,3,11,5,12
|
||||
15,9,5,6,10,15,1,15,8,3,5,4,6,2,8
|
||||
5,11,7,9,15,1,4,3,8,1,9,2,10,13,2
|
||||
15,15,10,3,1,14,8,12,11,1,9,8,2,7,2
|
||||
10,7,7,12,9,3,15,2,5,2,10,5,1,7,4
|
||||
3,8,9,14,1,6,12,4,15,2,13,11,5,10,11
|
||||
8,6,7,15,11,4,5,11,2,10,3,13,8,12,9
|
||||
2,2,3,3,4,13,5,6,5,11,5,15,8,9,12
|
||||
2,15,15,11,13,7,6,5,3,13,8,10,5,1,11
|
||||
12,5,11,13,13,2,2,8,8,4,10,9,3,2,5
|
||||
1,13,8,2,1,7,11,4,9,15,4,12,9,3,10
|
||||
13,10,12,5,15,3,2,7,13,14,12,12,9,11,6
|
||||
7,12,4,8,14,10,13,13,7,4,2,6,15,15,11
|
||||
|
||||
//Lösung
|
||||
1,4
|
||||
1,6
|
||||
1,8
|
||||
1,11
|
||||
2,1
|
||||
2,3
|
||||
2,9
|
||||
2,12
|
||||
2,14
|
||||
3,5
|
||||
3,7
|
||||
3,11
|
||||
3,15
|
||||
4,1
|
||||
4,3
|
||||
4,6
|
||||
4,9
|
||||
4,13
|
||||
5,4
|
||||
5,10
|
||||
5,15
|
||||
6,2
|
||||
6,5
|
||||
6,7
|
||||
6,9
|
||||
6,11
|
||||
6,13
|
||||
7,1
|
||||
7,3
|
||||
7,6
|
||||
7,8
|
||||
7,12
|
||||
7,14
|
||||
8,5
|
||||
8,9
|
||||
8,15
|
||||
9,3
|
||||
9,8
|
||||
9,13
|
||||
10,1
|
||||
10,4
|
||||
10,7
|
||||
10,9
|
||||
10,11
|
||||
11,3
|
||||
11,10
|
||||
11,13
|
||||
11,15
|
||||
12,2
|
||||
12,5
|
||||
12,7
|
||||
12,9
|
||||
12,11
|
||||
12,14
|
||||
13,1
|
||||
13,6
|
||||
13,8
|
||||
13,13
|
||||
14,3
|
||||
14,5
|
||||
14,9
|
||||
14,12
|
||||
15,1
|
||||
15,7
|
||||
15,10
|
||||
15,14
|
||||
|
Can't render this file because it has a wrong number of fields in line 17.
|
|
|
@ -0,0 +1,117 @@
|
|||
package de.hs_mannheim.informatik.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import de.hs_mannheim.informatik.domain.CSVReader;
|
||||
|
||||
public class CSVReaderTest {
|
||||
@Test
|
||||
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<String> filteredData = new CSVReader().getSolution(inputStream);
|
||||
assertEquals(5, filteredData.size());
|
||||
assertEquals(ergebnis4x4[0], filteredData.get(0));
|
||||
assertEquals(ergebnis4x4[1], filteredData.get(1));
|
||||
assertEquals(ergebnis4x4[2], filteredData.get(2));
|
||||
assertEquals(ergebnis4x4[3], filteredData.get(3));
|
||||
assertEquals(ergebnis4x4[4], filteredData.get(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getSolutionTest2() throws FileNotFoundException {
|
||||
String[] ergebnis4x4 = {"0,0"};
|
||||
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
ArrayList<String> filteredData = new CSVReader().getSolution(inputStream);
|
||||
assertNotEquals(1, filteredData.size());
|
||||
assertNotEquals(ergebnis4x4[0], filteredData.get(0));
|
||||
assertNotEquals(ergebnis4x4[0], filteredData.get(1));
|
||||
assertNotEquals(ergebnis4x4[0], filteredData.get(2));
|
||||
assertNotEquals(ergebnis4x4[0], filteredData.get(3));
|
||||
assertNotEquals(ergebnis4x4[0], filteredData.get(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDataTest1() throws FileNotFoundException {
|
||||
String[][] data = {
|
||||
{"3", "3", "1", "4"},
|
||||
{"4", "3", "2", "2"},
|
||||
{"1", "3", "4", "2"},
|
||||
{"3", "4", "3", "2"}};
|
||||
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
assertTrue(Arrays.deepEquals(data, new CSVReader().getData(inputStream, 4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDataTest2() throws FileNotFoundException {
|
||||
String[][] data = {
|
||||
{"3", "0", "1", "4"},
|
||||
{"4", "0", "2", "2"},
|
||||
{"1", "0", "4", "2"},
|
||||
{"3", "0", "3", "2"}};
|
||||
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
assertFalse(Arrays.deepEquals(data, new CSVReader().getData(inputStream, 4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void readFromFileTest1() {
|
||||
String[] file = {
|
||||
"3,3,1,4",
|
||||
"4,3,2,2",
|
||||
"1,3,4,2",
|
||||
"3,4,3,2",
|
||||
"",
|
||||
"//Lösung (schwarze Felder)",
|
||||
"1,2",
|
||||
"2,4",
|
||||
"3,2",
|
||||
"4,1",
|
||||
"4,4"};
|
||||
ArrayList<String> fileEntry = new ArrayList<String>();
|
||||
for(int i=0;i<file.length;i++) {
|
||||
fileEntry.add(file[i]);
|
||||
}
|
||||
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
ArrayList<String> ergebnisList = new CSVReader().readFromFile(inputStream);
|
||||
assertEquals(fileEntry, ergebnisList);
|
||||
}
|
||||
|
||||
@Test
|
||||
void readFromFileTest2() {
|
||||
String[] file = {
|
||||
"3,3,1,0",
|
||||
"4,3,2,0",
|
||||
"1,3,4,0",
|
||||
"3,4,3,0",
|
||||
"",
|
||||
"//Lösung (schwarze Felder)",
|
||||
"1,2",
|
||||
"2,4",
|
||||
"3,2",
|
||||
"4,1",
|
||||
"4,4"};
|
||||
ArrayList<String> fileEntry = new ArrayList<String>();
|
||||
for(int i=0;i<file.length;i++) {
|
||||
fileEntry.add(file[i]);
|
||||
}
|
||||
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
ArrayList<String> ergebnisList = new CSVReader().readFromFile(inputStream);
|
||||
assertNotEquals(fileEntry, ergebnisList);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package de.hs_mannheim.informatik.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import de.hs_mannheim.informatik.gui.GameGUI;
|
||||
|
||||
public class GameGUITest {
|
||||
|
||||
@Test
|
||||
void checkStartTimeTest() {
|
||||
assertEquals("Zeit: 00:00", new GameGUI().startTimer());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package de.hs_mannheim.informatik.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import java.time.LocalTime;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import de.hs_mannheim.informatik.domain.HighscoreEintrag;
|
||||
|
||||
public class HighscoreEintragTest {
|
||||
|
||||
@Test
|
||||
void highscoreEintragGetterTest() {
|
||||
LocalTime time = LocalTime.of(10, 00);
|
||||
HighscoreEintrag he = new HighscoreEintrag(time, "Berat");
|
||||
assertTrue(he.getName().equals("Berat"));
|
||||
LocalTime parsedTime = LocalTime.parse("10:00");
|
||||
assertTrue(he.getTime().equals(parsedTime));
|
||||
LocalTime wrongParsedTime = LocalTime.parse("11:00");
|
||||
assertFalse(he.getTime().equals(wrongParsedTime));
|
||||
assertFalse(he.getName().equals("Emre"));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package de.hs_mannheim.informatik.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import de.hs_mannheim.informatik.domain.HighscoreManager;
|
||||
|
||||
public class HighscoreManagerTest {
|
||||
@Test
|
||||
void getAvgTimeTest1() throws IOException {
|
||||
String filename = "timeFileForTest.txt";
|
||||
String path = "/Hitori_Highscores/timeFileForTest.txt";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
byte[] data = inputStream.readAllBytes();
|
||||
String actual = new HighscoreManager().getAvgTime(data, filename);
|
||||
String expected = "Durchschnittszeit: 6:39";
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAvgTimeTest2() throws IOException {
|
||||
String filename = "timeFileForTest.txt";
|
||||
String path = "/Hitori_Highscores/timeFileForTest.txt";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
byte[] data = inputStream.readAllBytes();
|
||||
String actual = new HighscoreManager().getAvgTime(data, filename);
|
||||
String expected = "Durchschnittszeit: 00:10";
|
||||
assertNotEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,297 @@
|
|||
package de.hs_mannheim.informatik.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import de.hs_mannheim.informatik.domain.CSVReader;
|
||||
import de.hs_mannheim.informatik.domain.HitoriLogic;
|
||||
|
||||
class HitoriLogicTest{
|
||||
|
||||
@Test
|
||||
void makeColorArrayTest1() {
|
||||
String[][] array3x3 = {
|
||||
{"W", "W", "W"},
|
||||
{"W", "W", "W"},
|
||||
{"W", "W", "W"}
|
||||
};
|
||||
assertTrue(Arrays.deepEquals(array3x3, new HitoriLogic().makeColorArray(3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void makeColorArrayTest2() {
|
||||
String[][] array3x2 = {
|
||||
{"W", "W", "W"},
|
||||
{"W", "W", "W"},
|
||||
};
|
||||
assertFalse(Arrays.deepEquals(array3x2, new HitoriLogic().makeColorArray(3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkArraySameTest1() {
|
||||
String[][] data = {
|
||||
{"W", "B", "W", "W"},
|
||||
{"W", "W", "W", "B"},
|
||||
{"W", "B", "W", "W"},
|
||||
{"B", "W", "W", "B"}};
|
||||
String[][] colors = {
|
||||
{"W", "W", "W", "W"},
|
||||
{"W", "W", "W", "B"},
|
||||
{"W", "B", "W", "W"},
|
||||
{"B", "W", "W", "B"}};
|
||||
assertFalse(new HitoriLogic().checkArraySame(data, colors));
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkArraySameTest2() {
|
||||
String[][] data = {
|
||||
{"W", "B", "W", "W"},
|
||||
{"W", "W", "W", "B"},
|
||||
{"W", "B", "W", "W"},
|
||||
{"B", "W", "W", "B"}};
|
||||
String[][] colors = {
|
||||
{"W", "B", "W", "W"},
|
||||
{"W", "W", "W", "B"},
|
||||
{"W", "B", "W", "W"},
|
||||
{"B", "W", "W", "B"}};
|
||||
|
||||
assertTrue(new HitoriLogic().checkArraySame(data, colors));
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkArraySameTest3() {
|
||||
String[][] data = {
|
||||
{"B", "W", "W", "B", "W"},
|
||||
{"W", "W", "B", "W", "W"},
|
||||
{"B", "W", "W", "B", "W"},
|
||||
{"W", "W", "B", "W", "W"},
|
||||
{"B", "W", "W", "W", "B"}};
|
||||
String[][] colors = {
|
||||
{"W", "W", "W", "W", "W"},
|
||||
{"W", "W", "W", "B", "W"},
|
||||
{"W", "B", "W", "W", "W"},
|
||||
{"W", "B", "W", "W", "W"},
|
||||
{"W", "B", "W", "W", "W"}};
|
||||
assertFalse(new HitoriLogic().checkArraySame(data, colors));
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkArraySameTest4() {
|
||||
String[][] data = {
|
||||
{"B", "W", "W", "B", "W"},
|
||||
{"W", "W", "B", "W", "W"},
|
||||
{"B", "W", "W", "B", "W"},
|
||||
{"W", "W", "B", "W", "W"},
|
||||
{"B", "W", "W", "W", "B"}};
|
||||
String[][] colors = {
|
||||
{"B", "W", "W", "B", "W"},
|
||||
{"W", "W", "B", "W", "W"},
|
||||
{"B", "W", "W", "B", "W"},
|
||||
{"W", "W", "B", "W", "W"},
|
||||
{"B", "W", "W", "W", "B"}};
|
||||
assertTrue(new HitoriLogic().checkArraySame(data, colors));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getCordsTest1() {
|
||||
String[] array = {"3", "4"};
|
||||
assertFalse(Arrays.deepEquals(array, new HitoriLogic().getCords(3, 3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getCordsTest2() {
|
||||
String[] array = {"3", "4"};
|
||||
assertTrue(Arrays.deepEquals(array, new HitoriLogic().getCords(3, 4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
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"},
|
||||
{"W", "B", "W", "W", "W", "B", "W", "W", "B", "W"},
|
||||
{"W", "W", "W", "W", "W", "W", "W", "B", "W", "B"},
|
||||
{"B", "W", "B", "W", "B", "W", "B", "W", "W", "W"},
|
||||
{"W", "B", "W", "W", "W", "B", "W", "W", "W", "B"},
|
||||
{"W", "W", "W", "W", "B", "W", "W", "W", "B", "W"},
|
||||
{"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"}};
|
||||
String[][] colors = {
|
||||
{"B", "W", "B", "W", "W", "B", "W", "W", "W", "B"},
|
||||
{"W", "W", "W", "B", "W", "W", "B", "W", "W", "W"},
|
||||
{"W", "B", "W", "W", "W", "B", "W", "W", "B", "W"},
|
||||
{"W", "W", "W", "W", "W", "W", "W", "B", "W", "B"},
|
||||
{"B", "W", "B", "W", "B", "W", "B", "W", "W", "W"},
|
||||
{"W", "B", "W", "W", "W", "B", "W", "W", "W", "B"},
|
||||
{"W", "W", "W", "W", "B", "W", "W", "W", "B", "W"},
|
||||
{"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(new HitoriLogic().checkArraySame(data, colors));
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkArraySameTest6() {
|
||||
String[][] data = {
|
||||
{"B", "W", "B", "W", "W", "B", "W", "W", "W", "B"},
|
||||
{"W", "W", "W", "B", "W", "W", "B", "W", "W", "W"},
|
||||
{"W", "B", "W", "W", "W", "B", "W", "W", "B", "W"},
|
||||
{"W", "W", "W", "W", "W", "W", "W", "B", "W", "B"},
|
||||
{"B", "W", "B", "W", "B", "W", "B", "W", "W", "W"},
|
||||
{"W", "B", "W", "W", "W", "B", "W", "W", "W", "B"},
|
||||
{"W", "W", "W", "W", "B", "W", "W", "W", "B", "W"},
|
||||
{"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"}};
|
||||
String[][] colors = {
|
||||
{"B", "W", "B", "W", "W", "B", "W", "W", "W", "B"},
|
||||
{"W", "W", "W", "B", "W", "W", "B", "W", "W", "W"},
|
||||
{"W", "B", "W", "W", "W", "B", "W", "W", "B", "W"},
|
||||
{"W", "W", "W", "W", "W", "W", "W", "B", "W", "B"},
|
||||
{"B", "W", "B", "W", "B", "W", "B", "W", "W", "W"},
|
||||
{"W", "B", "W", "W", "W", "B", "W", "W", "W", "B"},
|
||||
{"W", "W", "W", "W", "B", "W", "W", "W", "B", "W"},
|
||||
{"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(new HitoriLogic().checkArraySame(data, colors));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getResultTest1() {
|
||||
String[][] data = {
|
||||
{"W", "G", "B", "W"},
|
||||
{"G", "B", "W", "G"},
|
||||
{"B", "W", "G", "B"},
|
||||
{"W", "G", "B", "W"}};
|
||||
String[][] colors = {
|
||||
{"W", "G", "B", "W"},
|
||||
{"G", "B", "W", "G"},
|
||||
{"B", "W", "G", "B"},
|
||||
{"W", "G", "B", "W"}};
|
||||
String[][] array = {
|
||||
{"W", "W", "B", "W"},
|
||||
{"W", "B", "W", "W"},
|
||||
{"B", "W", "W", "B"},
|
||||
{"W", "W", "B", "W"}};
|
||||
assertTrue(Arrays.deepEquals(array, new HitoriLogic().getResult(data, colors)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getResultTest2() {
|
||||
String[][] data = {
|
||||
{"W", "G", "B", "W"},
|
||||
{"G", "B", "W", "G"},
|
||||
{"B", "W", "G", "B"},
|
||||
{"W", "G", "B", "W"}};
|
||||
String[][] colors = {
|
||||
{"W", "G", "B", "W"},
|
||||
{"G", "B", "W", "G"},
|
||||
{"B", "W", "G", "B"},
|
||||
{"W", "G", "B", "W"}};
|
||||
String[][] array = {
|
||||
{"W", "W", "B", "W"},
|
||||
{"G", "B", "W", "W"},
|
||||
{"B", "W", "W", "B"},
|
||||
{"W", "W", "B", "W"}};
|
||||
assertFalse(Arrays.deepEquals(array, new HitoriLogic().getResult(data, colors)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void makeColorArrayTest3() {
|
||||
String[][] colors = {
|
||||
{"W", "W", "W", "W"},
|
||||
{"W", "W", "W", "W"},
|
||||
{"W", "W", "W", "W"},
|
||||
{"W", "W", "W", "W"}};
|
||||
assertTrue(Arrays.deepEquals(colors, new HitoriLogic().makeColorArray(4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void makeColorArrayTest4() {
|
||||
String[][] colors = {
|
||||
{"B", "W", "W", "W"},
|
||||
{"B", "W", "W", "W"},
|
||||
{"B", "W", "W", "W"},
|
||||
{"B", "W", "W", "W"}};
|
||||
assertFalse(Arrays.deepEquals(colors, new HitoriLogic().makeColorArray(4)));
|
||||
}
|
||||
|
||||
@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<String> filteredData = new CSVReader().getSolution(inputStream);
|
||||
InputStream newStream = getClass().getResourceAsStream(path);
|
||||
int rows = 4;
|
||||
String[][] data = new CSVReader().getData(newStream, rows);
|
||||
assertTrue(Arrays.deepEquals(ergebnis1, new HitoriLogic().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<String> filteredData = new CSVReader().getSolution(inputStream);
|
||||
InputStream newStream = getClass().getResourceAsStream(path);
|
||||
int rows = 4;
|
||||
String[][] data = new CSVReader().getData(newStream, rows);
|
||||
assertFalse(Arrays.deepEquals(ergebnis1, new HitoriLogic().getErgebnisArray(data, filteredData)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void abgabeMöglichTest1() throws FileNotFoundException{
|
||||
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
String[][] data = {
|
||||
{"W", "B", "W", "W"},
|
||||
{"W", "W", "W", "B"},
|
||||
{"W", "B", "W", "W"},
|
||||
{"B", "W", "W", "B"}
|
||||
};
|
||||
String[][] colors = {
|
||||
{"W", "WGBBB", "W", "W"},
|
||||
{"W", "W", "W", "WGB"},
|
||||
{"W", "WGB", "W", "W"},
|
||||
{"WBGGGGB", "W", "W", "WGB"}
|
||||
};
|
||||
boolean expected = true;
|
||||
assertEquals(expected, new HitoriLogic().abgabeMöglich(inputStream, data, colors));
|
||||
}
|
||||
|
||||
@Test
|
||||
void abgabeMöglichTest2() throws FileNotFoundException{
|
||||
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
String[][] data = {
|
||||
{"W", "W", "W", "W"},
|
||||
{"W", "W", "W", "W"},
|
||||
{"W", "W", "W", "W"},
|
||||
{"W", "W", "W", "W"}
|
||||
};
|
||||
String[][] colors = {
|
||||
{"W", "B", "W", "W"},
|
||||
{"W", "W", "W", "B"},
|
||||
{"W", "B", "W", "W"},
|
||||
{"B", "W", "W", "B"}
|
||||
};
|
||||
boolean expected = false;
|
||||
assertNotEquals(expected, new HitoriLogic().abgabeMöglich(inputStream, data, colors));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<!-- Konsole Appender -->
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout
|
||||
pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %C{1} - %msg%n" />
|
||||
</Console>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<!-- Root Logger -->
|
||||
<Root level="info">
|
||||
<AppenderRef ref="Console" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
Loading…
Reference in New Issue