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

Reply

Join Date: Sep 2004
Posts: 11
Reputation: h3rtz is an unknown quantity at this point 
Solved Threads: 0
h3rtz h3rtz is offline Offline
Newbie Poster

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

 
0
  #1
Sep 19th, 2004
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-
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 2
Reputation: donn is an unknown quantity at this point 
Solved Threads: 0
donn donn is offline Offline
Newbie Poster

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

 
0
  #2
Sep 19th, 2004
what exactly is this maze game. if u giv me a briefing abt it i mite give the code to it
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 185
Reputation: Stack Overflow is an unknown quantity at this point 
Solved Threads: 4
Stack Overflow's Avatar
Stack Overflow Stack Overflow is offline Offline
C Programmer

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

 
0
  #3
Sep 19th, 2004
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
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.

IRC
Channel: irc.daniweb.com
Room: #c, #shell
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC