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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
| #include "stdio.h" #include <windows.h> #include <conio.h> #include <time.h> #define Esc 27 #define Up 72 #define Down 80 #define Left 75 #define Right 77 #define Kong 32
int x=10; int y=18; int d2=10; int d1=10; int d=10; int r=1; int r1=1; int r2=1; int t=1; int f=0; int m=3; int j=0; char p; void kongzhi(int bx,int by); void huatu(); void gotoxy(int x,int y) { COORD coord; coord.X=x; coord.Y=y; SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord ); } void hidden() { HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cci; GetConsoleCursorInfo(hOut,&cci); cci.bVisible=0; SetConsoleCursorInfo(hOut,&cci); }
void shuoming() { printf("\t\t\t\n\n\n\n"); printf("\t\t\t方向控制\n\n" "\t\t\t上 ↑\n\n" "\t\t\t下 ↓\n\n" "\t\t\t左 ←\n\n" "\t\t\t右 →\n\n" "\t\t\t子弹 空格\n\n\n" "\t\t\t退出请按 ESC\n"); gotoxy(0,0); }
void byebye() { if((x==d&&y==r)||(x==d1&&y==r1)||(x==d2&&y==r2)) { gotoxy(1,3); printf(" !!! 游戏结束 !!!\n" "*******************\n" " 您的总得分: %d\n\n" " 敌机数: %d\n" " 歼敌数: %d\n" " 命中率: %.0f %%\n" "*******************\n",f,m,j,((float)j/(float)m)*100); while(!kbhit()) { Sleep(500); gotoxy(1,12); printf(" 继续请按任意键...\n\n\n"); Sleep(900); gotoxy(1,12); printf(" "); } gotoxy(0,0); huatu(); f=0; m=0; j=0; if(x>=18) x--; else x++; gotoxy(x,y); printf("Ж"); } }
void jifan() { if(x==d&&y==r) { gotoxy(d,r); printf("3"); Sleep(200); gotoxy(d,r); printf(" "); f+=2; r=0; j++;} if(x==d1&&y==r1) { gotoxy(d1,r1); printf("1"); Sleep(200); gotoxy(d1,r1); printf(" "); f+=3; r1=0; j++; } if(x==d2&&y==r2) { gotoxy(d2,r2); printf("0"); Sleep(200); gotoxy(d2,r2); printf(" "); f+=1; r2=0; j++; } gotoxy(26,2); printf(" %d \n",f);
}
void huatu() { int i,n; for(i=0;i<=20;i++) { for(n=0;n<=20;n++) { printf("*"); } printf("\n"); } for(i=1;i<=19;i++) { for(n=1;n<=19;n++) { gotoxy(i,n); printf(" "); } } }
void dfeiji() { while(t) { if(!r) {d=rand()%17+1; m++;} if(!r1) {d1=rand()%17+1; m++;} if(!r2) {d2=rand()%17+1; m++;} while(t) { r++; r1++; r2++; gotoxy(d,r); printf("Ψ"); gotoxy(d1,r1); printf("ж"); gotoxy(d2,r2); printf("♀"); Sleep(900); gotoxy(d,r); printf(" "); gotoxy(d1,r1); printf(" "); gotoxy(d2,r2); printf(" "); kongzhi(0,0); byebye(); if(r==18) r=0; if(r1==18) r1=0; if(r2==18) r2=0; if(r==0||r1==0||r2==0) break; } } }
void kongzhi(int bx,int by) { int a; while (kbhit()) { if((p=getch())==-32) p=getch(); a=p; gotoxy(22,5); switch(a) { case Up:if (y!=1) { gotoxy(x,y); printf(" "); y--; gotoxy(x,y); printf("Ж"); }break; case Down:if (y!=18) { gotoxy(x,y); printf(" "); y++; gotoxy(x,y); printf("Ж"); }break; case Left:if (x!=1) { gotoxy(x,y); printf(" "); x--; gotoxy(x,y); printf("Ж"); }break; case Right:if (x!=18) { gotoxy(x,y); printf(" "); x++; gotoxy(x,y); printf("Ж"); }break; case Kong: { bx=y; for(by=y;by>1;) { by--; gotoxy(x,by); printf("θ"); Sleep(10); gotoxy(x,by); printf(" "); y=by; jifan(); if(r==0||r1==0||r2==0) break; } y=bx; }break; case Esc:t=0; break; default:break; } } } void main() { srand(time(NULL)); shuoming(); hidden(); huatu(); gotoxy(x,y); printf("Ж"); gotoxy(22,2); printf("分数:"); while (t) { kongzhi(0,0); if(t) dfeiji (); } }
|