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?
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?
gotoxy(xcord,ycord);
cout<<"|";//can output anything else for wall
depends on how you set up the arena.
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.
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...
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.
Can you show me sample code... I understood your responce but i'm not so sure how to interpret it into c++.
I figured out my glitch with gotoxy.
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 << "*";
}
}
}
}