Home > Back-end >  For bosses to help see the self-closing endl and cout
For bosses to help see the self-closing endl and cout

Time:10-02

In Linux using c + + write a choice difficulty typing game
The ideal output should be morally for such

Actual output became the ghost sample, please help!

The code is as follows:
 # define TTY_PATH "/dev/tty 
"# define STTY_US "stty raw echo - F"
# define STTY_DEF "stty - the raw echo - F"

Void delay (int);
Char putc ();
Int puti ();
Void skin_up ();
Void skin_down ();
Int devil (int);
Int get_char ();
Int main ()
{
using namespace std;
Int h;
Cout & lt; <"Both please input your difficulty: h=" & lt; cin> h;
While (enginer (h));
Cout & lt; <"Game over" & lt; System (STTY_DEF TTY_PATH);
return 0;
}

 char putc ()//generate random letters 
{
Char a;
Srand ((int) time (0));
A=char (rand () % 26 + 97);
Return a;
}
Int puti ()//generate random transverse position
{
int a;
Srand ((int) time (0));
A=rand () % 20;
Return a;
}
Void delay (int t)//delay
{
Clock_t now=clock ();
While (clock () - now & lt; t);
}
Int get_char monitoring ()//no jam buttons, return key value
{
Fd_set RFDS;
Struct timeval TV;
Int ch=0;
FD_ZERO (& amp; RFDS);
FD_SET (0, & amp; RFDS);
TV. Tv_sec=0;
TV. Tv_usec=10;

If (select (1, & amp; RFDS, NULL, NULL, & amp; TV) & gt; 0)
Ch=getchar ();

Return ch;
}

 
Void skin_up ()
{
STD: : cout & lt; <"Play word play";
STD: : cout & lt; STD: : cout & lt; <"____________________";
STD: : cout & lt; }
Void skin_down ()
{
STD: : cout & lt; <"____________________" & lt; STD: : cout & lt; <"Enter a ':' to pause, and then enter the 'e' to quit." & lt; }

 int devil (int h)/sport/letter the main function, returns 0, 1 for judging the main function 
{
using namespace std;
Char ele=putc ();
Int lenth=puti ();
/* letters output such as falling */
for(int i=0; I & lt;=20; I++)
{
System (" the clear ");
Skin_up ();
Int w;
/* letters longitudinal position */
for(int i=0; I & lt;=20; I++)
{
System (" the clear ");
Skin_up ();
Int w;
/* letters longitudinal position */
For (int j=0; J & lt;=I; J++)
{
Cout & lt; W=20 - j;
}
/* letters transverse position */
For (int j=0; J & lt;=lenth; J++)
Cout & lt; <"';
Cout & lt; /* fill line */
for(int i=0; I & lt;=w; I++) cout & lt; Skin_down ();

Delay (15625 * 50/h);
System (STTY_US TTY_PATH);
Char a;
/* monitoring keyboard, judge the key value */
If (a=get_char ())
{
If (a==ele)
{system (" the clear ");
break;
}
Else if (a==':')
{
Char b=getchar ();
If (b=='e')
return 0;
}
}
}
return 1;
}
  • Related