![]() |
| | #1 |
| Rambling Man Join Date: Jan 2002
Posts: 1,050
| My Maze Game --- A Few Questions 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 | |
| | #2 |
| Rebooted 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 | |
| | #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 | |
| | #4 |
| Rebooted Join Date: Apr 2002
Posts: 281
| 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 | |
| | #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 | |
| | #6 |
| Registered User 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 | |
| | #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;
}
|
| White Rider is offline | |
| | #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 | |
| | #9 |
| Rebooted 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 | |
| | #10 |
| I am the worst best coder Join Date: Mar 2002
Posts: 644
| Just use the sleep() function.....I use dev-C++ to.....
__________________ poems by me |
| Quantrizi is offline | |
| | #11 |
| Registered User 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 | |
| | #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 | |
| | #13 |
| Registered User 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.
}
Wow! what I wrote above is confusing ummmmm basically the code should do what you want (i think) |
| heat511 is offline | |
| | #14 |
| 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 |
|
| | #15 |
| Rebooted 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> Code: int getche();
__________________ Compilers: GCC on Red Hat 8.1 (Primary) GCC on Mac OS X 10.2.4 (Secondary) Others: MinGW on XP |
| Inquirer is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |