GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Jul-2006, 08:18
suvirj suvirj is offline
New Member
 
Join Date: Jul 2006
Posts: 8
suvirj is on a distinguished road

Typing tutor Game problem


I am working on the code of a C++ game program in which....words keep falling from top to bottom of the screen...the user has to enter the word before the word reaches the end of the screen..

I figured out how to make the words fall ...BUT HOW DO I MAKE THE USER ENTER WORDS WHILE THE WORDS ARE FALLING ...

Any help would be appreciated...i m using turbo C++ 4.5...just tell me atleast which inbuilt function i can use..

Thanx
  #2  
Old 30-Jul-2006, 09:53
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Typing tutor Game problem


Look into the functions kbhit() and getch(). These functions will help you out.
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #3  
Old 31-Jul-2006, 03:22
suvirj suvirj is offline
New Member
 
Join Date: Jul 2006
Posts: 8
suvirj is on a distinguished road

Re: Typing tutor Game problem


I tried kbhit() and getch(), it didnt work...the word stops falling so that the user can enter sumthing...i want sumthing so that the word keeps falling and the user can enter whatever he wants.... ;-)
  #4  
Old 31-Jul-2006, 08:57
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Typing tutor Game problem


Quote:
Originally Posted by suvirj
I tried kbhit() and getch(), it didnt work...the word stops falling so that the user can enter sumthing...i want sumthing so that the word keeps falling and the user can enter whatever he wants.... ;-)
Then you used the functions wrong... I use them all the time for exactly the type of work you are trying to do.
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #5  
Old 31-Jul-2006, 10:05
suvirj suvirj is offline
New Member
 
Join Date: Jul 2006
Posts: 8
suvirj is on a distinguished road

Re: Typing tutor Game problem


Cool...could u plllleeeeeaaaasse give me an extract of the code so that i can understand better...thanx a ton dude... :-)
  #6  
Old 31-Jul-2006, 12:36
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Typing tutor Game problem


Quote:
Originally Posted by suvirj
Cool...could u plllleeeeeaaaasse give me an extract of the code so that i can understand better...thanx a ton dude... :-)
If you'd read the Guidelines you'll note that you post the code you're having trouble with and we will help you correct it. We like to know what we're dealing with because any blind response (which is what you are asking for) may not be acceptable or workable with your design.

Just post the area of the program you're having trouble with, but enough to see the the program flow.
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #7  
Old 31-Jul-2006, 15:11
suvirj suvirj is offline
New Member
 
Join Date: Jul 2006
Posts: 8
suvirj is on a distinguished road
Exclamation

Re: Typing tutor Game problem


Here is the code....

CPP / C++ / C Code:
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<stdlib.h>
void game()
{
int i,j,k; char ch;
cout<<"Press a key to start: "<<endl;
  getch();
   clrscr();
      i=10;

for(j=0;j<27;j++)
for(k=0;k<100;k++)
{ clrscr();
   gotoxy(i,j);
       cout<<"word";}
clrscr(); }
void main()
{ game(); }

Now up here i made the word fall but how do i make the user enter sumthing while its falling...
Any help would be appreciated...
Thanx
  #8  
Old 31-Jul-2006, 15:35
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Typing tutor Game problem


Quote:
Originally Posted by suvirj
Here is the code....

CPP / C++ / C Code:
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<stdlib.h>
void game()
{
int i,j,k; char ch;
cout<<"Press a key to start: "<<endl;
  getch();
   clrscr();
      i=10;

for(j=0;j<27;j++)
for(k=0;k<100;k++)
{ clrscr();
   gotoxy(i,j);
       cout<<"word";}
clrscr(); }
void main()
{ game(); }

Now up here i made the word fall but how do i make the user enter sumthing while its falling...
Any help would be appreciated...
Thanx
OK.

#1: void main() -- not good, here's why

#2: I don't see where you tried using kbhit() at all. That must be used to figure out if there is a key that's been pressed. If so, read the character. If not, just drop the word. It therefore would go in your inner loop. Try writing a program using kbhit() and getch() in conjunction with many putchar() statements to see what happens at each step. This is the way you use them together:
CPP / C++ / C Code:
if (kbhit())        // If true, read the character, if not, just continue
{
    ch = getch();   // get the character.
}

#3: Your formatting needs work. See this. It's important because when your programs get larger, you will get lost trying to follow the code.
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #9  
Old 31-Jul-2006, 16:24
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,791
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Typing tutor Game problem


Quote:
Originally Posted by suvirj
Now up here i made the word fall but how do i make the user enter sumthing while its falling...

I don't have your version of Turbo C, but I played around with bcc32 (the free download command-line compiler from Borland) on my Windows XP machine. The following gave something worth testing:

CPP / C++ / C Code:
#include <iostream>
#include <cstdio>
#include <conio.h>

using namespace std;

int main()
{
    void game(void);

    game();
    return 0;
}

void game(void)
{
    int i, j, k;
    char ch;
    cout << "Press a key to start: ";
    getch();

    i = 10;

    // Note that the top row is row 1, not row 0;
    for (j = 1; j <= 27 && !kbhit(); j++) { //if you want a total of 27
        clrscr(); // erase the previous line (and everything else)
        //
        // A "busy" loop to give some delay
        //
        for (k = 0; k < 1000; k++) { // adjust counter for your system speed
            gotoxy(i, j);
            cout << "word " << i << "," << j; // show coords, just for kicks
        }
    }
    //clrscr(); // I commented it out so that I could see the final screen
}

Now, if your compiler doesn't like these headers, you can use what you had before, but this is the preferred Standard way of doing things with C++. Note that <conio.h> is not a standard library header, and kbhit() and clrscr() and gotoxy() are not standard library functions, but they work for my version of Borland C (and C++) compiler. Good enough for a personal game and for learning in general, but not portable.

Regards,

Dave
  #10  
Old 31-Jul-2006, 23:38
suvirj suvirj is offline
New Member
 
Join Date: Jul 2006
Posts: 8
suvirj is on a distinguished road

Re: Typing tutor Game problem


Thanx for the tips guys...Our professor at skool uses "void main()". Picked it up frm him. Steve Summit must be right...makes sense too. Also, the formatting page is helpful..nice!
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 4) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Graphic problem in Unreal Tournament 2004 zerox Computer Software Forum - Games 10 09-Oct-2005 13:31
Runtime Problem involving "printf" in C Program supamakia C Programming Language 2 09-Oct-2005 11:09
a significant problem after installing Xp mohammad Computer Software Forum - Windows 10 09-Aug-2005 08:03
Another FX 5600 problem (but with details that might shed light on this) BobDaDuck Computer Hardware Forum 2 16-Apr-2004 08:53

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:18.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.