-
Notifications
You must be signed in to change notification settings - Fork 0
/
numattack.c.older
130 lines (129 loc) · 2.06 KB
/
numattack.c.older
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <stdio.h>
#include <curses.h>
#include <time.h>
#include <math.h>
char creator[55]="'Number Attack!' Created by Qwerty Keyboard: u/userse31"
char wallcrash[]="";
char enemykilled[]="[10;440][11;50]";//18
char lose1[]="[10;100][11;200]";//19
char lose2[]="[10;90][11;150]";
int wall[7];
int score=0;
int enemyx;
int enemyy;
int enemyval;
int play=1;
int enemydelay=5000;
int tmp;
int counter;
int level=1;
FILE *sound;
WINDOW *canvas;
time_t startstamp;
time_t endstamp;
int main(int argc, char *argv[]
printf(sound,"[10;440]");
printf("(U");
startstamp=time(NULL);
srand(time(NULL));
//init
canvas=initscr();
noecho();
cbreak();
nodelay(stdscr,TRUE);
curs_set(0);
newenemy();
sound=fopen("/dev/tty","a"); //open the current tty for sending sound effects
//main loop
while(play){
enemyx--;
draw();
refresh();
if(enemyx==0){
draw();
beep();
if(wall[enemyy]==0){
wall[enemyy]=1;
score=score-enemyval;
newenemy();
}else{
play=0;
}
}
for(counter=0;counter<enemydelay;counter++){
usleep(1);
tmp=getch();
if(tmp != -1){
attack();
}
}
}
endwin();
printf("Your score was: %d\n",score);
endstamp=time(NULL);
printf("You have been playing for %d seconds\n",endstamp-startstamp);
printf("Thank you for playing [36m[42mNumber Attack![37m[40m\n");
return 0;
}
int draw(){
clear();
for(int a=0;a<7;a++){
move(a,0);
if(wall[a]==0){
printw("#");
}else{
printw(" ");
}
}
move(enemyy,enemyx);
printw("%d",enemyval);
mvprintw(7,0,"score: %d",score);
}
int newenemy(){
enemyval=(rand()%10);
enemyx=22;
enemyy=(rand()%7);
}
int attack(){
if((tmp==48)&&(enemyval==0)){ //winning
score++;
beep();
if((score%10)==0){
level++;
}
if(enemydelay>11){
enemydelay-=10;
}else{
enemydelay=10;
}
newenemy();
}
if((tmp==49)&&(enemyval==1)){
enemyval--;
}
if((tmp==50)&&(enemyval==2)){
enemyval--;
}
if((tmp==51)&&(enemyval==3)){
enemyval--;
}
if((tmp==52)&&(enemyval==4)){
enemyval--;
}
if((tmp==53)&&(enemyval==5)){
enemyval--;
}
if((tmp==54)&&(enemyval==6)){
enemyval--;
}
if((tmp==55)&&(enemyval==7)){
enemyval--;
}
if((tmp==56)&&(enemyval==8)){
enemyval--;
}
if((tmp==57)&&(enemyval==9)){
enemyval--;
}
draw();
}