Merge remote-tracking branch 'origin/master'
commit
848d64c11b
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -202,23 +202,6 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
||||||
return flippedImage;
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -12,4 +12,6 @@
|
||||||
00000000
|
00000000
|
||||||
00000000
|
00000000
|
||||||
00000000
|
00000000
|
||||||
|
00000000
|
||||||
|
00000000
|
||||||
11111111
|
11111111
|
|
@ -3,8 +3,9 @@ import java.util.ArrayList;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class MapReader {
|
public class MapReader {
|
||||||
|
//Input game map
|
||||||
public static void inputMap(ArrayList<Tile> map, String filePath) throws IOException {
|
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 x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
for(int i=0; i<file.length(); i++){
|
for(int i=0; i<file.length(); i++){
|
||||||
|
|
Loading…
Reference in New Issue