deleted unused imports and made pmd corrections
parent
7e47bca18c
commit
b1d744e10f
|
|
@ -79,7 +79,7 @@
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
|
||||||
<classpathentry kind="lib" path="src/main/java/de/hs_mannheim/informatik/mvn/domain/HitoriMain.java"/>
|
<classpathentry kind="lib" path="src/main/java/de/hs_mannheim/informatik/mvn/domain/HitoriMain2.java"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,11 @@
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.6.0</version>
|
<version>3.6.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>de.hs_mannheim.informatik.mvn.HitoriMain2</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
|
|
|
||||||
|
|
@ -1,236 +0,0 @@
|
||||||
package de.hs_mannheim.informatik.mvn.domain;
|
|
||||||
|
|
||||||
import java.awt.CardLayout;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.LocalTime;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.Stack;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.mvn.gui.GameGUI;
|
|
||||||
import de.hs_mannheim.informatik.mvn.gui.MenuGUI;
|
|
||||||
|
|
||||||
|
|
||||||
public class HitoriMain extends JFrame implements ActionListener{
|
|
||||||
|
|
||||||
private static String[] filepath = {"", ""};
|
|
||||||
|
|
||||||
public static void main(String[] args) throws FileNotFoundException{
|
|
||||||
new MenuGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ablauf(CardLayout cl, JPanel main, String[] filepath) throws FileNotFoundException {
|
|
||||||
Stack<String> madeMoves = new Stack<>();
|
|
||||||
String[][] data = getData(filepath[0], Integer.parseInt(filepath[1]));
|
|
||||||
String[][] colors = makeColorArray(data.length);
|
|
||||||
JButton[][] buttons = makeButtonArray(data);
|
|
||||||
GameGUI.paintGame(cl, main, filepath, 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{
|
|
||||||
Scanner sc = new Scanner(new File(filepath));
|
|
||||||
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 b = new JButton(number);
|
|
||||||
buttons[i][j] = b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 totalResetButton(CardLayout cl, JPanel main, JButton[][] buttons, String[][] colors,Stack<String> madeMoves,String[][] data) throws FileNotFoundException{
|
|
||||||
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(cl, main, filepath, 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sortByTime(String path) throws FileNotFoundException, IOException{
|
|
||||||
File file = new File(path);
|
|
||||||
ArrayList<Entry> entries = new ArrayList<>();
|
|
||||||
|
|
||||||
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null) {
|
|
||||||
String[] parts = line.split(" ", 2);
|
|
||||||
String timeStr = parts[0];
|
|
||||||
String name = parts.length > 1 ? parts[1] : "";
|
|
||||||
|
|
||||||
String[] timeParts = timeStr.split(":");
|
|
||||||
int hour = Integer.parseInt(timeParts[0]);
|
|
||||||
int minute = Integer.parseInt(timeParts[1]);
|
|
||||||
LocalTime time = LocalTime.of(hour, minute);
|
|
||||||
|
|
||||||
entries.add(new Entry(time, name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
entries.sort(Comparator.comparing(e -> e.time));
|
|
||||||
|
|
||||||
try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) {
|
|
||||||
for (Entry e : entries) {
|
|
||||||
String formattedTime = String.format("%02d:%02d", e.time.getHour(), e.time.getMinute());
|
|
||||||
bw.write(formattedTime + " " + e.name);
|
|
||||||
bw.newLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Entry {
|
|
||||||
LocalTime time;
|
|
||||||
String name;
|
|
||||||
|
|
||||||
Entry(LocalTime time, String name) {
|
|
||||||
this.time = time;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -96,6 +96,7 @@ public class HitoriMain2 extends JFrame implements ActionListener{
|
||||||
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(ergebnis1[i][j])){
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
count--;
|
count--;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,12 @@ import java.io.BufferedWriter;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.System.Logger;
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.*;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
public class LogHighscores {
|
public class LogHighscores {
|
||||||
private static final org.apache.logging.log4j.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 path, String username, String time) throws FileNotFoundException {
|
||||||
String timePart = time.substring("Zeit: ".length()).trim();
|
String timePart = time.substring("Zeit: ".length()).trim();
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,8 @@ import javax.swing.JPanel;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.mvn.domain.HitoriMain;
|
import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
|
||||||
import de.hs_mannheim.informatik.mvn.domain.LogHighscores;
|
import de.hs_mannheim.informatik.mvn.domain.LogHighscores;
|
||||||
import de.hs_mannheim.informatik.mvn.domain.*;
|
|
||||||
|
|
||||||
public class GameGUI extends JFrame implements ActionListener {
|
public class GameGUI extends JFrame implements ActionListener {
|
||||||
|
|
||||||
|
|
@ -218,7 +217,9 @@ public class GameGUI extends JFrame implements ActionListener {
|
||||||
colors[i][j] = str0;
|
colors[i][j] = str0;
|
||||||
gridUpdate(grid, buttons);
|
gridUpdate(grid, buttons);
|
||||||
}
|
}
|
||||||
} catch(EmptyStackException e) {}
|
} catch(EmptyStackException e) {
|
||||||
|
System.out.println("Fehler: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void gridUpdate(JPanel grid, JButton[][] buttons){
|
public static void gridUpdate(JPanel grid, JButton[][] buttons){
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,8 @@ 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.BufferedWriter;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
@ -17,8 +15,7 @@ import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import de.hs_mannheim.informatik.mvn.domain.HitoriMain;
|
import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
|
||||||
import de.hs_mannheim.informatik.mvn.domain.*;
|
|
||||||
|
|
||||||
public class HighscoreGUI extends JFrame implements ActionListener {
|
public class HighscoreGUI extends JFrame implements ActionListener {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -9,13 +8,11 @@ import java.awt.event.ActionListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Stack;
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import de.hs_mannheim.informatik.mvn.domain.HitoriMain;
|
import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
|
||||||
import de.hs_mannheim.informatik.mvn.domain.*;
|
|
||||||
|
|
||||||
public class MenuGUI extends JFrame implements ActionListener {
|
public class MenuGUI extends JFrame implements ActionListener {
|
||||||
|
|
||||||
|
|
@ -83,7 +80,7 @@ public class MenuGUI extends JFrame implements ActionListener {
|
||||||
menuPanel.add(text0, BorderLayout.NORTH);
|
menuPanel.add(text0, BorderLayout.NORTH);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
setSize(600, 600);
|
setSize(600, 600);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
add(main);
|
add(main);
|
||||||
main.add(menuPanel, "HAUPT");
|
main.add(menuPanel, "HAUPT");
|
||||||
cl.show(main, "HAUPT");
|
cl.show(main, "HAUPT");
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
|
|
||||||
import de.hs_mannheim.informatik.mvn.gui.GameGUI;
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
@ -16,7 +11,7 @@ import java.util.Arrays;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.mvn.domain.HitoriMain;
|
import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
|
||||||
import de.hs_mannheim.informatik.mvn.gui.GameGUI;
|
import de.hs_mannheim.informatik.mvn.gui.GameGUI;
|
||||||
|
|
||||||
class HitoriTest{
|
class HitoriTest{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue