C Board  

Go Back   C Board > General Programming Boards > Game Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-11-2002, 05:35 PM   #1
Rambling Man
 
Join Date: Jan 2002
Posts: 1,050
My Maze Game --- A Few Questions

I'm trying to make a maze...wait let me rephrase that, I am making a maze game. You start off not knowing not any of the map, but as you move farther into the maze you see more of the map (all discovered squares never go away). Right now my game could be finished after a few hours of work (just a matter of typing in some code), but it would contain a rather poor interface for this type of game. Instead of being able to use the arrow keys when moving through the maze you have to enter U/u (up), D/d (down), L/l (left), and R/r (right). I would rather make it so the player could just use the arrow keys to move through the maze...this would make the game a lot more fun. Could anyone tell me how I could do this? I'm not sure how the program can detect the key movement, then load the graphics (a console app so they are only * o X ) for the squares that should be made visible. Here is an example of what I currently have:

if(d_maze[2][0] == '*' && var_1 == 1)
{
do
{
cout << "Would you like to move up, down, or right?\n";
cin >> move;
if(move == 'U' || move == 'u')
{
d_maze[2][0] = 'o';
d_maze[1][0] = '*';
d_maze[0][0] = 'o';
d_maze[2][1] = 'o';
var_1 = 0;
break;
}
if(move == 'D' || move == 'd')
{
d_maze[2][0] = 'o';
d_maze[3][0] = '*';
d_maze[4][0] = 'o';
d_maze[4][1] = 'X';
d_maze[2][1] = 'o';
d_maze[3][1] = 'X';
var_1 = 0;
break;
}
if(move == 'R' || move == 'r')
{
d_maze[2][0] = 'o';
d_maze[2][1] = '*';
d_maze[1][0] = 'o';
d_maze[3][0] = 'o';
d_maze[3][1] = 'X';
d_maze[3][2] = 'X';
d_maze[1][1] = 'X';
d_maze[1][2] = 'X';
d_maze[2][2] = 'o';
var_1 = 0;
break;
}
}while(var_1 == 1);
}

Here is a basic breakdown of how the program works:

show maze
ask for user move
input user move (graphics)
...repeat process until game end

Also, another thing I would like to do with the program is have a timer. This would a certain challenge to the game by discouraging slow decisions by the user. I want the timer to continue to run in until either time = 0 or until game end. I'm sure there is a way to do this, but I just don't know the basic syntax of it all.

Hopefully somebody can help me on this, because I would like to be able to improve the gameplay/interface of my maze game. If not I guess I'll have to do without for the time being.
TechWins is offline   Reply With Quote
Old 04-11-2002, 07:24 PM   #2
Rebooted
 
Inquirer's Avatar
 
Join Date: Apr 2002
Posts: 281
What is the * o and X in your program for?

What compiler are you using?

