Skip to content

Commit

Permalink
Fix a refactoring issue
Browse files Browse the repository at this point in the history
maze -> mazesolver -> maze
  • Loading branch information
ApolloZhu committed Dec 4, 2017
1 parent e84bac0 commit f82968c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
13 changes: 7 additions & 6 deletions src/io/github/apollozhu/mazesolver/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Welcome to Maze Solver.\n" +
"1. Solve Mr. Lau's mazesolver (default)\n" +
"2. Randomly generates a mazesolver to solve\n" +
"1. Solve Mr. Lau's maze (default)\n" +
"2. Randomly generates a maze to solve\n" +
"> ");
CHECK:
try {
Expand Down Expand Up @@ -70,9 +70,10 @@ public static void main(String[] args) {
} while (!findAnExit(startX, startY, targetX, targetY)
&& print("Still trapped inside!"));

System.out.println("Successfully exit the mazesolver!!!");
System.out.println("Successfully exit the maze!!!");

// display the path (indicated by 7) that leads to the exit of the mazesolver
// display the path (indicated by 7)
// that leads to the exit of the maze
// also display locations tried
MazeCoder.print(grid);
}
Expand All @@ -90,7 +91,7 @@ private static boolean findAnExit(int x, int y, int tR, int tC) {
/*
7 8
[7,8][7,9][7,10][7,11][7,12]
Successfully exit the net.fcpsschools._1685666.mazesolver!!!
Successfully exit the maze!!!
3 3 3 0 3 3 0 0 0 3 3 3 3
3 0 3 3 3 0 3 3 3 3 0 0 3
Expand All @@ -106,7 +107,7 @@ private static boolean findAnExit(int x, int y, int tR, int tC) {
0 0
[0,0][0,1][0,2][1,2][1,3][1,4][2,4][3,4][3,5][3,6][2,6][1,6][1,7][1,8][2,8][3,8][4,8][4,7][5,7][5,6][5,5][5,4][5,3][5,2]
[4,2][3,2][3,1][3,0][4,0][5,0][6,0][7,0][7,1][7,2][7,3][7,4][7,5][7,6][7,7][7,8][7,9][7,10][7,11][7,12]
Successfully exit the net.fcpsschools._1685666.mazesolver!!!
Successfully exit the maze!!!
7 7 7 0 1 1 0 0 0 1 1 1 1
3 0 7 7 7 0 7 7 7 1 0 0 1
Expand Down
4 changes: 2 additions & 2 deletions src/io/github/apollozhu/mazesolver/controller/MazePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ public void mouseClicked(MouseEvent e) {
MazeFile.Info info = MazeFile.chooseMaze(this);
if (info == null) return;
if (loadMap(info)) JOptionPane.showMessageDialog(this,
"Successfully loaded the mazesolver",
"Successfully loaded the maze",
"Loaded!", JOptionPane.INFORMATION_MESSAGE);
else JOptionPane.showMessageDialog(this,
"Something went wrong when opening the mazesolver.",
"Something went wrong when opening the maze.",
"Failed!", JOptionPane.ERROR_MESSAGE);
});

Expand Down
18 changes: 9 additions & 9 deletions src/io/github/apollozhu/mazesolver/model/MazeFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public enum MazeFile {

public static boolean saveMaze(Component parent, Info info) {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Save mazesolver document in...");
chooser.setDialogTitle("Save maze document in...");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (chooser.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) {
String path = MazeFile.write(info, chooser.getSelectedFile().getPath());
if (path == null) JOptionPane.showMessageDialog(parent,
"Something went wrong when saving the mazesolver.",
"Something went wrong when saving the maze.",
"Failed!", JOptionPane.ERROR_MESSAGE);
else {
JOptionPane.showMessageDialog(parent,
Expand All @@ -34,7 +34,7 @@ public static boolean saveMaze(Component parent, Info info) {
return true;
}
} else JOptionPane.showMessageDialog(parent,
"You didn't choose a directory to save the mazesolver.",
"You didn't choose a directory to save the maze.",
"Cancelled!", JOptionPane.WARNING_MESSAGE);
return false;
}
Expand All @@ -47,7 +47,7 @@ public static String write(Info info, String directory) {
sb.append(info.start.getR()).append('_');
sb.append(info.start.getC()).append('_');
sb.append(info.end.getR()).append('_');
sb.append(info.end.getC()).append(".mazesolver");
sb.append(info.end.getC()).append(".maze");
String fileName = sb.toString();
Logger.getGlobal().log(Level.INFO, fileName);

Expand All @@ -57,28 +57,28 @@ public static String write(Info info, String directory) {
Files.write(path, toByteArray(info.map));
return path.toAbsolutePath().toString();
} catch (Throwable e) {
Logger.getGlobal().log(Level.WARNING, "Failed to save mazesolver", e);
Logger.getGlobal().log(Level.WARNING, "Failed to save maze", e);
return null;
}
}

public static Info chooseMaze(Component parent) {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Open mazesolver document");
chooser.setDialogTitle("Open maze document");
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setFileFilter(new FileNameExtensionFilter("Maze (*.mazesolver)", "mazesolver"));
chooser.setFileFilter(new FileNameExtensionFilter("Maze (*.maze)", "maze"));
if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION)
return MazeFile.read(Paths.get(chooser.getSelectedFile().getAbsolutePath()));
JOptionPane.showMessageDialog(parent,
"You didn't choose a mazesolver.",
"You didn't choose a maze.",
"Cancelled!", JOptionPane.WARNING_MESSAGE);
return null;
}

public static Info read(Path file) {
try {
int[] comp = Arrays.stream(file.getFileName().toString()
.replace(".mazesolver", "").split("_"))
.replace(".maze", "").split("_"))
.mapToInt(Integer::parseUnsignedInt).toArray();
if (comp.length < 6) return null;
MazeBlock[][] map = fromByteArray(Files.readAllBytes(file), comp[0], comp[1]);
Expand Down

0 comments on commit f82968c

Please sign in to comment.