please help...

Hi. Getting into c++. Made a program that printed a 'o', then had a delay, then backspaced to erase the o, then spaced and printed another o. Ended up having it move across the screen, disappearing at the end using a modulus statement, and printing again on the next line. Not a great program, but here is my question: what do I need to know to print a maze on that screen. I could simply use a cout << "***** ***** ****" etc and make it that way, but I would rather use something like peek and poke (old reference to pet computers) to have more control. My simple goal is to make a maze and use keys to get out of it, without being able to go thru walls. Any help is appreciated.....please point me in the right direction. Thanks!
Last edited on
To start with i would have done a 'map' like a coordinate system and put the numbers in a vector like this.

vector< vector<int> > map;

Lets say 1 is a wall and 0 is where you can go.

And when you move. to right for example you do like

void moveRight()
{
if(map[y][x] + 1 == 1) //If the position +1 is a wall
{
//Do not move
}else{
//move
}

}

Thats how i would do it!

Wish you best luck :)
TY for the reply. Not sure about that yet.....still new to this, but I looked up vectors and realize there is still much for me to read. Shorter question.....

When you compile and run the c++ program, the smaller doslike screen appear. Is there any way to 'poke' a character like 20 down and 40 over?
How do you manipulate characters on this screen (like mae one appear at 34 down, 23 right, then change it to something else) Is this possible??

Thanks

I would suggest the same answer actually, make a coordinate system. where empty spots is a ' ' character. just do a

vector< vector<char> >

or

char map[MAP_HEIGHT][MAP_WIDTH];

if you are more comfortable with arrays, Tho they are evil. Then you just make a algoritm to insert a character at certain positions. I can help you with it but i suggest that you try it out for yourself. I dont think there are any easy ways to accomplish this.

Best luck :)

EDIT: i almost forgot, the last character in the X rows should always be '\n' so that you get a new line
Last edited on
Editing single characters on the CLI depends on the environment. You could use ncurses for linux/unix, or check http://msdn.microsoft.com/en-us/library/windows/desktop/ms682010(v=vs.85).aspx out if you're using Windows.
Last edited on
I would suggest you to read this article

http://cplusplus.com/articles/G13hAqkS/

I agreed with this guy totally.
And this is not only for games, This is for all graphical applications.

I think the console is for text output ONLY.

If youre gonna do things like this its probaly easier to just use a simple graphics library.
TY for the replies! -otisleb
Topic archived. No new replies allowed.