Program

Remember the facebook game typing maniac? i'm trying to make that game using dev c++.. but i don't know how to put a line where a user will type the falling word before it hits the line.. i've only made the platform and the falling word..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream>
#include<conio.h>
#include<cstdlib>
#include<windows.h>
using namespace std;
int gotoXY(int x, int y)
{
COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
int main()
{
    int hits=0,miss=0,a;
    string word="Letter",type;
    
    for (a=1;a<=12;a++) 
     {
     cout<<"Hits: "<<hits<<"\tMisses: "<<miss<<endl;
     cout<<"||                        ||"<<endl;
     cout<<"||                        ||"<<endl;
     cout<<"||                        ||"<<endl;
     cout<<"||                        ||"<<endl;
     cout<<"||                        ||"<<endl;
     cout<<"||                        ||"<<endl;
     cout<<"||                        ||"<<endl;
     cout<<"||                        ||"<<endl;
     cout<<"||                        ||"<<endl;
     cout<<"||                        ||"<<endl;
     cout<<"||                        ||"<<endl;
     cout<<"||                        ||"<<endl;
     cout<<"----------------------------"<<endl;
     gotoXY(10,a);
     cout<<word;
     Sleep(500);
     system("cls"); 
     }
getch();
return 0;
}
     
Last edited on
You really need to have a game programming library to make this in so that you have use of threads and timers. Otherwise, this is going to be very difficult/impossible to make.
I think you could do it.

Will the user have to press enter? Otherwise, you will have to use non-line buffered input, which as Mats said, is easiest done with a game lib, or at least a graphics lib like SFML. I will be happy to help if you need it!
with the enter pressed or not its ok .. as long as it will work .. :D
just to make things clearer, what i want to do is to add a line below where the user can input the word while the word is falling.
Ok, sure, in order for this to work, it will not have to press 0;

So, some psuedocode:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
      //instructions
      //ready? Go!!
      //choose word to fall from a list
      //game loop:
      //print the screen, walls, word, etc
      //if keyboard hit, then use getch or some other way.
      //add the key to the input string
      //if input string -equals the word,
            //Winner
      //else
           // update the board
           //wait for a amount of time, probably a var
}


Note: THis is simple, doesn't work with more than one word.
Last edited on
The point of using the game programming library is you want to do this:

Print the screen
Test keyboards hits
Add key to the input string
Check winning conditions
Check losing conditions.

But you want to do ALL of this at the same time! A game programming library would let you do it like this (pseudocode):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
timer eventupdate == 0.02s 
{
    UpdateEvents(); //Update the falling word and anything else like 
    //charactors remaining or current typing speed
    reset timer eventupdate; 
}
timer print == 0.025s //40 frames per second
{
    UpdateScreen();
    CollisionCheck(); //Check if the falling word is in collision with the line.
    LoseCheck(); //Check if the losing condition was met.
    reset timer print;
}
timerkeytest == 0.05s //Allows for a typing speed above the current world record. 
{
    CheckKeyPress(); //Check for a new keypress 
    WinCheck(); //Check for a win
    reset timer keytest;
}


So we don't exactly do everything at the same time, but update the events very quickly and in a sensible order so that it appears to the user that everything is seamless. I'm not sure how you would do this in standard C++ (without doing some advanced coding), although I'm sure you could achieve it with boost. It would be way easier using a library such as SFML or Allegro though, which has all the things that you need already done!

Edit: Forgot to reset the timers. :p
Last edited on
that is what the google tells me. i like to learn how to use that multithread.
Topic archived. No new replies allowed.