#include #include //Clear Screen... clrscr() #include //for delay() char kybd; //to store a keystroke pressed char GameOver; //is 'y' or 'n', means ended or not int shipx, shipy; //position of ship int shiplife; //if shiplife is 0, game over int jetx, jety; //position of jet int jetlife; //if jetlife is 0, game over too void get_input() { kybd=getch(); } //Ship Exlosion void ship_explode() { sound(1000); gotoxy(shipx, shipy); cout<<"."; delay (1000); gotoxy(shipx, shipy); cout<<"(.)"; delay (1000); gotoxy(shipx, shipy); cout<<"((.))"; delay (1000); nosound(); if (shiplife==0) GameOver='y'; } //Jet Explode void jet_explode() { sound(1000); gotoxy(jetx, jety); cout<<"."; nosound(); jetlife--; if (shiplife==0) GameOver='y'; } // Ship Fire void ship_fire() { int y; for(y=shipy-1; y>1; y--) { gotoxy(shipx,y); cout<<" |"; delay(10); } if (shipx==jetx+2) jet_explode(); if (shipx==jetx+1) jet_explode(); if (shipx==jetx-1) jet_explode(); if (shipx==jetx-2) jet_explode(); } //Jet Fire void jet_fire() { int y; for(y=jety; y<23; y++) { gotoxy(jetx,y); cout<<" |"; delay(10); } if (jetx==shipx+2) ship_explode(); if (jetx==shipx+1) ship_explode(); if (jetx==shipx-1) ship_explode(); if (jetx==shipx-2) ship_explode(); } //Process void do_process() { //Ship Control if (kybd=='j') shipx--; //Ship move left else if (kybd=='l') shipx++; //Ship move right else if (kybd=='i') shipy--; //Ship move up else if (kybd=='k') shipy++; //Ship move down else if (kybd=='o') ship_fire(); //Ship Fire //Jet Control if (kybd=='a') jetx--; //Jet move left else if (kybd=='d') jetx++; //Jet move right else if (kybd=='w') jety--; //Jet move up else if (kybd=='s') jety++; //Jet move down else if(kybd=='z') jet_fire(); //Jet Fire //Quit Program if (kybd=='q') GameOver='y'; //Program Quit //Limit Ship if (shipx<1) shipx=1; if (shipx>75) shipx=75; //Minus 5 Chars cuz Ship 5 Chars if (shipy<1) shipy=1; if (shipy>25) shipy=25; //Limit Jet if (jetx<1) jetx=1; if (jetx>75) jetx=75; //Minus 7 Chars cuz Jet 7 Chars if (jety<1) jety=1; if (jety>25) jety=25; } void give_output() { clrscr(); //Ship Life if(shiplife>0) { gotoxy(shipx, shipy); cout<<"_[^]_"; } //Jet Life if(jetlife>0) { gotoxy(jetx,jety); cout<<"=[^]="; } } void main() { clrscr(); shipx=40; shipy=23; shiplife=1; jetx=20; jety=2; jetlife=1; GameOver='n'; //Game is not over yet at the beginning.. while (GameOver!='y') { get_input(); do_process(); give_output(); } //Message For Loser cout<<" GAME OVER!"<