Hi guys!
I'm beginner on the scene and I'm trying to make an ascii maze game.
I have managed out how to get the character to move and how to make a goal where to go. But now I have faced a problem...the walls.
I'm not sure how should I do the walls so that the character wouldn't go on / trough them. This is where I need your help.

At the moment my game looks like that in the picture (of course there will be lots and lots of more walls later).
' * ' represents my character which is moving with keys W, S, A, D.
# = wall
[ ] = goal

So the problem is: * should not go on #. :D But how?
I'm using Borland C++ 4.5.
Here is my code:

#include <iostream.h>
#include <conio.h>


int main(void)
{
	int a=2, b=2, x;
// *************************************
for (int c = 1; c<24; c++){
	gotoxy(1,c);
	cout<<"#";

	gotoxy(76,c);
	cout<<"#";
}

for (int d = 1; d<77; d++){
	gotoxy(d,1);
	cout<<"#";

	gotoxy(d,23);
	cout<<"#";
}
	gotoxy(25,5);
	cout<<"#";

	gotoxy(25,6);
	cout<<"#";

	gotoxy(25,7);
	cout<<"#";


	gotoxy(72,21);
	cout<<"[ ]";

// *************************************
while((a!=73) || (b!=21))
{
	gotoxy(a,b);
	{
	cout<<"*";
	}

if ( kbhit()==1)
{
	x = getch();
	cout<<"\b";

if ((x==119) && (b>2))
	b--;

if ((x==115) && (b<22))
	b++;

if ((x==97) && (a>2))
	a--;

if ((x==100) && (a<74))
	a++;

}
}
	clrscr();
	cout<<" Wohoo! You did it!";

return 0;
}

Create an internal representation of the maze using a multidimensional array of char. Then you can check the value of each element of the array as if were a visible cell in the maze. If the value of the element is the equivalent of a wall, then you can't go there. IF the value of an element is space then it is a legal move and if the value of the element is the goal then it is a legal move.

hehe I am doing the same thing...

here is a link to my source code....it all works except for some reason it keeps repeating level one (I'd be greatly appriciative if you [or anyone] could find where it was looping and fix it).

http://www.daniweb.com/forums/thread117258.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.