944,031 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 18236
  • C++ RSS
Sep 19th, 2004
0

how to make maze game using "gotoxy" & getch?

Expand Post »
ey there! i have a problem here regarding this maze stuff... i think using getch and gotoxy is not complicated. our teacher says he will give extra points to who can finish this.. can it be done using switch? a simple code would be much appreciated. - h3rtz-
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
h3rtz is offline Offline
11 posts
since Sep 2004
Sep 19th, 2004
0

Re: how to make maze game using "gotoxy" & getch?

what exactly is this maze game. if u giv me a briefing abt it i mite give the code to it
Reputation Points: 10
Solved Threads: 0
Newbie Poster
donn is offline Offline
2 posts
since Sep 2004
Sep 19th, 2004
1

Re: how to make maze game using "gotoxy" & getch?

Greetings,

Writing your own version of gotoxy() and clrscr() would probably be for the best. They can be found all over the place, but the best ones I've found were:

#include <iostream.h>
#include <windows.h>

void gotoxy(short x, short y) {
	HANDLE hConsoleOutput;
	COORD Cursor_Pos = {x, y};

	hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hConsoleOutput, Cursor_Pos);
}

void clrscr(void) {
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD coord = {0, 0};
	DWORD count;
	
	GetConsoleScreenBufferInfo(hStdOut, &csbi);
	FillConsoleOutputCharacter(hStdOut, ' ', csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
	SetConsoleCursorPosition(hStdOut, coord);
}

Doing the rest is quite simple. Here's a simple layout of how this can be accomplished:
  • Create a function to update the player's position. Have it clear the screen everytime this is called
  • Use an infinite while loop and get the key pressed using getch()
  • Call a switch case and find out which key was pressed and where to update the players position

That should get you to a good start, and good luck.


- Stack Overflow
Reputation Points: 26
Solved Threads: 4
Junior Poster
Stack Overflow is offline Offline
185 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Visual C++ graphics
Next Thread in C++ Forum Timeline: ebcdic to decimal function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC