-
Notifications
You must be signed in to change notification settings - Fork 0
/
numattack.c
191 lines (188 loc) · 3.13 KB
/
numattack.c
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* Copyright 2019 Noah M. Walker - All Rights Reserved
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
USA; either version 2 of the License, or (at your option) any later
version; incorporated herein by reference.
*/
#include <stdio.h>
#include <curses.h>
#include <time.h>
#include <math.h>
int *wall;
int score=0;
//enemy
int enemyx;
int enemyy;
int enemyval;
bool has_wand;
int play=1;
int enemydelay=5000;
int tmp;
int counter;
int level=1;
int wands=0;
bool debug=0;
WINDOW *canvas;
time_t startstamp;
time_t endstamp;
int width=22;
int height=7;
int main(int argc, char *argv[])
{
printf("[10;100][11;50]");
if(argc>1){
if(!strcmp(argv[1],"-d")){
debug=1;
}
for(int i=1;i<argc;i++){
//printf("%s\n",argv[i]);
if(!strcmp(argv[i],"-d")){
debug=1;
}
if(!strcmp(argv[i],"-w")){
if(argc<i+1){
return 0;
}
width=atoi(argv[i+1]);
}
if(!strcmp(argv[i],"-h")){
if(argc<i+1){
return 0;
}
height=atoi(argv[i+1]);
}
}
}
//printf("%i,%i\n",width,height);
//exit(0);
wall=malloc(sizeof(int)*height);
printf("(U");
startstamp=time(NULL);
srand(time(NULL));
//init
canvas=initscr();
noecho();
cbreak();
nodelay(stdscr,TRUE);
curs_set(0);
newenemy();
//main loop
draw_wall();
while(play){
enemyx--;
draw();
refresh();
if(enemyx==0){
//draw();
draw_wall();
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_wall(){
clear();
for(int a=0;a<height;a++){
move(a,0);
if(wall[a]==0){ //draw wall
printw("#");
}else{
printw(" ");
}
}
mvprintw(height,0,"score: %d level: %d wands: %d",score,level,wands);
if(debug){
mvprintw(height+1,0,"enemy delay: %d", enemydelay);
}
//draw();
}
int draw(){
move(enemyy,enemyx);
if(has_wand){
printw("%d¥ ",enemyval);
}else{
printw("%d ",enemyval);
}
}
int newenemy(){
enemyval=(rand()%10);
enemyx=width;
enemyy=(rand()%height);
has_wand=0;
if(!(rand()%(level*10))){ //give enemy wand depending on level.
has_wand=1;
}
}
int attack(){
if((tmp==48)&&(enemyval==0)){ //winning
draw_wall();
score++;
if(has_wand){
wands++;
}
beep();
if((score%10)==0){
level++;
if(enemydelay>1000){ //speed things up on new level
enemydelay-=200;
}else{
enemydelay=1000;
}
}
newenemy();
}
if((tmp==49)&&(enemyval==1)){//1
enemyval--;
}
if((tmp==50)&&(enemyval==2)){//2
enemyval--;
}
if((tmp==51)&&(enemyval==3)){//3
enemyval--;
}
if((tmp==52)&&(enemyval==4)){//4
enemyval--;
}
if((tmp==53)&&(enemyval==5)){//5
enemyval--;
}
if((tmp==54)&&(enemyval==6)){//6
enemyval--;
}
if((tmp==55)&&(enemyval==7)){ //7
enemyval--;
}
if((tmp==56)&&(enemyval==8)){ //8
enemyval--;
}
if((tmp==57)&&(enemyval==9)){ //key 9
enemyval--;
}
if((tmp==10)&&(wands>0)){ //use wand: enter key
for(int i=0;i<7;i++){
wall[i]=0;
}
wands--;
}
draw();
}