-
Notifications
You must be signed in to change notification settings - Fork 765
/
Copy pathflying_character
75 lines (63 loc) · 1.46 KB
/
flying_character
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
/*will return character based on passed number*/
char getCHAR(int n)
{
char ok[]="~!@#$%^&*:;'\",{}|<>=";
return ok[n];
}
/*function to identify that any key hit by the keyboard*/
int kbhit(void)
{
struct termios oldt, newt;
int ch;
int oldf;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
if(ch != EOF)
{
ungetc(ch, stdin);
return 1;
}
return 0;
}
/*move cursor on specified position on screen*/
void gotoxy(int x,int y)
{
printf("%c[%d;%df",0x1B,y,x);
}
int main(void) {
int x,y;
long int i,j;
i=j=0;
x=1; y=20;
system("clear");
/*program will run until any key hit*/
while(!kbhit())
{
x=rand()%((150-1+1)+1);
y=rand()%((50-1+1)+1);
gotoxy(x,y);
printf("%c", getCHAR(rand()%((20-1+1)+1))); fflush(stdout);
++i;
if(i==10000) {++j; i=0;}
if(j==100000){ i=0;}
if(j<=100)
usleep(30000);
if(j<=1000)
usleep(3000);
if(j<=10000)
usleep(300);
}
return 0;
}
<div class="open_grepper_editor" title="Edit & Save To Grepper"></div>