changed pathfinding for csv and txt files

main
beratkocak 2024-12-20 15:03:40 +01:00
parent 19fe8fee34
commit 18d440bdbc
4 changed files with 33 additions and 8 deletions

View File

@ -128,7 +128,11 @@ public class HitoriMain extends JFrame implements ActionListener{
buttons[i][j] = null; buttons[i][j] = null;
} }
JButton[][] buttons0 = makeButtonArray(data); JButton[][] buttons0 = makeButtonArray(data);
try {
GameGUI.paintGame(filepath, buttons0, colors, madeMoves, data); GameGUI.paintGame(filepath, buttons0, colors, madeMoves, data);
} catch (FileNotFoundException s) {
System.out.println("File not found: " + s.getMessage());
}
} }
} }

View File

@ -17,7 +17,7 @@ import de.hs_mannheim.informatik.pr2projekt.domain.HitoriMain;
public class GameGUI { public class GameGUI {
public static void paintGame(String[] filepath, JButton[][] buttons, String[][] colors, Stack<String> madeMoves, String[][] data){ public static void paintGame(String[] filepath, JButton[][] buttons, String[][] colors, Stack<String> madeMoves, String[][] data) throws FileNotFoundException{
JFrame frame = new JFrame(); JFrame frame = new JFrame();
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));
@ -40,7 +40,11 @@ public class GameGUI {
JButton b0 = new JButton("Aufgeben"); JButton b0 = new JButton("Aufgeben");
b0.addActionListener(e -> { b0.addActionListener(e -> {
frame.dispose(); frame.dispose();
try {
MenuGUI.getPath(filepath); MenuGUI.getPath(filepath);
} catch (FileNotFoundException i) {
System.out.println("File not found: " + i.getMessage());
}
}); });
JButton b1 = new JButton("Zurück"); JButton b1 = new JButton("Zurück");
b1.addActionListener(e -> {GameGUI.backOneStep(madeMoves, buttons, colors, gameGrid);}); b1.addActionListener(e -> {GameGUI.backOneStep(madeMoves, buttons, colors, gameGrid);});
@ -201,7 +205,11 @@ public class GameGUI {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e1.printStackTrace(); e1.printStackTrace();
} }
try {
MenuGUI.getPath(filepath); MenuGUI.getPath(filepath);
} catch (FileNotFoundException i) {
System.out.println("File not found: " + i.getMessage());
}
}); });
filepath[0] = ""; filepath[0] = "";
filepath[1] = ""; filepath[1] = "";

View File

@ -20,6 +20,8 @@ import de.hs_mannheim.informatik.pr2projekt.domain.HitoriMain;
public class HighscoreGUI { public class HighscoreGUI {
public static void highscoreScreen(String[] filepath){ public static void highscoreScreen(String[] filepath){
String currentWorkingDir = System.getProperty("user.dir");
System.out.println("Current working directory: " + currentWorkingDir);
JFrame frame = new JFrame("Highscores"); JFrame frame = new JFrame("Highscores");
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));
@ -54,7 +56,11 @@ public class HighscoreGUI {
JButton b = new JButton("Zurück"); JButton b = new JButton("Zurück");
b.addActionListener(e -> { b.addActionListener(e -> {
frame.dispose(); frame.dispose();
try {
MenuGUI.getPath(filepath); MenuGUI.getPath(filepath);
} catch (FileNotFoundException i) {
System.out.println("File not found: " + i.getMessage());
}
}); });
buttonPanel.add(b); buttonPanel.add(b);
frame.setVisible(true); frame.setVisible(true);
@ -88,6 +94,8 @@ public class HighscoreGUI {
} }
public static void showHighscores(String[] filepath, String path){ public static void showHighscores(String[] filepath, String path){
String currentWorkingDir = System.getProperty("user.dir");
System.out.println("Current working directory: " + currentWorkingDir);
JFrame frame = new JFrame("Highscore"); JFrame frame = new JFrame("Highscore");
JPanel mainPanel = new JPanel(new BorderLayout()); JPanel mainPanel = new JPanel(new BorderLayout());
File file = new File(path); File file = new File(path);
@ -126,7 +134,11 @@ public class HighscoreGUI {
JButton b = new JButton("Zurück"); JButton b = new JButton("Zurück");
b.addActionListener(e ->{ b.addActionListener(e ->{
frame.dispose(); frame.dispose();
try {
MenuGUI.getPath(filepath); MenuGUI.getPath(filepath);
} catch (FileNotFoundException s) {
System.out.println("File not found: " + s.getMessage());
}
}); });
mainPanel.add(highscorePanel, BorderLayout.CENTER); mainPanel.add(highscorePanel, BorderLayout.CENTER);
frame.add(mainPanel); frame.add(mainPanel);

View File

@ -12,7 +12,8 @@ import javax.swing.JPanel;
public class MenuGUI { public class MenuGUI {
public static void getPath(String[] filepath){ public static void getPath(String[] filepath) throws FileNotFoundException{
String[] filepath0 = new String[2]; String[] filepath0 = new String[2];
JFrame frame = new JFrame("Hitori"); JFrame frame = new JFrame("Hitori");
JPanel menuPanel = new JPanel(new BorderLayout()); JPanel menuPanel = new JPanel(new BorderLayout());
@ -34,12 +35,12 @@ public class MenuGUI {
b0.addActionListener(e -> { b0.addActionListener(e -> {
int j = count[0]; int j = count[0];
String[] paths = { String[] paths = {
"Hitori_Spielfelder2/Hitori4x4_leicht.csv", "Hitori_Spielfelder/Hitori4x4_leicht.csv",
"Hitori_Spielfelder2/Hitori5x5leicht.csv", "Hitori_Spielfelder/Hitori5x5leicht.csv",
"Hitori_Spielfelder2/Hitori8x8leicht.csv", "Hitori_Spielfelder/Hitori8x8leicht.csv",
"Hitori_Spielfelder2/Hitori8x8medium.csv", "Hitori_Spielfelder/Hitori8x8medium.csv",
"Hitori_Spielfelder2/Hitori10x10medium.csv", "Hitori_Spielfelder/Hitori10x10medium.csv",
"Hitori_Spielfelder2/Hitori15x15_medium.csv" "Hitori_Spielfelder/Hitori15x15_medium.csv"
}; };
filepath0[0] = paths[j]; filepath0[0] = paths[j];
filepath0[1] = row[0]; filepath0[1] = row[0];