added getData and readfromfile method to read the csv files
parent
319dd29405
commit
c7fcabd287
|
@ -22,4 +22,31 @@ public class HitoriMain extends JFrame implements AcrtionListener{
|
|||
JButton[][] buttons = makeButtonArray(data);
|
||||
GameGUI.paintGame(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{
|
||||
String filepath0 = filepath;
|
||||
Scanner sc = new Scanner(new File(filepath0));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue