Add load maze
This commit is contained in:
1 parent
9d6b6a286f
commit
3cdf425435
10 files changed
+81
-176
No files matched your search
@@ -1,5 +1,8 @@
|
||||
package model;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
@@ -40,4 +43,34 @@ public class MazeAppModel extends Observable {
|
||||
public void saveToFile(String filename) {
|
||||
maze.saveToTextFile(filename);
|
||||
}
|
||||
|
||||
public void paintMaze(Graphics2D g, int width, int height) {
|
||||
|
||||
int dimensionX = maze.getDimensionX();
|
||||
int dimensionY = maze.getDimensionY();
|
||||
int boxWidth = width/dimensionX;
|
||||
int boxHeight = height/dimensionY;
|
||||
|
||||
for (int line = 0; line < dimensionY; line++) {
|
||||
for (int row = 0; row < dimensionX; row++) {
|
||||
if (maze.getMaze()[line][row].isWalkable()) {
|
||||
if (maze.getMaze()[line][row].isDeparture()) {
|
||||
g.setColor(Color.GREEN);
|
||||
}
|
||||
else if (maze.getMaze()[line][row].isArrival()) {
|
||||
g.setColor(Color.RED);
|
||||
}
|
||||
else {
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
}
|
||||
else {
|
||||
g.setColor(Color.WHITE);
|
||||
}
|
||||
g.fill3DRect(row*boxWidth, line*boxHeight,
|
||||
boxWidth, boxHeight,
|
||||
true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user