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 5fbf074..a1ba9d4 100644 --- a/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/domain/HitoriMain.java +++ b/PR2Projekt/src/de/hs_mannheim/informatik/pr2projekt/domain/HitoriMain.java @@ -73,7 +73,7 @@ public class HitoriMain extends JFrame implements AcrtionListener{ return buttons; } - private static boolean abgabeMöglich(String path, String[][] data, String[][] colors) throws FileNotFoundException{ + public static boolean abgabeMöglich(String path, String[][] data, String[][] colors) throws FileNotFoundException{ boolean abgabeMöglich = false; String[][] result = getResult(data, colors); ArrayList filteredData = getSolution(path, result); @@ -95,4 +95,137 @@ public class HitoriMain extends JFrame implements AcrtionListener{ } 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 backOneStep(Stack movesMade, JButton[][] buttons, String[][] colors, JPanel grid){ + try { + String move = movesMade.pop(); + String[] line = move.split("\\."); + String y = line[0]; + String x = line[1]; + String color = line[2]; + if(color.equals("W")){ + int i = Integer.parseInt(y); + int j = Integer.parseInt(x); + JButton b0 = buttons[i][j]; + b0.setOpaque(true); + b0.setForeground(Color.WHITE); + b0.setContentAreaFilled(true); + b0.setBorderPainted(false); + b0.setFocusPainted(false); + b0.setBackground(Color.BLACK); + buttons[i][j] = b0; + String str = colors[i][j]; + String str0 = str.substring(0, str.length() - 1); + colors[i][j] = str0; + grid.repaint(); + gridUpdate(grid, buttons); + }else if(color.equals("G")){ + int i = Integer.parseInt(y); + int j = Integer.parseInt(x); + JButton b0 = buttons[i][j]; + b0.setOpaque(true); + b0.setForeground(Color.BLACK); + b0.setContentAreaFilled(true); + b0.setBorderPainted(false); + b0.setFocusPainted(false); + b0.setBackground(Color.WHITE); + buttons[i][j] = b0; + String str = colors[i][j]; + String str0 = str.substring(0, str.length() - 1); + colors[i][j] = str0; + gridUpdate(grid, buttons); + } else if(color.equals("B")){ + int i = Integer.parseInt(y); + int j = Integer.parseInt(x); + JButton b0 = buttons[i][j]; + b0.setOpaque(true); + b0.setForeground(Color.BLACK); + b0.setContentAreaFilled(true); + b0.setBorderPainted(false); + b0.setFocusPainted(false); + b0.setBackground(Color.lightGray); + buttons[i][j] = b0; + String str = colors[i][j]; + String str0 = str.substring(0, str.length() - 1); + colors[i][j] = str0; + gridUpdate(grid, buttons); + } + } catch(EmptyStackException e) {} + } + + public static void totalResetButton(JButton[][] buttons, String[][] colors,Stack madeMoves,String[][] data){ + madeMoves.clear(); + for(int i = 0; i getSolution(String path, String[][] result) throws FileNotFoundException{ + Scanner sc = new Scanner(new File(path)); + ArrayList 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 filteredData){ + String[][] ergebnis = new String[result.length][result.length]; + for(int i=0;i= 0 && row < ergebnis.length && col >= 0 && col < ergebnis[row].length) { + ergebnis[row][col] = "B"; + } + } + return ergebnis; + } }