fixed pathing and gui, added tests,
parent
39f106f1bd
commit
f4de80f801
|
|
@ -29,7 +29,7 @@
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
|
||||||
<!-- Test Resources -->
|
<!-- Test Resources -->
|
||||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/main/java/resources">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
|
@ -65,7 +65,7 @@
|
||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/main/java/de/hs_mannheim/informatik/mbvn/resources">
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/main/java/resources">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
|
|
|
||||||
|
|
@ -118,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>
|
||||||
|
|
|
||||||
|
|
@ -5,66 +5,73 @@ import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
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.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
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.LocalTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.mvn.gui.*;
|
import de.hs_mannheim.informatik.mvn.gui.*;
|
||||||
|
|
||||||
public class HitoriMain2 extends JFrame implements ActionListener{
|
public class HitoriMain2 extends JFrame implements ActionListener{
|
||||||
|
|
||||||
private static String[] filepath = {"", ""};
|
private static byte[] gameData;
|
||||||
|
|
||||||
public static void main(String[] args) throws FileNotFoundException{
|
public static void main(String[] args) throws FileNotFoundException{
|
||||||
|
System.out.println("HERE");
|
||||||
new MenuGUI();
|
new MenuGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ablauf(CardLayout cl, JPanel main, String[] filepath) throws FileNotFoundException {
|
public static void ablauf(CardLayout cl, JPanel main, InputStream inputStream, int rows, String path) throws IOException {
|
||||||
Stack<String> madeMoves = new Stack<>();
|
Stack<String> madeMoves = new Stack<>();
|
||||||
String[][] data = getData(filepath[0], Integer.parseInt(filepath[1]));
|
gameData = inputStream.readAllBytes();
|
||||||
String[][] colors = makeColorArray(data.length);
|
InputStream newStream = new ByteArrayInputStream(gameData);
|
||||||
JButton[][] buttons = makeButtonArray(data);
|
String[][] data = getData(newStream, rows);
|
||||||
GameGUI.paintGame(cl, main, filepath, buttons, colors, madeMoves, data);
|
String[][] colors = makeColorArray(data.length);
|
||||||
}
|
JButton[][] buttons = makeButtonArray(data);
|
||||||
|
InputStream newStream1 = new ByteArrayInputStream(gameData);
|
||||||
|
GameGUI.paintGame(newStream1, cl, main, buttons, colors, madeMoves, data, path);
|
||||||
|
}
|
||||||
|
|
||||||
public static ArrayList<String> readFromFile(String path){
|
public static ArrayList<String> readFromFile(InputStream inputStream){
|
||||||
ArrayList<String> lines = new ArrayList<>();
|
ArrayList<String> lines = new ArrayList<>();
|
||||||
try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.getMessage();
|
||||||
}
|
}
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[][] getData(String filepath, int rows) throws FileNotFoundException{
|
public static String[][] getData(InputStream inputStream, int rows) throws FileNotFoundException{
|
||||||
Scanner sc = new Scanner(new File(filepath));
|
|
||||||
String[][] data = new String[rows][rows];
|
String[][] data = new String[rows][rows];
|
||||||
int rowInt = 0;
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
while (sc.hasNextLine() && rowInt < rows) {
|
String line;
|
||||||
String line = sc.nextLine();
|
int rowInt = 0;
|
||||||
data[rowInt] = line.split(",");
|
while ((line = reader.readLine()) != null && rowInt < rows) {
|
||||||
rowInt++;
|
data[rowInt] = line.split(",");
|
||||||
}
|
rowInt++;
|
||||||
sc.close();
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String[][] makeColorArray(int size){
|
public static String[][] makeColorArray(int size){
|
||||||
String[][] colors = new String[size][size];
|
String[][] colors = new String[size][size];
|
||||||
for(int i=0;i<size;i++){
|
for(int i=0;i<size;i++){
|
||||||
|
|
@ -87,26 +94,31 @@ public class HitoriMain2 extends JFrame implements ActionListener{
|
||||||
return buttons;
|
return buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean abgabeMöglich(String path, String[][] data, String[][] colors) throws FileNotFoundException{
|
public static boolean checkArraySame(String[][] ergebnis,String[][] result){
|
||||||
boolean abgabeMöglich = false;
|
int count = 0;
|
||||||
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 i=0;i<result.length;i++){
|
||||||
for(int j=0;j<result.length;j++){
|
for(int j=0;j<result.length;j++){
|
||||||
if(result[i][j].equals(ergebnis1[i][j])){
|
if(result[i][j].equals(ergebnis[i][j])){
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
count--;
|
count--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(count <0){
|
if(count <0){
|
||||||
abgabeMöglich = false;
|
boolean arrayNotSame = false;
|
||||||
|
return arrayNotSame;
|
||||||
} else {
|
} else {
|
||||||
abgabeMöglich = true;
|
boolean arraySame = true;
|
||||||
|
return arraySame;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean abgabeMöglich(InputStream inputStream, String[][] data, String[][] colors) throws FileNotFoundException{
|
||||||
|
String[][] result = getResult(data, colors);
|
||||||
|
ArrayList<String> filteredData = getSolution(inputStream, result);
|
||||||
|
String[][] ergebnis = getErgebnisArray(result, filteredData);
|
||||||
|
boolean abgabeMöglich = checkArraySame(result, ergebnis);
|
||||||
return abgabeMöglich;
|
return abgabeMöglich;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,7 +129,7 @@ public class HitoriMain2 extends JFrame implements ActionListener{
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void totalResetButton(CardLayout cl, JPanel main, JButton[][] buttons, String[][] colors,Stack<String> madeMoves,String[][] data) 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++){
|
||||||
|
|
@ -125,7 +137,11 @@ public class HitoriMain2 extends JFrame implements ActionListener{
|
||||||
buttons[i][j] = null;
|
buttons[i][j] = null;
|
||||||
}
|
}
|
||||||
JButton[][] buttons0 = makeButtonArray(data);
|
JButton[][] buttons0 = makeButtonArray(data);
|
||||||
GameGUI.paintGame(cl, main, filepath, buttons0, colors, madeMoves, data);
|
try {
|
||||||
|
GameGUI.paintGame(inputStream, cl, main, buttons0, colors, madeMoves, data, path);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,27 +160,30 @@ public class HitoriMain2 extends JFrame implements ActionListener{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<String> getSolution(String path, String[][] result) throws FileNotFoundException{
|
public static ArrayList<String> getSolution(InputStream inputStream, String[][] result) throws FileNotFoundException{
|
||||||
Scanner sc = new Scanner(new File(path));
|
|
||||||
ArrayList<String> filteredData = new ArrayList<>();
|
ArrayList<String> filteredData = new ArrayList<>();
|
||||||
boolean isUnderComment = false;
|
boolean isUnderComment = false;
|
||||||
while (sc.hasNextLine()) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
String line = sc.nextLine().trim();
|
String line;
|
||||||
if (line.equals("//Lösung (schwarze Felder)")) {
|
while ((line = reader.readLine()) != null) {
|
||||||
isUnderComment = true;
|
line = line.trim();
|
||||||
continue;
|
if (line.equals("//Lösung (schwarze Felder)")) {
|
||||||
}
|
isUnderComment = true;
|
||||||
if (isUnderComment && !line.isEmpty()) {
|
continue;
|
||||||
String[] lineArray = line.split(",");
|
}
|
||||||
int num1 = Integer.parseInt(lineArray[0]);
|
if (isUnderComment && !line.isEmpty()) {
|
||||||
int num2 = Integer.parseInt(lineArray[1]);
|
String[] lineArray = line.split(",");
|
||||||
String newNum1 = String.valueOf(num1-1);
|
int num1 = Integer.parseInt(lineArray[0]);
|
||||||
String newNum2 = String.valueOf(num2-1);
|
int num2 = Integer.parseInt(lineArray[1]);
|
||||||
String newLine = newNum1+","+newNum2;
|
String newNum1 = String.valueOf(num1 - 1);
|
||||||
filteredData.add(newLine);
|
String newNum2 = String.valueOf(num2 - 1);
|
||||||
}
|
String newLine = newNum1 + "," + newNum2;
|
||||||
}
|
filteredData.add(newLine);
|
||||||
sc.close();
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.getMessage();
|
||||||
|
}
|
||||||
return filteredData;
|
return filteredData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -186,41 +205,61 @@ public class HitoriMain2 extends JFrame implements ActionListener{
|
||||||
return ergebnis;
|
return ergebnis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sortByTime(String path) throws FileNotFoundException, IOException{
|
public static void sortByTime(byte[] data, String filename) throws IOException {
|
||||||
File file = new File(path);
|
|
||||||
ArrayList<HighscoreEintrag> highscores = new ArrayList<>();
|
ArrayList<HighscoreEintrag> highscores = new ArrayList<>();
|
||||||
|
try (BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(new ByteArrayInputStream(data), StandardCharsets.UTF_8))) {
|
||||||
|
|
||||||
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
|
|
||||||
String line;
|
String line;
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
String[] parts = line.split(" ", 2);
|
try {
|
||||||
String timeStr = parts[0];
|
String[] parts = line.split(" ", 2);
|
||||||
String name = parts.length > 1 ? parts[1] : "";
|
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]);
|
||||||
|
|
||||||
String[] timeParts = timeStr.split(":");
|
if (hour < 0 || hour > 23 || minute < 0 || minute > 59) {
|
||||||
int hour = Integer.parseInt(timeParts[0]);
|
System.err.println("Invalid time values: " + timeStr);
|
||||||
int minute = Integer.parseInt(timeParts[1]);
|
continue;
|
||||||
LocalTime time = LocalTime.of(hour, minute);
|
}
|
||||||
|
LocalTime time = LocalTime.of(hour, minute);
|
||||||
highscores.add(new HighscoreEintrag(time, name));
|
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(); // Keep the name
|
||||||
|
formattedHighscores.add(line);
|
||||||
|
}
|
||||||
|
String fileName = filename.substring(filename.lastIndexOf('/') + 1);
|
||||||
|
File file = new File(fileName);
|
||||||
|
overwriteContentOfFile(formattedHighscores, file);
|
||||||
|
}
|
||||||
|
|
||||||
highscores.sort(Comparator.comparing(e -> e.time));
|
private static void overwriteContentOfFile(ArrayList<String> formattedHighscores, File file) throws FileNotFoundException, IOException {
|
||||||
|
try (BufferedWriter writer = new BufferedWriter(
|
||||||
try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) {
|
new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) {
|
||||||
for (HighscoreEintrag e : highscores) {
|
for (String entry : formattedHighscores) {
|
||||||
String formattedTime = String.format("%02d:%02d", e.time.getHour(), e.time.getMinute());
|
writer.write(entry);
|
||||||
bw.write(formattedTime + " " + e.name);
|
writer.newLine();
|
||||||
bw.newLine();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -232,4 +271,12 @@ class HighscoreEintrag {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LocalTime getTime() {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,47 @@
|
||||||
package de.hs_mannheim.informatik.mvn.domain;
|
package de.hs_mannheim.informatik.mvn.domain;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
public class LogHighscores {
|
public class LogHighscores {
|
||||||
private static final Logger logger = LogManager.getLogger(LogHighscores.class);
|
private static final Logger logger = LogManager.getLogger(LogHighscores.class);
|
||||||
|
|
||||||
public static void newRecord(String path, String username, String time) throws FileNotFoundException {
|
public static void newRecord(String resourcePath, String username, String time) throws IOException {
|
||||||
String timePart = time.substring("Zeit: ".length()).trim();
|
String timePart = time.substring("Zeit: ".length()).trim();
|
||||||
String[] parts = path.split("/");
|
String[] parts = resourcePath.split("/");
|
||||||
String filename = parts[parts.length - 1];
|
String jarFileName = parts[parts.length - 1];
|
||||||
int dotIndex = filename.lastIndexOf(".");
|
String newName = jarFileName.replace(".csv", ".txt");
|
||||||
String result = filename.substring(0, dotIndex);
|
|
||||||
String ordner = "Hitori_Highscores/";
|
|
||||||
String filetype = ".txt";
|
|
||||||
String filepath = ordner + result + filetype;
|
|
||||||
System.out.println("A: " + filepath);
|
|
||||||
Scanner sc = new Scanner(filepath);
|
|
||||||
while (sc.hasNextLine()) {
|
|
||||||
sc.nextLine();
|
|
||||||
}
|
|
||||||
sc.close();
|
|
||||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filepath, true))) {
|
|
||||||
String eintrag = timePart + " " + username;
|
|
||||||
logger.info("Neuer Eintrag: {}", eintrag);
|
|
||||||
|
|
||||||
writer.write(eintrag);
|
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 = LogHighscores.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();
|
writer.newLine();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Fehler beim Schreiben in die Datei: " + filepath, e);
|
logger.error("Error handling local highscore file: {}", localFile.getAbsolutePath(), e);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,13 @@
|
||||||
package de.hs_mannheim.informatik.mvn.gui;
|
package de.hs_mannheim.informatik.mvn.gui;
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.CardLayout;
|
import java.awt.*;
|
||||||
import java.awt.Color;
|
import java.awt.event.*;
|
||||||
import java.awt.GridLayout;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.util.EmptyStackException;
|
import java.util.EmptyStackException;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
import java.io.*;
|
||||||
import javax.swing.JButton;
|
import javax.swing.*;
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
|
import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
|
||||||
import de.hs_mannheim.informatik.mvn.domain.LogHighscores;
|
import de.hs_mannheim.informatik.mvn.domain.LogHighscores;
|
||||||
|
|
||||||
|
|
@ -26,9 +16,13 @@ public class GameGUI extends JFrame implements ActionListener {
|
||||||
private static Timer timer = new Timer();
|
private static Timer timer = new Timer();
|
||||||
private static long startTime;
|
private static long startTime;
|
||||||
private static long elapsedSeconds;
|
private static long elapsedSeconds;
|
||||||
|
private static byte[] gameData;
|
||||||
|
|
||||||
public static void paintGame(CardLayout cl, JPanel main, String[] filepath, JButton[][] buttons, String[][] colors, Stack<String> madeMoves, String[][] data) throws FileNotFoundException{
|
public static void paintGame(InputStream inputStream, CardLayout cl, JPanel main, JButton[][] buttons, String[][] colors, Stack<String> madeMoves, String[][] data, String path0) throws IOException{
|
||||||
elapsedSeconds = 0;
|
elapsedSeconds = 0;
|
||||||
|
gameData = inputStream.readAllBytes();
|
||||||
|
|
||||||
|
String[] filepath = new String[2];
|
||||||
int num = buttons.length;
|
int num = buttons.length;
|
||||||
JPanel gameGrid = new JPanel(new GridLayout(num,num,0,0));
|
JPanel gameGrid = new JPanel(new GridLayout(num,num,0,0));
|
||||||
for(int i=0;i<num;i++){
|
for(int i=0;i<num;i++){
|
||||||
|
|
@ -57,12 +51,11 @@ public class GameGUI extends JFrame implements ActionListener {
|
||||||
b1.addActionListener(e -> {backOneStep(cl, main, madeMoves, buttons, colors, gameGrid);});
|
b1.addActionListener(e -> {backOneStep(cl, main, madeMoves, buttons, colors, gameGrid);});
|
||||||
JButton b2 = new JButton("Zurücksetzen");
|
JButton b2 = new JButton("Zurücksetzen");
|
||||||
b2.addActionListener(e -> {try {
|
b2.addActionListener(e -> {try {
|
||||||
HitoriMain2.totalResetButton(cl, main, buttons, colors, madeMoves, data);
|
HitoriMain2.totalResetButton(inputStream, cl, main, buttons, colors, madeMoves, data, path0);
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}});
|
}});
|
||||||
JButton b3 = new JButton("Abgeben");
|
JButton b3 = new JButton("Abgeben");
|
||||||
String path = filepath[0];
|
|
||||||
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);
|
||||||
|
|
@ -70,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 = HitoriMain2.abgabeMöglich(path, 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();
|
||||||
|
|
@ -78,7 +71,7 @@ public class GameGUI extends JFrame implements ActionListener {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
elapsedSeconds = (System.currentTimeMillis() - startTime) / 1000;
|
elapsedSeconds = (System.currentTimeMillis() - startTime) / 1000;
|
||||||
long minutes = (elapsedSeconds % 3600) / 60;
|
long minutes = elapsedSeconds % 3600 / 60;
|
||||||
long seconds = elapsedSeconds % 60;
|
long seconds = elapsedSeconds % 60;
|
||||||
String newTime = String.format("Zeit: %02d:%02d", minutes, seconds);
|
String newTime = String.format("Zeit: %02d:%02d", minutes, seconds);
|
||||||
|
|
||||||
|
|
@ -95,22 +88,20 @@ public class GameGUI extends JFrame implements ActionListener {
|
||||||
|
|
||||||
b3.addActionListener(e -> {
|
b3.addActionListener(e -> {
|
||||||
try {
|
try {
|
||||||
levelFinished[0] = HitoriMain2.abgabeMöglich(path, data, colors);
|
InputStream newStream = new ByteArrayInputStream(gameData);
|
||||||
System.out.println("0000: " + levelFinished[0]);
|
levelFinished[0] = HitoriMain2.abgabeMöglich(newStream, data, colors);
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
if (levelFinished[0] == true) {
|
if (levelFinished[0] == true) {
|
||||||
System.out.println("1111: " + levelFinished[0]);
|
|
||||||
String endtime = stopTimer();
|
String endtime = stopTimer();
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
try {
|
try {
|
||||||
finish(cl, main, endtime, filepath, path, data, colors);
|
finish(cl, main, endtime, filepath, path0);
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("2222: " + levelFinished[0]);
|
|
||||||
luecke.setText("Abgabe nicht richtig!");
|
luecke.setText("Abgabe nicht richtig!");
|
||||||
mainPanel.revalidate();
|
mainPanel.revalidate();
|
||||||
mainPanel.repaint();
|
mainPanel.repaint();
|
||||||
|
|
@ -218,7 +209,7 @@ public class GameGUI extends JFrame implements ActionListener {
|
||||||
gridUpdate(grid, buttons);
|
gridUpdate(grid, buttons);
|
||||||
}
|
}
|
||||||
} catch(EmptyStackException e) {
|
} catch(EmptyStackException e) {
|
||||||
System.out.println("Fehler: " + e.getMessage());
|
e.getStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -242,14 +233,14 @@ public class GameGUI extends JFrame implements ActionListener {
|
||||||
|
|
||||||
public static String stopTimer() {
|
public static String stopTimer() {
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
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; // Reset so the next start begins at zero
|
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, String[][] data, String[][] colors) 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 text = 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(text, BorderLayout.NORTH);
|
mainPanel.add(text, BorderLayout.NORTH);
|
||||||
|
|
@ -266,8 +257,8 @@ public class GameGUI extends JFrame implements ActionListener {
|
||||||
filepath[0] = "";
|
filepath[0] = "";
|
||||||
filepath[1] = "";
|
filepath[1] = "";
|
||||||
cl.show(main, "HAUPT");
|
cl.show(main, "HAUPT");
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (IOException e1) {
|
||||||
e1.printStackTrace();
|
e1.getMessage();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
main.add(mainPanel, "HIGHSCORENEU");
|
main.add(mainPanel, "HIGHSCORENEU");
|
||||||
|
|
@ -276,7 +267,5 @@ public class GameGUI extends JFrame implements ActionListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
package de.hs_mannheim.informatik.mvn.gui;
|
package de.hs_mannheim.informatik.mvn.gui;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
|
@ -6,11 +5,18 @@ import java.awt.CardLayout;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Scanner;
|
import java.util.List;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
|
@ -19,47 +25,51 @@ import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
|
||||||
|
|
||||||
public class HighscoreGUI extends JFrame implements ActionListener {
|
public class HighscoreGUI extends JFrame implements ActionListener {
|
||||||
|
|
||||||
public static void highscoreScreen(CardLayout cl, JPanel main){
|
final String[] paths = {
|
||||||
|
"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"
|
||||||
|
};
|
||||||
|
|
||||||
|
final String[] buttons = {
|
||||||
|
"Highscore 4x4 - leicht",
|
||||||
|
"Highscore 5x5 - leicht",
|
||||||
|
"Highscore 8x8 - leicht",
|
||||||
|
"Highscore 8x8 - medium",
|
||||||
|
"Highscore 10x10 - medium",
|
||||||
|
"Highscore 15x15 - medium"
|
||||||
|
};
|
||||||
|
|
||||||
|
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));
|
||||||
String[] buttons = {
|
|
||||||
"Highscore 4x4 - leicht",
|
for (int i = 0; i < buttons.length; i++) {
|
||||||
"Highscore 5x5 - leicht",
|
|
||||||
"Highscore 8x8 - leicht",
|
|
||||||
"Highscore 8x8 - medium",
|
|
||||||
"Highscore 10x10 - medium",
|
|
||||||
"Highscore 15x15 - medium"
|
|
||||||
};
|
|
||||||
for(int i=0;i<buttons.length;i++){
|
|
||||||
JButton b0 = new JButton(buttons[i]);
|
JButton b0 = new JButton(buttons[i]);
|
||||||
buttonPanel.add(b0);
|
buttonPanel.add(b0);
|
||||||
int[] count = {i};
|
final int index = i;
|
||||||
b0.addActionListener(e -> {
|
b0.addActionListener(e -> {
|
||||||
int j = count[0];
|
String resourcePathInJar = paths[index];
|
||||||
String[] paths = {
|
String localFileName = resourcePathInJar.substring(resourcePathInJar.lastIndexOf('/') + 1);
|
||||||
"src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Highscores/Hitori4x4_leicht.txt",
|
File outFile = new File("resources/Hitori_Highscores", localFileName);
|
||||||
"src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Highscores/Hitori5x5leicht.txt",
|
|
||||||
"src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Highscores/Hitori8x8leicht.txt",
|
|
||||||
"src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Highscores/Hitori8x8medium.txt",
|
|
||||||
"src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Highscores/Hitori10x10medium.txt",
|
|
||||||
"src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Highscores/Hitori15x15_medium.txt"
|
|
||||||
};
|
|
||||||
try {
|
try {
|
||||||
showHighscores(cl, main, paths[j]);
|
copyResourceIfNotExists(resourcePathInJar, outFile);
|
||||||
} catch (FileNotFoundException e0) {
|
byte[] data = Files.readAllBytes(outFile.toPath());
|
||||||
e0.printStackTrace();
|
showHighscores(cl, main, data, outFile.getPath());
|
||||||
} catch (IOException e1) {
|
} catch (IOException ex1) {
|
||||||
e1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
|
empty(cl, main);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
JButton b = new JButton("Zurück");
|
JButton b = new JButton("Zurück");
|
||||||
b.addActionListener(e -> {
|
b.addActionListener(e -> cl.show(main, "HAUPT"));
|
||||||
cl.show(main, "HAUPT");
|
|
||||||
});
|
|
||||||
buttonPanel.add(b);
|
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 text0 = new JLabel("Level für Highscore Liste auswählen!");
|
JLabel text0 = new JLabel("Level für Highscore Liste auswählen!");
|
||||||
highscorePanel.add(text0, BorderLayout.NORTH);
|
highscorePanel.add(text0, BorderLayout.NORTH);
|
||||||
|
|
@ -67,54 +77,83 @@ public class HighscoreGUI extends JFrame implements ActionListener {
|
||||||
cl.show(main, "HIGHSCORES");
|
cl.show(main, "HIGHSCORES");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showHighscores(CardLayout cl, JPanel main, String path) throws FileNotFoundException, IOException{
|
private static void copyResourceIfNotExists(String resourcePathInJar, File outFile) throws IOException {
|
||||||
HitoriMain2.sortByTime(path);
|
if (outFile.exists()) {
|
||||||
JPanel mainPanel = new JPanel(new BorderLayout());
|
return;
|
||||||
File file = new File(path);
|
|
||||||
int i = 0;
|
|
||||||
try (Scanner scanner = new Scanner(file)) {
|
|
||||||
while (scanner.hasNextLine()) {
|
|
||||||
if(scanner.nextLine() != "") {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
JPanel highscorePanel = new JPanel(new GridLayout(i,1,10,10));
|
outFile.getParentFile().mkdirs();
|
||||||
if(i>0){
|
try (InputStream in = HighscoreGUI.class.getResourceAsStream(resourcePathInJar);
|
||||||
ArrayList<String> lines = HitoriMain2.readFromFile(path);
|
FileOutputStream fos = new FileOutputStream(outFile)) {
|
||||||
for(String s: lines){
|
if (in == null) {
|
||||||
JLabel text = new JLabel(s);
|
throw new FileNotFoundException("Resource not found in JAR: " + resourcePathInJar);
|
||||||
highscorePanel.add(text);
|
}
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = in.read(buffer)) != -1) {
|
||||||
|
fos.write(buffer, 0, bytesRead);
|
||||||
}
|
}
|
||||||
JButton b = new JButton("Zurück");
|
|
||||||
b.addActionListener(e -> {
|
|
||||||
cl.show(main, "HIGHSCORES");
|
|
||||||
highscoreScreen(cl, main);
|
|
||||||
});
|
|
||||||
mainPanel.add(b, BorderLayout.SOUTH);
|
|
||||||
} else {
|
|
||||||
JLabel text = new JLabel("Noch kein Highscore eingetragen.");
|
|
||||||
highscorePanel.add(text);
|
|
||||||
JButton b = new JButton("Zurück");
|
|
||||||
b.addActionListener(e -> {
|
|
||||||
cl.show(main, "HIGHSCORES");
|
|
||||||
highscoreScreen(cl, main);
|
|
||||||
});
|
|
||||||
mainPanel.add(b, BorderLayout.SOUTH);
|
|
||||||
}
|
}
|
||||||
mainPanel.add(highscorePanel, BorderLayout.CENTER);
|
|
||||||
mainPanel.setVisible(true);
|
|
||||||
mainPanel.setSize(600,600);
|
|
||||||
main.add(mainPanel, "HIGHSCORES");
|
|
||||||
cl.show(main, "HIGHSCORES");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static void empty(CardLayout cl, JPanel main) {
|
||||||
public void actionPerformed(ActionEvent e) {
|
JPanel panel = new JPanel(new BorderLayout());
|
||||||
// TODO Auto-generated method stub
|
JButton b = new JButton("Zurück");
|
||||||
|
JLabel text = new JLabel("Noch kein Highscore eingetragen.");
|
||||||
|
panel.add(text, BorderLayout.CENTER);
|
||||||
|
panel.add(b, BorderLayout.SOUTH);
|
||||||
|
b.addActionListener(e -> cl.show(main, "HIGHSCORES"));
|
||||||
|
main.add(panel, "EMPTY");
|
||||||
|
cl.show(main, "EMPTY");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public static void showHighscores(CardLayout cl, JPanel main, byte[] data, String filename) throws IOException {
|
||||||
|
HitoriMain2.sortByTime(data, filename);
|
||||||
|
data = Files.readAllBytes(new File(filename).toPath());
|
||||||
|
JPanel highscorePanel1 = 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) {
|
||||||
|
if (!s.trim().isEmpty()) {
|
||||||
|
JLabel text = new JLabel(s);
|
||||||
|
entryPanel.add(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
highscorePanel1.add(entryPanel, BorderLayout.CENTER);
|
||||||
|
} else {
|
||||||
|
JLabel text = new JLabel("Noch kein Highscore eingetragen.");
|
||||||
|
highscorePanel1.add(text, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
JButton b = new JButton("OK");
|
||||||
|
highscorePanel1.add(b, BorderLayout.SOUTH);
|
||||||
|
b.addActionListener(e -> cl.show(main, "HIGHSCORES"));
|
||||||
|
|
||||||
|
highscorePanel1.setVisible(true);
|
||||||
|
highscorePanel1.setSize(600, 600);
|
||||||
|
main.add(highscorePanel1, "HIGHSCOREEINTRAG");
|
||||||
|
cl.show(main, "HIGHSCOREEINTRAG");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import java.awt.CardLayout;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.nio.file.Paths;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
|
@ -23,7 +23,7 @@ public class MenuGUI extends JFrame implements ActionListener {
|
||||||
public MenuGUI(){
|
public MenuGUI(){
|
||||||
JPanel menuPanel = new JPanel(new BorderLayout());
|
JPanel menuPanel = new JPanel(new BorderLayout());
|
||||||
JPanel buttonPanel = new JPanel(new GridLayout(7,1,10,10));
|
JPanel buttonPanel = new JPanel(new GridLayout(7,1,10,10));
|
||||||
String[] buttons = {
|
final String[] buttons = {
|
||||||
"4x4 - leicht",
|
"4x4 - leicht",
|
||||||
"5x5 - leicht",
|
"5x5 - leicht",
|
||||||
"8x8 - leicht",
|
"8x8 - leicht",
|
||||||
|
|
@ -31,6 +31,14 @@ public class MenuGUI extends JFrame implements ActionListener {
|
||||||
"10x10 - medium",
|
"10x10 - medium",
|
||||||
"15x15 - medium"
|
"15x15 - medium"
|
||||||
};
|
};
|
||||||
|
final String[] paths = {
|
||||||
|
"/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"
|
||||||
|
};
|
||||||
for(int i=0;i<buttons.length;i++){
|
for(int i=0;i<buttons.length;i++){
|
||||||
JButton b0 = new JButton(buttons[i]);
|
JButton b0 = new JButton(buttons[i]);
|
||||||
buttonPanel.add(b0);
|
buttonPanel.add(b0);
|
||||||
|
|
@ -38,41 +46,23 @@ public class MenuGUI extends JFrame implements ActionListener {
|
||||||
String[] num = buttons[i].split("x");
|
String[] num = buttons[i].split("x");
|
||||||
b0.addActionListener(e -> {
|
b0.addActionListener(e -> {
|
||||||
int j = count[0];
|
int j = count[0];
|
||||||
String currentDirectory = Paths.get("").toAbsolutePath().toString();
|
|
||||||
System.out.println("Current Working Directory: " + currentDirectory);
|
|
||||||
String[] paths = {
|
|
||||||
"src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Spielfelder/Hitori4x4_leicht.csv",
|
|
||||||
"src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Spielfelder/Hitori5x5leicht.csv",
|
|
||||||
"src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Spielfelder/Hitori8x8leicht.csv",
|
|
||||||
"src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Spielfelder/Hitori8x8medium.csv",
|
|
||||||
"src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Spielfelder/Hitori10x10medium.csv",
|
|
||||||
"src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Spielfelder/Hitori15x15_medium.csv"
|
|
||||||
};
|
|
||||||
// /Users/beratkocak/git/PR2Projekt/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn
|
|
||||||
|
|
||||||
|
|
||||||
for (String path : paths) {
|
|
||||||
File file = new File(path);
|
|
||||||
if (file.exists()) {
|
|
||||||
System.out.println("File found: " + file.getAbsolutePath());
|
|
||||||
} else {
|
|
||||||
System.out.println("File not found: " + file.getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
filepath[0] = paths[j];
|
filepath[0] = paths[j];
|
||||||
filepath[1] = num[0];
|
filepath[1] = num[0];
|
||||||
try{
|
try (InputStream inputStream = getClass().getResourceAsStream(filepath[0])) {
|
||||||
HitoriMain2.ablauf(cl, main, filepath);
|
if (inputStream != null) {
|
||||||
} catch (FileNotFoundException s){
|
String path=filepath[0];
|
||||||
System.out.println("Fehler: " + s.getMessage());
|
HitoriMain2.ablauf(cl, main, inputStream, Integer.parseInt(filepath[1]), path);
|
||||||
}
|
} else {
|
||||||
});
|
throw new FileNotFoundException("Resource not found: " + filepath[0]);
|
||||||
|
}
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.getMessage();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
JButton b = new JButton("Highscores");
|
JButton b = new JButton("Highscores");
|
||||||
b.addActionListener(e -> {
|
b.addActionListener(e -> {
|
||||||
HighscoreGUI.highscoreScreen(cl, main);
|
new HighscoreGUI(cl, main);
|
||||||
});
|
});
|
||||||
buttonPanel.add(b);
|
buttonPanel.add(b);
|
||||||
menuPanel.add(buttonPanel, BorderLayout.CENTER);
|
menuPanel.add(buttonPanel, BorderLayout.CENTER);
|
||||||
|
|
@ -88,7 +78,5 @@ public class MenuGUI extends JFrame implements ActionListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,12 @@
|
||||||
|
00:02 paul
|
||||||
|
00:02 paul
|
||||||
|
00:02 thomas
|
||||||
|
00:02 thomas
|
||||||
|
00:02 dfopwahgfa
|
||||||
|
00:02 dfopwahgfa
|
||||||
|
00:02 fwagfawgagagas
|
||||||
|
00:02 fwagfawgagagas
|
||||||
|
00:03 fafaadxc
|
||||||
|
00:03 fafaadxc
|
||||||
|
00:04 haveaqniucelife
|
||||||
|
00:04 haveaqniucelife
|
||||||
|
|
@ -7,6 +7,8 @@ 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.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
@ -52,13 +54,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"}};
|
||||||
String path = "src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
assertFalse(HitoriMain2.checkArraySame(data, colors));
|
||||||
|
|
||||||
try {
|
|
||||||
assertFalse(HitoriMain2.abgabeMöglich(path, data, colors));
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -73,12 +69,8 @@ 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"}};
|
||||||
String path = "src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
|
||||||
try {
|
assertTrue(HitoriMain2.checkArraySame(data, colors));
|
||||||
assertTrue(HitoriMain2.abgabeMöglich(path, data, colors));
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -95,12 +87,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"}};
|
||||||
String path = "src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Spielfelder/Hitori5x5leicht.csv";
|
assertFalse(HitoriMain2.checkArraySame(data, colors));
|
||||||
try {
|
|
||||||
assertFalse(HitoriMain2.abgabeMöglich(path, data, colors));
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -117,12 +104,7 @@ 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"}};
|
||||||
String path = "src/main/java/de/hs_mannheim/informatik/mvn/resources/Hitori_Spielfelder/Hitori5x5leicht.csv";
|
assertTrue(HitoriMain2.checkArraySame(data, colors));
|
||||||
try {
|
|
||||||
assertTrue(HitoriMain2.abgabeMöglich(path, data, colors));
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -136,4 +118,58 @@ class HitoriTest{
|
||||||
String[] array = {"3", "4"};
|
String[] array = {"3", "4"};
|
||||||
assertTrue(Arrays.deepEquals(array, HitoriMain2.getCords(3, 4)));
|
assertTrue(Arrays.deepEquals(array, HitoriMain2.getCords(3, 4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test10() 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(HitoriMain2.checkArraySame(data, colors));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test11() {
|
||||||
|
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(HitoriMain2.checkArraySame(data, colors));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue