From 18d440bdbc3f6d40f556bb730210f2ee2e98a0a5 Mon Sep 17 00:00:00 2001 From: beratkocak Date: Fri, 20 Dec 2024 15:03:40 +0100 Subject: [PATCH] changed pathfinding for csv and txt files --- .../informatik/pr2projekt/domain/HitoriMain.java | 4 ++++ .../informatik/pr2projekt/gui/GameGUI.java | 10 +++++++++- .../informatik/pr2projekt/gui/HighscoreGUI.java | 12 ++++++++++++ .../informatik/pr2projekt/gui/MenuGUI.java | 15 ++++++++------- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/domain/HitoriMain.java b/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/domain/HitoriMain.java index e04aab6..23e1064 100644 --- a/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/domain/HitoriMain.java +++ b/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/domain/HitoriMain.java @@ -128,7 +128,11 @@ public class HitoriMain extends JFrame implements ActionListener{ buttons[i][j] = null; } JButton[][] buttons0 = makeButtonArray(data); + try { GameGUI.paintGame(filepath, buttons0, colors, madeMoves, data); + } catch (FileNotFoundException s) { + System.out.println("File not found: " + s.getMessage()); + } } } diff --git a/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/gui/GameGUI.java b/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/gui/GameGUI.java index 0bcaf66..8a204d6 100644 --- a/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/gui/GameGUI.java +++ b/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/gui/GameGUI.java @@ -17,7 +17,7 @@ import de.hs_mannheim.informatik.pr2projekt.domain.HitoriMain; public class GameGUI { - public static void paintGame(String[] filepath, JButton[][] buttons, String[][] colors, Stack madeMoves, String[][] data){ + public static void paintGame(String[] filepath, JButton[][] buttons, String[][] colors, Stack madeMoves, String[][] data) throws FileNotFoundException{ JFrame frame = new JFrame(); int num = buttons.length; JPanel gameGrid = new JPanel(new GridLayout(num,num,0,0)); @@ -40,7 +40,11 @@ public class GameGUI { JButton b0 = new JButton("Aufgeben"); b0.addActionListener(e -> { frame.dispose(); + try { MenuGUI.getPath(filepath); + } catch (FileNotFoundException i) { + System.out.println("File not found: " + i.getMessage()); + } }); JButton b1 = new JButton("Zurück"); b1.addActionListener(e -> {GameGUI.backOneStep(madeMoves, buttons, colors, gameGrid);}); @@ -201,7 +205,11 @@ public class GameGUI { // TODO Auto-generated catch block e1.printStackTrace(); } + try { MenuGUI.getPath(filepath); + } catch (FileNotFoundException i) { + System.out.println("File not found: " + i.getMessage()); + } }); filepath[0] = ""; filepath[1] = ""; diff --git a/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/gui/HighscoreGUI.java b/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/gui/HighscoreGUI.java index f761f96..1fec047 100644 --- a/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/gui/HighscoreGUI.java +++ b/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/gui/HighscoreGUI.java @@ -20,6 +20,8 @@ import de.hs_mannheim.informatik.pr2projekt.domain.HitoriMain; public class HighscoreGUI { public static void highscoreScreen(String[] filepath){ + String currentWorkingDir = System.getProperty("user.dir"); + System.out.println("Current working directory: " + currentWorkingDir); JFrame frame = new JFrame("Highscores"); JPanel highscorePanel = new JPanel(new BorderLayout()); JPanel buttonPanel = new JPanel(new GridLayout(7,1,10,10)); @@ -54,7 +56,11 @@ public class HighscoreGUI { JButton b = new JButton("Zurück"); b.addActionListener(e -> { frame.dispose(); + try { MenuGUI.getPath(filepath); + } catch (FileNotFoundException i) { + System.out.println("File not found: " + i.getMessage()); + } }); buttonPanel.add(b); frame.setVisible(true); @@ -88,6 +94,8 @@ public class HighscoreGUI { } 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"); JPanel mainPanel = new JPanel(new BorderLayout()); File file = new File(path); @@ -126,7 +134,11 @@ public class HighscoreGUI { JButton b = new JButton("Zurück"); b.addActionListener(e ->{ frame.dispose(); + try { MenuGUI.getPath(filepath); + } catch (FileNotFoundException s) { + System.out.println("File not found: " + s.getMessage()); + } }); mainPanel.add(highscorePanel, BorderLayout.CENTER); frame.add(mainPanel); diff --git a/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/gui/MenuGUI.java b/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/gui/MenuGUI.java index 95bf6a7..90e84ee 100644 --- a/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/gui/MenuGUI.java +++ b/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/gui/MenuGUI.java @@ -12,7 +12,8 @@ import javax.swing.JPanel; public class MenuGUI { - public static void getPath(String[] filepath){ + public static void getPath(String[] filepath) throws FileNotFoundException{ + String[] filepath0 = new String[2]; JFrame frame = new JFrame("Hitori"); JPanel menuPanel = new JPanel(new BorderLayout()); @@ -34,12 +35,12 @@ public class MenuGUI { b0.addActionListener(e -> { int j = count[0]; String[] paths = { - "Hitori_Spielfelder2/Hitori4x4_leicht.csv", - "Hitori_Spielfelder2/Hitori5x5leicht.csv", - "Hitori_Spielfelder2/Hitori8x8leicht.csv", - "Hitori_Spielfelder2/Hitori8x8medium.csv", - "Hitori_Spielfelder2/Hitori10x10medium.csv", - "Hitori_Spielfelder2/Hitori15x15_medium.csv" + "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" }; filepath0[0] = paths[j]; filepath0[1] = row[0];