-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreateMaze.java
executable file
·37 lines (36 loc) · 1.04 KB
/
CreateMaze.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import javax.imageio.ImageIO;
public class CreateMaze{
public static void main(String[] args) throws IOException{
//load in the maze strings
ArrayList<String> lines = new ArrayList<String>();
Scanner s = new Scanner(new File("maze.txt"));
while(s.hasNextLine()){
lines.add(s.nextLine());
}
s.close();
int rows = lines.size();
int columns = lines.get(0).length();
int width = columns*2;
int height = rows*2;
//draw maze on an image
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
for(int r=0; r<rows; r++){
for(int c=0;c<columns;c++){
if(lines.get(r).charAt(c) != 'A'){
g.fillRect(c*2-14,r*2-14,28,28);
}
}
}
g.dispose();
//save the image
ImageIO.write(image,"png",new File("maze.png"));
}
}