|
|
I dont think this works properly.This was created by another team....
#include <iostream.h> #include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <dos.h> #include <fstream.h>
fstream file("shoot.txt",ios::binary|ios::ate|ios::in);
int d=0,no_arrow=30; int score1=0,no_balloon=20; char string1[20];
class shoot { private: int p,q,l,m,bx,by; //Private member of the class char ch; public: shoot() //Constructor {q=60;p=140;m=430;bx=60;by=120;} void drawaman(); //Member functions void movement(); void movement_balloon(); void arrow(); void bullet(); void end(); void menu(); void game(); void score(); void draw_burst(int,int); }S; /*-------------------------------------------------------------------------*/ void main() { /* request auto detection */ int gdriver = DETECT, gmode, errorcode;
/* initialize graphics, local variables */ initgraph(&gdriver, &gmode, "c:\\tc");
S.game(); S.menu(); } /*-------------------------------------------------------------------------*/ void shoot:: movement_balloon() {
setcolor(0); setfillstyle(SOLID_FILL,0); //To move the balloon continously fillellipse(470,m+4,15,20); pieslice(470,m+24,310,220,5); line(470, m+24,467,m+84); if((m+40)>=10) { m-=4; setcolor(4); setfillstyle(SOLID_FILL,4); fillellipse(470,m+4,15,20); pieslice(470,m+24,310,220,5); line(470, m+24,467,m+84); } else { m=600; no_balloon-=1; if(no_balloon==0) //If no balloons left- game over { cleardevice(); setcolor(BROWN); settextstyle(1,HORIZ_DIR, 4); outtextxy(130,160,"NO MORE BALLOONS LEFT"); outtextxy(150,100,"YOUR SCORE IS :: "); itoa(score1,string1,10); settextstyle(4,0,4); outtextxy(440,100,string1); end(); }
setcolor(0); setfillstyle(SOLID_FILL,0); fillellipse(470,m+4,15,20); pieslice(470,m+24,310,220,5); line(470, m+24,467,m+84);
} } /*-------------------------------------------------------------------------*/
void shoot:: drawaman() { circle(p+14,q-20,20); //To draw the man line(p+12,q+70,p+12,q); line(p+14,q+70,p+14,q); line(p+10,q+70,p-12,q+80); line(p+15,q+70,p+37,q+80); line(p+15,q+20,p+25,q+15); line(p+15,q+20,p+25,q+25); circle(p+35,q-15,2); circle(p+23,q-22,2); arc(p+25,q-14,200,10,7); } /*-------------------------------------------------------------------------*/
void shoot:: movement() {
if (kbhit()!=0) //To move the man ch=getch();
if (ch==72) //To move the man up { setcolor(0); S.drawaman(); delay(2); if((q-40)>=25) q-=10; setcolor(9); S.drawaman();
} if (ch==80) //To move the man down { setcolor(0); S.drawaman(); delay(2); if((q+40)<=410) q+=10; setcolor(9); S.drawaman(); }
} /*-------------------------------------------------------------------------*/
void shoot:: bullet() { line(bx+40,by,bx+75,by); line(bx+75,by,bx+70,by+10); line(bx+75,by,bx+70,by-10); }
void shoot:: arrow() {
if (kbhit()!=0) //To move the man ch=getch();
if (ch==' '&&no_arrow>0) //To move the man up { setcolor(0); S.bullet(); if((bx+25)<=600) bx+=25; setcolor(9); S.bullet();
}
if(no_arrow==0) //If no arrows left- game over { cleardevice(); setcolor(BROWN); settextstyle(1,HORIZ_DIR, 4); outtextxy(130,160,"NO MORE ARROWS LEFT"); outtextxy(150,100,"YOUR SCORE IS :: "); file.write((char*)&S,sizeof(shoot)); itoa(score1,string1,10); settextstyle(4,0,4); outtextxy(425,100,string1); end(); } if(score1==120) //If score is 80- next level { cleardevice(); setcolor(BROWN); settextstyle(1,HORIZ_DIR, 4); outtextxy(150,160," YOU WON THE GAME"); outtextxy(150,100,"YOUR SCORE IS :: "); itoa(score1,string1,10); settextstyle(4,0,4); outtextxy(425,100,string1); end(); }
} /*-------------------------------------------------------------------------*/
void shoot:: menu() {
int a,s; getch(); cleardevice(); setcolor(6); rectangle(4, 4, 635, 475); rectangle(0, 0, 639, 479); rectangle(6, 6, 633, 473); setcolor(4); outtextxy ( 100,50 ," ENTER THE OPTION"); //Menu outtextxy ( 100,150," 1.INSTRUCTION "); outtextxy ( 100,250," 2.PLAY GAME "); outtextxy ( 100,350," 3.QUIT"); a=getch(); //If option is 1 if(a==49) //Instructions { cleardevice(); setcolor(6); rectangle(4, 4, 635, 475); rectangle(0, 0, 639, 479); rectangle(6, 6, 633, 473); setcolor(4); settextstyle(1,HORIZ_DIR, 5); outtextxy(170,10,"INSTRUCTIONS"); setusercharsize(40,70,20,20); outtextxy(10,70,"1. You can play three levels."); outtextxy(10,110,"2. You can move the man UP and DOWN with the help of arrow keys."); outtextxy(10,150,"3. Press Space Bar to shoot the arrow."); outtextxy(10,190,"4. You score 10 points every time you shoot the balloon."); outtextxy(10,230,"5. First level has 16 arrows and 10 balloons."); outtextxy(10,270,"6. You require to score 80 points to enter the second level."); outtextxy(10,310,"7. Second level has 16 arrows and 13 balloons."); outtextxy(10,350,"8. You require to score 120 points to enter the third level."); outtextxy(10,390,"9. Third level has 16 arrows and 15 balloons."); setcolor(6); outtextxy(200,430,"Press any key to continue"); settextstyle(1,HORIZ_DIR, 5); S.menu(); getch(); }
if(a==51) //If option is 3 { //Exit exit(1); } if(a==50) //If option is 2 { //To play the game cleardevice(); setcolor(9); //To draw the man S.drawaman(); while(1) { setcolor(BROWN); rectangle(114, 4, 635, 475); rectangle(110, 0, 639, 479); rectangle(116, 6, 633, 473);
S.movement(); //To move the man and balloon S.movement_balloon(); if (ch==' ') //Space- to shoot the arrow { bx=p;by=q; s=1;
} if (s==1) { if(getpixel(bx,by)!=BROWN) //To move the arrow till the end { S.arrow(); S.draw_burst(bx,by); } else {
no_arrow-=1; //Reduce the number of arrows s=0; bx=p;by=q; d=0; } } if(ch=='q'||ch=='Q') //To quit { cleardevice(); S.end(); } S.score(); } } } /*-------------------------------------------------------------------------*/
void shoot:: game() { /* set fill style and draw a pie slice */ enum coord { o=7,x1=630, y = 10,y1 = 460, s = 0, e = 360, r = 7 }; while (!kbhit()) { for(int i=0;i<617;i+=17) { int a = rand() % 14 + 1; pieslice(o+i, y, s, e,r); setcolor(a); setfillstyle(SOLID_FILL,a); a = rand() % 14 + 1; setcolor(a); setfillstyle(SOLID_FILL,a); pieslice(x1-i,y1, s, e,r); }
for(i=0;i<450;i+=17) { pieslice(o, y+i, s, e,r); int a = rand() % 14 + 1; setfillstyle(SOLID_FILL,a); setcolor(a); pieslice(x1, y1-i, s, e,r); } settextstyle(1,HORIZ_DIR, 5); outtextxy(130,200,"SHOOT THEM DOWN");
} } /*-------------------------------------------------------------------------*/
void shoot:: draw_burst ( int x, int y ) { if(getpixel(x,y)==RED) //To check if the arrow { //touches the balloon sound(500); delay(3); m=430; //To start the movement of nosound(); //balloon again setcolor(0); setfillstyle(SOLID_FILL,0); bar(450,470,497,10); //To draw the brust setcolor(8); setlinestyle(0,0,1); line (x-16, y-12, x-10, y-2); line (x-10, y-2, x-16, y); line (x-16, y, x-10, y+2); line (x-10, y+2, x-16, y+12);
line ( x-16, y+12, x-6, y+2); line ( x-6, y+2, x, y+12); line ( x, y+12, x+6, y+2); line ( x+6, y+2, x+16, y+12);
line ( x-16, y-12, x-6, y-2 ); line ( x-6, y-2, x, y-12 ); line ( x, y-12, x+6, y-2 ); line ( x+6, y-2, x+16, y-12);
line ( x+16, y-12, x+10, y-2); line ( x+10, y-2, x+16, y); line ( x+16, y, x+10, y+2); line ( x+10, y+2, x+16, y+12); no_balloon-=1; //Reduce the number of balloon if(no_balloon==0) //If no balloons left- game over { cleardevice(); setcolor(BROWN); settextstyle(1,HORIZ_DIR, 4); outtextxy(130,160,"NO MORE BALLOONS LEFT"); outtextxy(150,100,"YOUR SCORE IS :: "); itoa(score1,string1,10); settextstyle(4,0,4); outtextxy(440,100,string1); end(); } score1+=10; //To increase the score delay(100); setfillstyle(SOLID_FILL,0); bar(x-30, y-34,x+30,y+74); //To make the brust black }
} /*-------------------------------------------------------------------------*/
void shoot:: score() { char string[10],s[10],str[10]; setcolor(4); itoa(no_arrow,string,10); settextstyle(4,0,4); outtextxy(50,400,string); //To display number of arrows delay(5); setcolor(0); setfillstyle(1,0); bar(50,400,90,450); //To draw at the side setcolor(9); line(10,420,40,420); line(40,420,35,410); line(40,420,35,430); setcolor(4); //To draw balloon at the side setfillstyle(SOLID_FILL,4); fillellipse(25,320,10,15); line(25,335,27,365); setcolor(4); itoa(no_balloon,str,10); //To display number of balloons settextstyle(4,0,4); outtextxy(50,320,str); delay(5); setcolor(0); setfillstyle(1,0); bar(50,320,90,450); setcolor(4); //For level and quit settextstyle(7,0,3); outtextxy(10,130,"LEVEL"); outtextxy(10,160," 1"); outtextxy(10,230,"Q: QUIT"); outtextxy(10,30,"SCORE"); //To display score itoa(score1,s,10); settextstyle(4,0,4); outtextxy(30,70,s); delay(5); setcolor(0); setfillstyle(1,0); bar(25,70,90,110);
} /*-------------------------------------------------------------------------*/
void shoot:: end() { setcolor(4); rectangle(4, 4, 635, 475); rectangle(0, 0, 639, 479); rectangle(6, 6, 633, 473); setcolor(12); settextstyle(1,HORIZ_DIR, 5); outtextxy(200,205,"GAME OVER"); delay(2000); exit(1); } /*-------------------------------------------------------------------------*/
|