I4d like to create a maze in actionscript 3 but without drawing it because a lot of people are saying that timeline code and drawing things is bad so i'd like to create it with an array. I've searched on google and looked over a lot of tutorials, all doing it differently but not one of them uses classes and all that stuff and I'd really like to do it. I have the idea of how to do it, using an array filled with different numbers of characters if there's a wall, nothing etc... And i know how to draw the block with the graphics things then put a if loop and if the number is 0 put nothing if the number is 1 create the block and place it, but then i'm a bit lost on HOW to make the block appear at the same spot where there is a 1 in the array, I looked at tuts where they did something with rows but I couldn't really understand it clearly. And also I'm not sure if i have to create a new class for the block, and what do I have to put in this class if i do create it? Do i need to create the block in the class, or outside of it? =/

If someone knows what I mean then all help is welcome. If you need more details please tell me, sorry if it's confused. =3

有帮助吗?

解决方案

It looks like your best bet, your path of least resistance in the long run, may lie in doing a little bit more study and some smaller programs before embarking on this. However if you want a 2D maze made with an Array, you could just do this:

private var m_arrMaze:Array = new Array(40);

private function someFunc():void
{
    for (var i:int = 0; i < m_arrMaze.length; i++)
    {
        m_arrMaze[i] = new Array(50);
    }

    m_arrMaze[0][0] = 1;
    m_arrMaze[0][1] = 1;
    .
    .
    .
    m_arrMaze[24][24] = 3;
    .
    .
    .
    m_arrMaze[49][49] = 0;
}

This is because you seemed to mention using an array and setting its elements to certain int values to denote what each little spot or room or whatever in the maze is or has. The reason a lot of tutorials may not use a whole lot of classes is because, if this is all you're doing with it, you really don't need too many different classes to denote the stuff in the maze. Just instead of using hard-coded int values, go ahead and put them in constants at the top of your maze class:

private static const EMPTY_SPACE:int = 0;
private static const WALL:int = 1;
.
.
.
private static const PLAYER:int = 3;

private var m_arrMaze:Array = new Array(40);

private function someFunc():void
{
    for (var i:int = 0; i < m_arrMaze.length; i++)
    {
        m_arrMaze[i] = new Array(50);
    }

    m_arrMaze[0][0] = WALL;
    m_arrMaze[0][1] = WALL;
    .
    .
    .
    m_arrMaze[24][24] = PLAYER;
    .
    .
    .
    m_arrMaze[49][49] = EMPTY_SPACE;
}

If each type of contents within the maze is liable to have a whole different set of nouns, verbs, and adjectives associated with it, instead of just being a different type of marker of where something's at like in the examples above, and if the program is going to do a lot of different things with those contents, that's when you want to use a whole bunch of different classes. Hopefully this will get you started.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top