Skip to main content
GameDev.net gamedev.net
🔒 Locked

head asplode..

Started by dusty_one Aug 5, 2007 at 9:05 PM 0 replies 1.6k views
Original Post
dusty_one
dusty_one
Nothing like a seemingly easy problem to make one feel dumb. I've got a few very basic issues that will probably be ridiculously obvious when pointed out to me: 1. I can't for the life of me figure out the math formula for how many walls there should be given a # of columns and rows. 2. What I have so far for my maze generation class is:

class MazeGen
{
    int[] rooms;
    int[][] roomSets;

    Wall wall = new Wall;
    Wall floor = new Wall;
    Wall[] walls;

    // the ? is because I don't know how many walls to make..
    public MazeGen(int h, int w)
    {
        rooms = new int[h * w];
        roomSets  = new int[rooms.Length][];
        walls = new Wall[?];
    }

}

struct Wall
{
    bool wallUp;
    int room1;
    int room2;
}


3. been trying for 3 days now to come up with how to write and iteration that will assign a floor and and wall to a room. Once I can do that I'm sure it wouldn't be that difficult to finish. 4. Drawing the maze is being a pain aswell. I can't seem to figure out how to draw a simple 3x3 grid that's aligned nicely with for loops using the '|' and '_' characters. Its stupid easy, I remember doing it in 9th grade but I don't remember how I did it. Its frustrating because almost all of my hang ups feel like they're on the tip of my brain but just won't go over.
JWalsh
JWalsh
Regarding #1...

First, you must know how many rooms you have...given numRows rows and numColumnsColums, you'll have

int numRooms = numRows * numColumns;

Now, we know that "every room" has 2 walls, a right wall, and a bottom wall. So if we take the number of rooms and multiply it by 2, we'll get the number of walls....sortof.

int numWalls = numRooms * 2;

I say "sortof" because the right most rooms only have 1 wall...a bottom wall. So that means that every row in the right column is minus one wall...well, that's the same as the number of rows...so really we've got...

numWalls -= numRows;

However, all of the rooms on the bottom row only have 1 wall also...that is, they've only got a side wall. So, every column in the bottom row is minus 1 wall. Well, that's the same as numColumns. So really we've got...

numWalls -= numColumns;

Put all together that's...

int numRooms = numRows * numColumns;
int numWalls = numRooms * 2;
numWalls -= numRows;
numWalls -= numColumns;

Another way, with everything collapsed...

int numWalls = (numRows * numColumns * 2) - numRows - numColumns;

Now that you've got that, lets see if you can move forward.

Remember...

1. Calculate number of rooms and columns
2. Allocate memory
3. Initialize rooms, sets, and walls to starting values
4. Randomly permutate walls
5. Knock down walls sequentially
6. Print the standing walls to the screen

Take each of the above items one at a time...when you get stuck...ask for help.

Cheers!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.