diff --git a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/domain/HighscoreManager.java b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/domain/HighscoreManager.java index 03e5c34..b570030 100644 --- a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/domain/HighscoreManager.java +++ b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/domain/HighscoreManager.java @@ -23,7 +23,11 @@ import de.hs_mannheim.informatik.mvn.gui.HighscoreMenuGUI; public class HighscoreManager { - public static void sortByTime(byte[] data, String filename) throws IOException { + public static void main(String[] args) { + new HighscoreManager(); + } + + public void sortByTime(byte[] data, String filename) throws IOException { ArrayList highscores = new ArrayList<>(); try (BufferedReader reader = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(data), StandardCharsets.UTF_8))) { @@ -66,7 +70,7 @@ public class HighscoreManager { overwriteContentOfFile(formattedHighscores, file); } - private static void overwriteContentOfFile(ArrayList formattedHighscores, File file) throws FileNotFoundException, IOException { + private void overwriteContentOfFile(ArrayList formattedHighscores, File file) throws FileNotFoundException, IOException { try (BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) { for (String entry : formattedHighscores) { @@ -76,7 +80,7 @@ public class HighscoreManager { } } - public static String getAvgTime(byte[] data, String filename) throws IOException { + public String getAvgTime(byte[] data, String filename) throws IOException { int totalSeconds = 0; int count = 0; try (BufferedReader reader = new BufferedReader( @@ -106,7 +110,7 @@ public class HighscoreManager { } } - public static void copyResourceIfNotExists(String resourcePathInJar, File outFile) throws IOException { + public void copyResourceIfNotExists(String resourcePathInJar, File outFile) throws IOException { if (outFile.exists()) { return; } diff --git a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/domain/HitoriMain.java b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/domain/HitoriMain.java index 6dd382f..31c1707 100644 --- a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/domain/HitoriMain.java +++ b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/domain/HitoriMain.java @@ -15,7 +15,7 @@ public class HitoriMain { } - public static ArrayList readFromFile(InputStream inputStream){ + public ArrayList readFromFile(InputStream inputStream){ ArrayList lines = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { String line; @@ -28,7 +28,7 @@ public class HitoriMain { return lines; } - public static String[][] getData(InputStream inputStream, int rows) throws FileNotFoundException{ + 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; @@ -43,7 +43,7 @@ public class HitoriMain { return data; } - public static String[][] makeColorArray(int size){ + public String[][] makeColorArray(int size){ String[][] colors = new String[size][size]; for(int i=0;i filteredData = getSolution(inputStream); String[][] ergebnis = getErgebnisArray(result, filteredData); @@ -81,14 +81,14 @@ public class HitoriMain { return abgabeMöglich; } - public static String[] getCords(int i, int j){ + public String[] getCords(int i, int j){ String yKoordinate = String.valueOf(i); String xKoordinate = String.valueOf(j); String[] position = {yKoordinate, xKoordinate}; return position; } - public static String[][] getResult(String[][] data, String[][] colors){ + public String[][] getResult(String[][] data, String[][] colors){ String[][] result = new String[data.length][data.length]; for(int i=0;i getSolution(InputStream inputStream) throws FileNotFoundException{ + public ArrayList getSolution(InputStream inputStream) throws FileNotFoundException{ ArrayList filteredData = new ArrayList<>(); boolean isUnderComment = false; try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { @@ -130,7 +130,7 @@ public class HitoriMain { return filteredData; } - public static String[][] getErgebnisArray(String[][] result, ArrayList filteredData){ + public String[][] getErgebnisArray(String[][] result, ArrayList filteredData){ String[][] ergebnis = new String[result.length][result.length]; for(int i=0;i madeMoves, String[][] data, String path0) throws IOException{ + public void paintGame(InputStream inputStream, CardLayout cl, JPanel main, JButton[][] buttons, String[][] colors, Stack madeMoves, String[][] data, String path0) throws IOException{ elapsedSeconds = 0; gameData = inputStream.readAllBytes(); String[] filepath = new String[2]; @@ -46,7 +46,7 @@ public class GameGUI extends JFrame implements ActionListener { zurückButton.addActionListener(e -> {backOneStep(cl, main, madeMoves, buttons, colors, gameGrid);}); JButton resetButton = new JButton("Zurücksetzen"); resetButton.addActionListener(e -> {try { - HitoriAPI.totalResetButtonCatcher(inputStream, cl, main, buttons, colors, madeMoves, data, path0); + new HitoriAPI().totalResetButtonCatcher(inputStream, cl, main, buttons, colors, madeMoves, data, path0); } catch (FileNotFoundException e1) { e1.printStackTrace(); }}); @@ -58,7 +58,7 @@ public class GameGUI extends JFrame implements ActionListener { topGrid.add(timeLabel); topGrid.revalidate(); topGrid.repaint(); - boolean isOkay = HitoriAPI.abgabeMöglichCatcher(inputStream, data, colors); + boolean isOkay = new HitoriAPI().abgabeMöglichCatcher(inputStream, data, colors); levelFinished[0] = isOkay; Timer timer = new Timer(); startTimer(); @@ -82,7 +82,7 @@ public class GameGUI extends JFrame implements ActionListener { abgebenButton.addActionListener(e -> { try { InputStream newStream = new ByteArrayInputStream(gameData); - levelFinished[0] = HitoriAPI.abgabeMöglichCatcher(newStream, data, colors); + levelFinished[0] = new HitoriAPI().abgabeMöglichCatcher(newStream, data, colors); } catch (FileNotFoundException e1) { e1.printStackTrace(); } @@ -111,13 +111,13 @@ public class GameGUI extends JFrame implements ActionListener { cl.show(main, "GAME"); } - private static void addMove(String[][] colors, int i, int j, String lastLetterString, Stack madeMoves){ + private void addMove(String[][] colors, int i, int j, String lastLetterString, Stack madeMoves){ colors[i][j] += lastLetterString; String newMove = i+"."+j+"."+lastLetterString; madeMoves.push(newMove); } - private static void changeButtonColor(JButton button, Color foreground, Color background) { + private void changeButtonColor(JButton button, Color foreground, Color background) { button.setOpaque(true); button.setForeground(foreground); button.setContentAreaFilled(true); @@ -126,7 +126,7 @@ public class GameGUI extends JFrame implements ActionListener { button.setBackground(background); } - public static void paintButton(CardLayout cl, JPanel main, JButton button, String[] pos, String[][] colors, Stack madeMoves, JPanel grid, JButton[][] buttons){ + public void paintButton(CardLayout cl, JPanel main, JButton button, String[] pos, String[][] colors, Stack madeMoves, JPanel grid, JButton[][] buttons){ int i = Integer.parseInt(pos[0]); int j = Integer.parseInt(pos[1]); String col = colors[i][j]; @@ -156,7 +156,7 @@ public class GameGUI extends JFrame implements ActionListener { addMove(colors, i, j, lastLetterString, madeMoves); } - public static void backOneStep(CardLayout cl, JPanel main, Stack movesMade, JButton[][] buttons, String[][] colors, JPanel grid){ + public void backOneStep(CardLayout cl, JPanel main, Stack movesMade, JButton[][] buttons, String[][] colors, JPanel grid){ String move = movesMade.pop(); String[] line = move.split("\\."); int i = Integer.parseInt(line[0]); @@ -185,7 +185,7 @@ public class GameGUI extends JFrame implements ActionListener { removeMove(colors, i, j, grid, buttons); } - private static void removeMove(String[][] colors, int i, int j, JPanel grid, JButton[][] 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; @@ -193,7 +193,7 @@ public class GameGUI extends JFrame implements ActionListener { gridUpdate(grid, buttons); } - public static void gridUpdate(JPanel grid, JButton[][] buttons){ + public void gridUpdate(JPanel grid, JButton[][] buttons){ grid.removeAll(); grid.repaint(); for(int i = 0; i madeMoves,String[][] data,String path) throws FileNotFoundException{ + public void totalResetButton(InputStream inputStream, CardLayout cl, JPanel main, JButton[][] buttonArray, String[][] colors,Stack madeMoves,String[][] data,String path) throws FileNotFoundException{ madeMoves.clear(); for(int i = 0; i { - HitoriAPI.loadHighscore(index, pathNames, cl, main); + new HitoriAPI().loadHighscore(index, pathNames, cl, main); }); } JButton zurückButton = new JButton("Zurück"); diff --git a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/HighscoreTableGUI.java b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/HighscoreTableGUI.java index a77f3e7..2084332 100644 --- a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/HighscoreTableGUI.java +++ b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/HighscoreTableGUI.java @@ -18,8 +18,8 @@ import javax.swing.JPanel; import de.hs_mannheim.informatik.mvn.facade.HitoriAPI; public class HighscoreTableGUI { - public static void showHighscores(CardLayout cl, JPanel main, byte[] data, String filename) throws IOException { - HitoriAPI.sortByTimeCatcher(data,filename); + 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 lines = new ArrayList<>(); @@ -48,7 +48,7 @@ public class HighscoreTableGUI { } highscorePanel.add(entryPanel, BorderLayout.CENTER); - String avgString = HitoriAPI.getAvgTimeCatcher(data,filename); + String avgString = new HitoriAPI().getAvgTimeCatcher(data,filename); JLabel avgTime = new JLabel(avgString); highscorePanel.add(avgTime, BorderLayout.NORTH); } else { diff --git a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/MenuGUI.java b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/MenuGUI.java index fa88963..912b113 100644 --- a/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/MenuGUI.java +++ b/PR2Projekt/src/main/java/de/hs_mannheim/informatik/mvn/gui/MenuGUI.java @@ -21,8 +21,8 @@ public class MenuGUI extends JFrame implements ActionListener { public MenuGUI(){ JPanel menuPanel = new JPanel(new BorderLayout()); JPanel buttonPanel = new JPanel(new GridLayout(7,1,10,10)); - final String[] buttonNames = HitoriAPI.getGameButtonNamesCatcher(); - final String[] buttonPaths = HitoriAPI.getGamePathCatcher(); + final String[] buttonNames = new HitoriAPI().getGameButtonNamesCatcher(); + final String[] buttonPaths = new HitoriAPI().getGamePathCatcher(); for(int i=0;i filteredData = HitoriMain.getSolution(inputStream); + ArrayList filteredData = new HitoriMain().getSolution(inputStream); assertEquals(5, filteredData.size()); assertEquals(ergebnis4x4[0], filteredData.get(0)); assertEquals(ergebnis4x4[1], filteredData.get(1)); @@ -229,7 +229,7 @@ class HitoriTest{ String[] ergebnis4x4 = {"0,0"}; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; InputStream inputStream = getClass().getResourceAsStream(path); - ArrayList filteredData = HitoriMain.getSolution(inputStream); + ArrayList filteredData = new HitoriMain().getSolution(inputStream); assertNotEquals(1, filteredData.size()); assertNotEquals(ergebnis4x4[0], filteredData.get(0)); assertNotEquals(ergebnis4x4[0], filteredData.get(1)); @@ -245,7 +245,7 @@ class HitoriTest{ {"W", "W", "W", "W"}, {"W", "W", "W", "W"}, {"W", "W", "W", "W"}}; - assertTrue(Arrays.deepEquals(colors, HitoriMain.makeColorArray(4))); + assertTrue(Arrays.deepEquals(colors, new HitoriMain().makeColorArray(4))); } @Test @@ -255,7 +255,7 @@ class HitoriTest{ {"B", "W", "W", "W"}, {"B", "W", "W", "W"}, {"B", "W", "W", "W"}}; - assertFalse(Arrays.deepEquals(colors, HitoriMain.makeColorArray(4))); + assertFalse(Arrays.deepEquals(colors, new HitoriMain().makeColorArray(4))); } @Test @@ -267,7 +267,7 @@ class HitoriTest{ {"3", "4", "3", "2"}}; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; InputStream inputStream = getClass().getResourceAsStream(path); - assertTrue(Arrays.deepEquals(data, HitoriMain.getData(inputStream, 4))); + assertTrue(Arrays.deepEquals(data, new HitoriMain().getData(inputStream, 4))); } @Test @@ -279,7 +279,7 @@ class HitoriTest{ {"3", "0", "3", "2"}}; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; InputStream inputStream = getClass().getResourceAsStream(path); - assertFalse(Arrays.deepEquals(data, HitoriMain.getData(inputStream, 4))); + assertFalse(Arrays.deepEquals(data, new HitoriMain().getData(inputStream, 4))); } @Test @@ -302,7 +302,7 @@ class HitoriTest{ } String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; InputStream inputStream = getClass().getResourceAsStream(path); - ArrayList ergebnisList = HitoriMain.readFromFile(inputStream); + ArrayList ergebnisList = new HitoriMain().readFromFile(inputStream); assertEquals(fileEntry, ergebnisList); } @@ -326,7 +326,7 @@ class HitoriTest{ } String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; InputStream inputStream = getClass().getResourceAsStream(path); - ArrayList ergebnisList = HitoriMain.readFromFile(inputStream); + ArrayList ergebnisList = new HitoriMain().readFromFile(inputStream); assertNotEquals(fileEntry, ergebnisList); } @@ -339,11 +339,11 @@ class HitoriTest{ {"B", "W", "W", "B"}}; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; InputStream inputStream = getClass().getResourceAsStream(path); - ArrayList filteredData = HitoriMain.getSolution(inputStream); + ArrayList filteredData = new HitoriMain().getSolution(inputStream); InputStream newStream = getClass().getResourceAsStream(path); int rows = 4; - String[][] data = HitoriMain.getData(newStream, rows); - assertTrue(Arrays.deepEquals(ergebnis1, HitoriMain.getErgebnisArray(data, filteredData))); + String[][] data = new HitoriMain().getData(newStream, rows); + assertTrue(Arrays.deepEquals(ergebnis1, new HitoriMain().getErgebnisArray(data, filteredData))); } @Test @@ -355,11 +355,11 @@ class HitoriTest{ {"W", "W", "W", "W"}}; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; InputStream inputStream = getClass().getResourceAsStream(path); - ArrayList filteredData = HitoriMain.getSolution(inputStream); + ArrayList filteredData = new HitoriMain().getSolution(inputStream); InputStream newStream = getClass().getResourceAsStream(path); int rows = 4; - String[][] data = HitoriMain.getData(newStream, rows); - assertFalse(Arrays.deepEquals(ergebnis1, HitoriMain.getErgebnisArray(data, filteredData))); + String[][] data = new HitoriMain().getData(newStream, rows); + assertFalse(Arrays.deepEquals(ergebnis1, new HitoriMain().getErgebnisArray(data, filteredData))); } @Test