Results 1 to 2 of 2
Thread: Need help with Maze project.
- 01-06-2011, 05:02 PM #1
Member
- Join Date
- Jan 2011
- Location
- Glasgow, Scotland.
- Posts
- 1
- Rep Power
- 0
Need help with Maze project.
I've been searching the internet for a few days now looking for an answer to my problem but I honestly couldn't find anything similar to my program mainly due to the fact we are using the TextIO class to read the text file.
The task is
"You are required to write a program that will load a simple maze from a text file, display this on the
screen and allow the user to guide an on-screen marker to the maze exit. The maze is defined as a
grid of characters in the file with the following
character definitions:
0 = maze wall
1 = maze floor
2 = maze entrance
3 = maze exit
E.g. This is a 39*25 maze.
020000000000000000000000000000000000000
010111011111010101111111110111111101110
010001000100010101010001000101000001000
010111110101011101010101110101110111110
010001000101000101000101000100000100000
011101111101011111010101011101010111110
010000010001010000010100000101010100000
011101111101110111011111011101111101010
010000010000010001010000000101010001010
011111011101110101111101111111011111110
010000010000010101010001000100010101010
010101011111111111011111011111010101010
010101010001000000000000000100000001010
010101010101010101110101011111110111010
010101010100010101000101010000000000000
011111111111111111110101010111111101010
000001000100010100000101000001000001010
011111011111010111011111011111111111110
010101010101000001000100010001000001000
010101010101111101111111111101110111110
010100010001010001000000010100000000000
010101110101010111111101110111111111110
000001000101010101000100000100000101010
011111111101010101011111011111110101010
000000000000000000000000000000000000030
And I've managed to draw the maze up but the thing I am stumped with is this. :S
"Place a game character at the entrance of the maze (this character could be represented by a
number or letter (e.g. 9 or A) or some other character of your choice)."
This is my code so far:
public class Main {
public static void main(String[] args) {
TextIO.readFile("sample_maze.txt");
// sample_maze2.txt has a line with two numbers on it saying how many rows and
// how many columns of characters there are in the rest of the file.
// All calls to TextIO.get methods read now read from sample_maze2.txt.
int rows = TextIO.getInt(); // this is the number of rows in the file (maze)
int cols = TextIO.getlnInt(); // this is the number of columns in the file (maze)
char[][] array = new char[rows][cols];
// Each line of sample_maze.txt contains cols number of characters
// and there are rows number of lines
for (int i=0; i < rows; i++) {
for (int j=0; j < cols; j++) {
array[i][j] = TextIO.getChar();
}
TextIO.getln();
}
TextIO.readStandardInput(); // This closes the file
TextIO.putln("Display the maze using 'maze' characters:");
// In the maze project, whenever you read a '0' you display a wall character
// whenever you read a '1' you display a path character
// whenever you read a '2' you display an entrance character
// whenever you read a '3' you display an exit character
for (int i=0; i < rows; i++) {
for (int j=0; j < cols; j++) {
if (array[i][j]=='0') TextIO.put('\u2588');
if (array[i][j]=='1') TextIO.put('\u4500');
if (array[i][j]=='2') TextIO.put('S');
if (array[i][j]=='3') TextIO.put("F");
}
TextIO.putln();
}
}
}
Any ideas? :S
- 01-06-2011, 05:14 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,407
- Blog Entries
- 7
- Rep Power
- 17
So basically your character can never move to a square with a '0' in it (It's a wall); it starts at the position with a '2' in it and ends at the position with a '3' in it. The character can move up, down, left or right. Is this a start for you if you use a simple two dimensional array of chars?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Solving a Maze
By bdario1 in forum New To JavaReplies: 4Last Post: 04-14-2010, 12:02 AM -
help in maze code
By air in forum New To JavaReplies: 15Last Post: 04-01-2009, 08:20 AM -
Maze
By soriano in forum New To JavaReplies: 1Last Post: 12-16-2008, 05:40 PM -
3D Maze
By EternalSolitude in forum New To JavaReplies: 5Last Post: 11-14-2008, 12:51 AM -
Maze Help
By Soda in forum Advanced JavaReplies: 1Last Post: 12-22-2007, 03:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks