All the source is there on that page and is free to use. It's an infinitely scalable maze generating/solving algorithm, although it won't work exactly for Pac-Man. You'll have to tweak it so that there's more than one solvable path to a single location.

;)than you, the maze which i want it called block grid maze which is use for pac-man I have the code but it not work and there are many errors and I can not solve it.I hope anyone have idea or the code can I used for my game. thanks

;)than you, the maze which i want it called block grid maze which is use for pac-man I have the code but it not work and there are many errors and I can not solve it.I hope anyone have idea or the code can I used for my game. thanks

I already gave you a link to the source code of an advanced maze generator. That's more than most will do, as your question is ambiguous and simply cannot be answered. Post a specific question with attached source and maybe you'll get a response.

:)thank you for the link, but I dont understand it, you have code is easy than this.you know it is the first time I used java to create gameI am sorry because I ask so much

Hi

Demonpants gave you some excellent suggestions. If you don't understand the source code, maybe you should rather improve your skills in Java and algorithmic before attempting to create a game. On my view, yes, you ask too much. You can look at sourceforge.net, there are some other examples of PacMan in Java and in other languages.

The maze generator class is not very long at all. See, I can post the whole thing within a single JGO post. It's also well commented. And for you experienced JGOers, I know I do some lazy things in this code. This also tends to generates mazes where the solution goes from top-left to bottom-left to bottom-right because it generates it through for loops. I have a much improved version but it's significantly more complicated, so I figured now is not the time to show it.

/** * This class generates a random solvable maze by first filling in a maze with walls, * then charting a path from the start to the finish (top left to bottom right), then * giving every other piece of the path a random number of exits, until every * space has been evaluated. * @author Eli Delventhal * */

//import java.util.Stack;importjava.util.ArrayList;

publicclassMazeGenerator{//Can be changed for mazes that are more than two dimensions.publicstaticfinalintNUM_DIRECTIONS = 4;

//The indeces for the different possible directions. Add more for//mazes that are more than two dimensions.publicstaticfinalintUP = 0;publicstaticfinalintLEFT = 1;publicstaticfinalintRIGHT = 2;publicstaticfinalintDOWN = 3;

/** * Generates a random solvable maze with the top left corner as the start, * with no goal yet specified. The maze has the specified width and height * in terms of number of rooms, and is awlays rectangular. * @param width The width of the maze. * @param height The height of the maze. * @return A solvable maze with the matched width and height. */publicstaticRoom[][] generateMaze(intwidth, intheight) {returngenerateMaze(width,height,null); }

/** * Generates a random solvable maze with the top left corner as the start, * with no goal yet specified. The maze has the specified width and height * in terms of number of rooms, and is awlays rectangular. * @param width The width of the maze. * @param height The height of the maze. * @param frame The JFrame that should be repainting. If null, no pausing or painting. * @return A solvable maze with the matched width and height. */publicstaticRoom[][] generateMaze(intwidth, intheight, Mainframe) {//Initialize the maze with no rooms at all (all set to null).Room[][] maze = newRoom[width][height];

//Visit all spaces in the maze at least once.for (inti = 0; i < width; i++) {for (intj = 0; j < height; j++) {//As we get to a point in the maze, we need to create a room there//if there isn't one. Then we need to construct a path from that room.if (maze[i][j] == null)constructRoom(maze,i,j,newArrayList<Integer>(),frame);

//If there is already a room, we simply skip onwards. } }

returnmaze; }

/** * Constructs a room of the maze at the specified i and j positions. * It will then continue to call itself until it reaches a point * where it can no longer create more rooms. * @param maze The maze to work with. * @param i The i position to start with. * @param j The j position to start with. * @param checkedDirs The directions that have already been checked. * @param frame The frame to tell to repaint. */privatestaticvoidconstructRoom(Room[][] maze, inti, intj, ArrayList<Integer> checkedDirs, Mainframe) {//If all four directions have been tried, return from the function.if (checkedDirs.size() >= NUM_DIRECTIONS)return;

//Open up a random direction for this room. If that//direction already has a room,//try a different direction. If there is no room there,//call this function at the new position.intdirection = (int) (Math.random() * NUM_DIRECTIONS);if (!checkedDirs.contains(direction)) {//Add the current direction to the ones checked.checkedDirs.add(direction);

//Tell the main class to paint if it has been specified.if (frame != null) {frame.setMaze(maze);frame.repaint();try {Thread.sleep(frame.getDrawDelay());} catch(Exceptione) {} } }}

Here is the Room class it relies on.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

packagemm;

/** * A Room is a very simple object that contains 4 booleans determining where it has * walls. These walls can be at the north, south, east, or west. These are public * instance variables for simplicity's sake. By default, a room is entirely closed. * @author Eli Delventhal * */publicclassRoom{publicboolean[] open;publicinti;publicintj;

If you can't get your head around those, you've got some more learning to do. Why not start with pre-made levels so you can practice Java then come back to more advanced techniques later? Or why not just download my source, run it on your machine, then edit it so you have Pac-Man running around? The best way to learn it all is to mess around with it, rather than simply staring at it and saying "I don't understand this."

in [size=10pt]Main frame[/size]what you mean (main frame) and it not delacer (what it's type)

I thought you might ask that. This is simply a reference to the main window in the app that the maze generator is included in so that you can visually see what is happening as it is created (it updates the draw to reflect the maze). You can delete all the references to Main as well as that parameter.

I know I asked too much but I don't understand what you main I will tell some thing I am just student and I don't have iead how to do game by javabut what can I do, because the pac-man game is my project and I must submit after two weekscan you help meI am ready to learn more to do it

By deleting all the references to Main, you would for example do this:

//Was this:Main main;foo(bar);

//Becomes this:foo(bar);

If you know how to use a word processor you should be able to delete any references (should I say "mentions" to be more understandable) to Main.

That's with all the references deleted. If you can't solve such a simple type of syntax error and didn't understand what I meant about deleting the references, you should probably not be working on Pac-Man. Instead, start with something like a bunch of balls bouncing around. Note that the program I linked was one of the very first "games" I made in Java. You've got to start a lot smaller than Bomberman or you'll just be pulling your hair out. Also, I slowly over time added on to this bounce ball game, I didn't do it all at once. As I learned different things I would implement them.

/** * This class generates a random solvable maze by first filling in a maze with walls, * then charting a path from the start to the finish (top left to bottom right), then * giving every other piece of the path a random number of exits, until every * space has been evaluated. * @author Eli Delventhal * */

importjava.util.ArrayList;

publicclassMazeGenerator{//Can be changed for mazes that are more than two dimensions.publicstaticfinalintNUM_DIRECTIONS = 4;

//The indeces for the different possible directions. Add more for//mazes that are more than two dimensions.publicstaticfinalintUP = 0;publicstaticfinalintLEFT = 1;publicstaticfinalintRIGHT = 2;publicstaticfinalintDOWN = 3;

/** * Generates a random solvable maze with the top left corner as the start, * with no goal yet specified. The maze has the specified width and height * in terms of number of rooms, and is awlays rectangular. * @param width The width of the maze. * @param height The height of the maze. * @return A solvable maze with the matched width and height. */publicstaticRoom[][] generateMaze(intwidth, intheight) {//Initialize the maze with no rooms at all (all set to null).Room[][] maze = newRoom[width][height];

//Visit all spaces in the maze at least once.for (inti = 0; i < width; i++) {for (intj = 0; j < height; j++) {//As we get to a point in the maze, we need to create a room there//if there isn't one. Then we need to construct a path from that room.if (maze[i][j] == null)constructRoom(maze,i,j,newArrayList<Integer>());

//If there is already a room, we simply skip onwards. } }

returnmaze; }

/** * Constructs a room of the maze at the specified i and j positions. * It will then continue to call itself until it reaches a point * where it can no longer create more rooms. * @param maze The maze to work with. * @param i The i position to start with. * @param j The j position to start with. * @param checkedDirs The directions that have already been checked. */privatestaticvoidconstructRoom(Room[][] maze, inti, intj, ArrayList<Integer> checkedDirs) {//If all four directions have been tried, return from the function.if (checkedDirs.size() >= NUM_DIRECTIONS)return;

//Open up a random direction for this room. If that//direction already has a room,//try a different direction. If there is no room there,//call this function at the new position.intdirection = (int) (Math.random() * NUM_DIRECTIONS);if (!checkedDirs.contains(direction)) {//Add the current direction to the ones checked.checkedDirs.add(direction);

:)than you my dearsI got the source code of pac-man and I download some java books and I read it .I understand some basic iead about java and the basic concepts in the java.I will do the bast in my project.than you for your help

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org