Merge remote-tracking branch 'origin/master'

master
John 2022-06-03 13:10:05 -04:00
commit 848d64c11b
4 changed files with 29 additions and 18 deletions

25
src/FileManager.java Normal file
View File

@ -0,0 +1,25 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class FileManager {
public static void writeFile(String fileLocation, String writeString) throws IOException {
File newFile = new File(fileLocation);
FileWriter fileWriter = new FileWriter(newFile);
fileWriter.write(writeString);
fileWriter.close();
}
// will create file if it doesn't exist
public static String readFile(String fileLocation) throws IOException {
File newFile = new File(fileLocation);
if (newFile.createNewFile()) {
return null;
} else {
Scanner fileReader = new Scanner(newFile);
// using the delimiter \\Z reads the entire file at once
return fileReader.useDelimiter("\\Z").next();
}
}
}

View File

@ -202,23 +202,6 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
return flippedImage;
}
public static void writeFile(String fileLocation, String writeString) throws IOException {
File newFile = new File(fileLocation);
FileWriter fileWriter = new FileWriter(newFile);
fileWriter.write(writeString);
fileWriter.close();
}
// will create file if it doesn't exist
public static String readFile(String fileLocation) throws IOException {
File newFile = new File(fileLocation);
if (newFile.createNewFile()) {
return null;
} else {
Scanner fileReader = new Scanner(newFile);
// using the delimiter \\Z reads the entire file at once
return fileReader.useDelimiter("\\Z").next();
}
}
}

View File

@ -12,4 +12,6 @@
00000000
00000000
00000000
00000000
00000000
11111111

View File

@ -3,8 +3,9 @@ import java.util.ArrayList;
import java.util.Scanner;
public class MapReader {
//Input game map
public static void inputMap(ArrayList<Tile> map, String filePath) throws IOException {
String file = GamePanel.readFile(filePath);
String file = FileManager.readFile(filePath);
int x = 0;
int y = 0;
for(int i=0; i<file.length(); i++){