#include #include #include #define PX 5 #define YSIZE 15 #define XSIZE 80 #define TOPMOST (LINES-YSIZE)/2 #define LIVES 5 #define MIDDLE YSIZE/2 #define TURNS 200 #define BOTTOM TOPMOST+YSIZE #define ECHANCE 100 #define SHOTS 20 #define PCHANCE 1000 #define CCHANCE 25 chtype ship='>'|COLOR_PAIR(COLOR_WHITE); chtype flat='_'|COLOR_PAIR(COLOR_CYAN); chtype uslope='/' |COLOR_PAIR(COLOR_CYAN); chtype dslope='\\'|COLOR_PAIR(COLOR_CYAN); chtype space=' '|COLOR_PAIR(COLOR_BLACK); chtype full='.'|COLOR_PAIR(COLOR_CYAN); chtype flame='='|COLOR_PAIR(COLOR_RED); chtype alien='&'|COLOR_PAIR(COLOR_GREEN); chtype explode='*'|COLOR_PAIR(COLOR_RED); chtype shot='-'|COLOR_PAIR(COLOR_WHITE); chtype pup='*'|COLOR_PAIR(COLOR_WHITE); chtype civ='P'|COLOR_PAIR(COLOR_WHITE); chtype alien2='&'|COLOR_PAIR(COLOR_BLUE); chtype shield=')'|COLOR_PAIR(COLOR_WHITE); chtype wall='|'|COLOR_PAIR(COLOR_CYAN); chtype level[YSIZE][XSIZE]; int py=YSIZE/2,y=0,x=0,life=LIVES,score=0,top=0,bot=YSIZE-1,ltop=0,lbot=YSIZE-1,lv=0,echance=100,turn=TURNS,last=0,t=0,mid=MIDDLE,shots=0,sh=0; float magicNumber= CLOCKS_PER_SEC; void empty(); void adv(); void init(); void die(); void draw(); void newlev(); void play(); void again(); void laser(); void empty() { py=YSIZE/2; for (y=0;yy&&level[y+1][x]==space) { level[y][x]=space; level[y+1][x]=alien2; mvaddch(y+1+TOPMOST,x,level[y+1][x]); } if(py==y) { num=rand()%3; if (num==0&&level[y+1][x]==space) { level[y][x]=space; level[y+1][x]=alien2; mvaddch(y+1+TOPMOST,x,level[y+1][x]); } if(num==1&&level[y-1][x]==space) { level[y][x]=space; level[y-1][x]=alien2; mvaddch(y-1+TOPMOST,x,level[y-1][x]); } } if(level[y+1][x]==civ) {level[y+1][x]=alien;} } mvaddch(y+TOPMOST,x,level[y][x]); } } num=rand()%6; mid+=(num==0&&mid>YSIZE/4)?-1:(num==5&&mid<(YSIZE/4)*3)?1:0; num=rand()%4; top+=(num==0&&top>0)?-1:(num==3&&top2&&bot>mid+2)?-1:0; level[0][XSIZE-1]=flat; level[YSIZE-1][XSIZE-1]=flat; for (y=0;ybot){level[y][XSIZE-1]=full;} if(y==top&&top==ltop){level[y][XSIZE-1]=flat;} if(y==bot&&bot==lbot){level[y][XSIZE-1]=flat;} if(y==top&&topltop){level[y][XSIZE-1]=dslope;} if(y==bot&&botlbot){level[y][XSIZE-1]=dslope;} if(y==0||y==YSIZE-1){level[y][XSIZE-1]=flat;} if (level[y][XSIZE-1]==space&&rand()%echance==0){level[y][XSIZE-1]=(rand()%4==0)?alien2:alien;} if (level[y][XSIZE-1]==space&&rand()%PCHANCE==0){level[y][XSIZE-1]=pup;} if (level[y][XSIZE-1]==space&&rand()%PCHANCE==0){level[y][XSIZE-1]=shield;} if (level[y][XSIZE-1]==space&&rand()%CCHANCE==0&&level[y+1][XSIZE-1]==flat){level[y][XSIZE-1]=civ;} mvaddch(y+TOPMOST,XSIZE-1,level[y][XSIZE-1]); } ltop=top; lbot=bot; mvaddch(py+TOPMOST,PX,ship); mvaddch(py+TOPMOST,PX-1,flame); if(level[py][PX]==civ) { level[py][PX]=space; score+=lv+1; draw(); } if(level[py][PX]==pup) { level[py][PX]=space; shots+=score*2+1; if(score>50){life++;} score=0; draw(); } if(level[py][PX]==shield) { sh++; level[py][PX]=space; } if(sh>0) { mvaddch(py+TOPMOST,PX+1,shield); if(level[py][PX+1]==flat||level[py][PX+1]==uslope||level[py][PX+1]==dslope||level[py][PX+1]==alien||level[py][PX+1]==alien2) { level[py][PX+1]=space; sh--; } } if (level[py][PX]!=space)die(); if(turn==0){newlev;} } void init () { int c; srand (time(NULL)); keypad(initscr(),1); raw (); nodelay(stdscr,0); noecho(); curs_set(0); nonl(); start_color(); for (c=0; c<=8; c++) { init_pair(c,c,COLOR_BLACK); } } void die() { nodelay(stdscr,0); beep(); life--; shots=SHOTS; score=0; sh=0; mvaddch(py+TOPMOST,PX,'*'|COLOR_PAIR(COLOR_RED)); getch(); empty(); clear(); lbot=YSIZE-1; bot=YSIZE-2; ltop=0; top=1; py=mid; if (life<1){again();} draw(); nodelay(stdscr,1); } void newlev() { lv++; turn=TURNS*lv; shots+=SHOTS; magicNumber = CLOCKS_PER_SEC /((float)lv*2+5); if(ECHANCE-(lv*2)>5); echance=ECHANCE-(lv*2); } void draw() { for (y=0;y');} mvprintw(BOTTOM+1,0,"Ammo:%d Score:%d ",shots,score); } void play() { newlev(); clear(); empty(); nodelay(stdscr,1); draw(); last=clock(); while(1) { switch(getch()) { case KEY_UP: case'8': case'k': --py;adv();last=clock();break; case KEY_DOWN: case '2': case'j': ++py;adv();last=clock();break; case KEY_RIGHT: case'6': case'l': adv();last=clock();break; case' ': if(shots>0){ laser();}break; case'p':nodelay(stdscr,0);getch();nodelay(stdscr,1);break; case 'q': again(); default: break; } t=clock()-last; if (t>=magicNumber) { adv(); last=clock(); } } } void laser() { shots--; int l=0; for(l=PX+1;l