I will get back to you on the key thing, but i believe kbHit(); may work. (i don't think that is the correct caps though)
Inquirer is offline   Reply With Quote
Old 04-11-2002, 07:36 PM   #3
Rambling Man
 
Join Date: Jan 2002
Posts: 1,050
The * is for the player's piece so to speak.
The o is to show that this is a square you can move to.
The X is to show that this is a wall and you can't move there.

I'm using DevC++ as my compiler.
TechWins is offline   Reply With Quote
Old 04-11-2002, 07:42 PM   #4
Rebooted
 
Inquirer's Avatar
 
Join Date: Apr 2002
Posts: 281
Post

Oh, and if you would kindly use [code] tags? it makes the posts much nicer looking. See the note at the top of the forum for more info...

And, i havent gotten kbhit to work yet either.
Inquirer is offline   Reply With Quote
Old 04-12-2002, 12:15 AM   #5
Rambling Man
 
Join Date: Jan 2002
Posts: 1,050
Well, thanks for trying to help, but I found out to use arrow key movement appropriately (somewhat at least). The only problem is that you can't use arrow key movement in a console application, or can you and I'm just being really stupid right now?

Does anyone know how you can run a timer? I want the program to last say 30 seconds, what would be some basic code for it? I've been thinking that maybe having a continous loop while I subtract 1 from it each time, and redisplay the new number, but this might make the intervals too fast. Plus I'm not sure how I could make it to loop and run while other processes are taking place. Any help would be greatly appreicated...thanks.
TechWins is offline   Reply With Quote
Old 04-12-2002, 04:27 AM   #6
Registered User
 
Invincible's Avatar
 
Join Date: Feb 2002
Posts: 210
If you're programming for the win32 console you should look into the ReadConsoleInput() function.
__________________
"The mind, like a parachute, only functions when open."
Invincible is offline   Reply With Quote
Old 04-12-2002, 11:09 AM   #7
Registered User
 
Join Date: Feb 2002
Posts: 20
When you press an arrow key two hits are storred in the buffer therefor you need to use getch() twice to find out which arrow key is pressed. Something like this.


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

int main()
{
	int iKey;
	char key;
	
	do
	{
		if(kbhit())			//if a key is pressed
		{
			key = getch();	//get the key
			iKey = (char)key;//change it to an int
			cout<<"Key: "<<key<<"\tiKey: "<<iKey<<endl;//display it
		}
	}while(key != 'Q' && key != 'q');
	
	return 0;
}
This took me foooorever to fiqure out a while ago.
White Rider is offline   Reply With Quote
Old 04-12-2002, 04:34 PM   #8
Rambling Man
 
Join Date: Jan 2002
Posts: 1,050
Thank you very much for that code, WR. The only problem with it is that Dev can't use getch() or kbhit(), so the code won't work with Dev. Luckily, though, I have an introductory version of MSVC++ that I am able to use. Now it's just time to implement that code into my program.

It seems like everybody is avoiding this question, which is fine but I would appreciate it if it were answered. How a run a 30 second timer while the game is going on? I want the timer to count down from 30-0 and end when either the timer reaches 0 or the player has reached the end of the maze. The timer also has to loop continously while the rest of the game is going on. Could anybody help me on this, please?
TechWins is offline   Reply With Quote
Old 04-14-2002, 03:17 PM   #9
Rebooted
 
Inquirer's Avatar
 
Join Date: Apr 2002
Posts: 281
I am somewhat new to C++, but i know from my java experiance that if you want to do what you are saying, you will have to have another thread that does the timer. Unfortuantely, i have no idea how to do that.
Inquirer is offline   Reply With Quote
Old 04-14-2002, 06:33 PM   #10
I am the worst best coder
 
Quantrizi's Avatar
 
Join Date: Mar 2002
Posts: 644
Just use the sleep() function.....I use dev-C++ to.....
__________________
poems by me
Quantrizi is offline   Reply With Quote
Old 04-14-2002, 07:57 PM   #11
Registered User
 
Dual-Catfish's Avatar
 
Join Date: Sep 2001
Posts: 802
time_t seconds;

seconds = time(NULL);
long secondsToCountTo = seconds + 30;

while (seconds <= secondsToCountTo)
{
doStuff();
}


I *think* this will work.. if not you can look up functions in time.h yourself.
Dual-Catfish is offline   Reply With Quote
Old 04-15-2002, 12:21 AM   #12
Rambling Man
 
Join Date: Jan 2002
Posts: 1,050
Thanks, Dual-Catfish, for the help. I was going to go look in time.h myself, because it didn't seem as if anybody was going to answer that question for me, but since you did you have saved me some time.
TechWins is offline   Reply With Quote
Old 04-15-2002, 08:30 AM   #13
Registered User
 
heat511's Avatar
 
Join Date: Dec 2001
Posts: 169
this may work....

for the 30 second thing this could work

Code:
]
x = 0;
while(x != 30)
{

Sleep(1000);  //sleeps one second
x++;
do stuff here();  
//then you can check what x equals 
//for the time spent inside the loop and \
//check what key were pressed etc.

}
it only 'sleeps' for 1 second at a time, because otherwise you would pause the computer for too long before doing anything because sleep pauses the computer from doing almost everything but it will still remember the key you press during the sleep

Wow! what I wrote above is confusing
ummmmm basically the code should do what you want (i think)
heat511 is offline   Reply With Quote
Old 04-17-2002, 05:12 PM   #14
Unregistered
Guest
 
Posts: n/a
i've read something somewhere in a book about CLOCKS_PER_SECOND or maybe it was TICKS_PER_SECOND, and using how long the program has been running to create a time counter
  Reply With Quote
Old 04-18-2002, 05:20 PM   #15
Rebooted
 
Inquirer's Avatar
 
Join Date: Apr 2002
Posts: 281
getche()

In BloodShed Dev-C++, which i have it is possible to use getche().

Just:
Code:
#import <conio.h>
to get the character hit, cast it to a char, otherwise do a compare of the integer that it returns. the prototype of getche:
Code:
int getche();
~Inquirer
__________________
Compilers:
GCC on Red Hat 8.1 (Primary)
GCC on Mac OS X 10.2.4 (Secondary)

Others:
MinGW on XP
Inquirer is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Open-source Game Project Glorfindel Projects and Job Recruitment 0 03-24-2009 01:12 AM
A few questions on game programming mramazing Game Programming 7 01-11-2009 05:48 AM
20q game problems Nexus-ZERO C Programming 24 12-17-2008 05:48 PM
2D Game project requires extra C++ programmers, new or experienced drallstars Projects and Job Recruitment 2 05-16-2007 10:46 AM
Someone help me with this game?? stehigs321 Game Programming 15 10-30-2003 09:42 PM


All times are GMT -6. The time now is 12:10 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22