Thread: Maze

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question Maze

    I'm using Borland C++. I've created a Maze editor with a start, end and an arena, but how would I make individual walls in the inside... What kind of code might I use?

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    gotoxy(xcord,ycord);
    cout<<"|";//can output anything else for wall

  3. #3
    Unregistered
    Guest
    depends on how you set up the arena.

  4. #4
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Exclamation Question

    That didn't answer my question... what kind of function could I use for walls? I've tried locationx=locationx-1; but it waits till you move to actually push you back... And anyway I just want the wall to stop the character not move it.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    27
    i guess u should check whether u are allowed to move before you try to do it. in short: if not then stop else move...

  6. #6
    Unregistered
    Guest
    the simplest mazes are 2D char arrays with walls identified by a given char, frequently '|', but it could be anything. Let's say you had an arena declared as: char arena[3][3]; with enter being an E at (0, 0) and stop portrayed as an X at (2, 2). Let's also say there is a wall at (0, 1) and (1, 1) but all the other "spots"/"cells" are 0's. then the arena would look like this:

    E|0
    0|0
    00X

    Obviously, if the arena were bigger, you could put in more walls, etc. You read the value of a given "cell" to determine whether it is a valid move or a wall or whatever. But you should get the picture.

    If, on the other hand, each cell is considered to be an instance of class that not only has a member variable to indicate whether it has been visited or not but also has 4 member variables to represent the four possible walls used in 2D; then things could get a bit busier.

    And if the arena is a 3D array or if it is an object like a bitmap etc then it get's busier, and more exciting/interesting, at the same time.

    So it really depends on how you have the arena set up as to how you create/depict walls, etc.

  7. #7
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Code

    Can you show me sample code... I understood your responce but i'm not so sure how to interpret it into c++.

  8. #8
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Nevermind

    I figured out my glitch with gotoxy.

  9. #9
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Update

    Ok, I'm back. I used gotoxy for the arena, start and finished. How might I got about puting walls(that actually block the asterisk) into the code. Here Is my code:

    //Filename: lv1.cpp
    //Function: Level 1
    #include <conio.h>
    #include <iostream.h>
    #define left arrow = 'A'
    #define up arrow = 'Q'
    #define down arrow = 'Z'
    #define right arrow = 'S'
    void main()
    {
    int stx=1;
    int sty=1;
    int ndx=3;
    int ndy=3;
    int w1x=2;
    int w1y=1;
    int w2x=2;
    int w2y=2;
    int arnx=4;
    int arny=4;
    int psty=1;
    int pstx=1;
    cout << " ~ASTERISK MAN~" << endl << endl;
    cout << " CONTROLS: " << endl;
    cout << " A Left" << endl;
    cout << " S Right" << endl;
    cout << " Q Up" << endl;
    cout << " Z Down" << endl;
    int lp=1;
    while(lp!=0)
    {
    char ch;
    ch = getch();
    if(ch == 'S')
    {
    gotoxy(stx, sty);
    cout << "$";
    gotoxy(ndx, ndy);
    cout << "@";
    gotoxy(w1x, w1y);
    cout << "#";
    gotoxy(pstx, psty);
    cout << " ";
    pstx=pstx+1;
    gotoxy(2, 1);
    gotoxy(pstx, psty);
    cout << "*";
    gotoxy(stx, sty);
    cout << "$";
    gotoxy(ndx, ndy);
    cout << "@";
    }
    if(ch == 'A')
    {
    gotoxy(stx, sty);
    cout << "$";
    gotoxy(ndx, ndy);
    cout << "@";
    gotoxy(w1x, w1y);
    cout << "#";
    gotoxy(pstx, psty);
    cout << " ";
    pstx=pstx-1;
    gotoxy(2, 1);
    gotoxy(pstx, psty);
    cout << "*";
    gotoxy(stx, sty);
    cout << "$";
    gotoxy(ndx, ndy);
    cout << "@";
    }
    if(ch == 'Q')
    {
    gotoxy(stx, sty);
    cout << "$";
    gotoxy(ndx, ndy);
    cout << "@";
    gotoxy(w1x, w1y);
    cout << "#";
    gotoxy(pstx, psty);
    cout << " ";
    psty=psty-1;
    gotoxy(2, 1);
    gotoxy(pstx, psty);
    cout << "*";
    }
    if(ch == 'Z')
    {
    gotoxy(stx, sty);
    cout << "$";
    gotoxy(ndx, ndy);
    cout << "@";
    gotoxy(w1x, w1y);
    cout << "#";
    gotoxy(pstx, psty);
    cout << " ";
    psty=psty+1;
    gotoxy(pstx, psty);
    cout << "*";
    gotoxy(stx, sty);
    cout << "$";
    gotoxy(ndx, ndy);
    cout << "@";
    }
    if(psty==arny)
    {
    gotoxy(stx, sty);
    cout << "$";
    gotoxy(ndx, ndy);
    cout << "@";
    gotoxy(w1x, w1y);
    cout << "#";
    gotoxy(pstx,psty);
    cout << " ";
    psty=arny-1;
    gotoxy(pstx, psty);
    cout << "*";
    gotoxy(stx, sty);
    cout << "$";
    gotoxy(ndx, ndy);
    cout << "@";
    }
    if(pstx==arnx)
    {
    gotoxy(stx, sty);
    cout << "$";
    gotoxy(ndx, ndy);
    cout << "@";
    gotoxy(w1x, w1y);
    cout << "#";
    gotoxy(pstx,psty);
    cout << " ";
    pstx=arnx-1;
    gotoxy(pstx, psty);
    cout << "*";
    gotoxy(stx, sty);
    cout << "$";
    gotoxy(ndx, ndy);
    cout << "@";
    }
    if(pstx==ndx)
    {
    if(psty==ndy)
    {
    lp=0;
    }
    }
    if(pstx==w1x-1)
    {
    if(psty==w1y)
    {
    gotoxy(pstx, psty);
    cout << " ";
    gotoxy(w1x, w1y);
    cout << "#";
    pstx=w1x-1;
    gotoxy(pstx, psty);
    cout << "*";
    }
    }
    }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble solving maze.
    By eurus in forum C Programming
    Replies: 3
    Last Post: 02-17-2006, 01:52 AM
  2. Q: Recursion to find all paths of a maze
    By reti in forum C Programming
    Replies: 7
    Last Post: 11-26-2002, 09:28 AM
  3. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM
  4. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 01:54 AM
  5. Maze game, complete with maze editor and an example maze!
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-20-2002, 03:27 AM