This game will help all new C Language Programmers in understanding the concepts of graphics and object oriented programming in C++. So play and enjoy…………

Please post your comments and rate the game. Regards
Ehsan ul haq
[code language=cpp]/*******************************************************
* MYCPLUS Sample Code – https://www.mycplus.com *
* *
* This code is made available as a service to our *
* visitors and is provided strictly for the *
* purpose of illustration. *
* *
* Please direct all inquiries to saqib at mycplus.com *
*******************************************************/

// A GAME BY EHSAN UL HAQ
#include
#include
#include
#include
#include

class ballon
{
protected:
int bx,by,brx,bry,clor;
public:
ballon()
{
bx=400,by=400,brx=15,bry=30,clor=1;
}

void draw_burst ( int a, int b )
{
int x,y;
x=a,y=b;
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 ) ;

}

void olddraw_burst ( int a, int b )
{
int x,y;
x=a,y=b;
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 ) ;

}

void draw()
{
setfillstyle(SOLID_FILL,clor);
fillellipse(bx,by,brx,bry);
setcolor(BLUE);
}
void move()
{
while(!kbhit())
{
static int c=1;
int boy=by;
setfillstyle(SOLID_FILL,clor);
setcolor(WHITE);
fillellipse(bx,by-=10,brx,bry);
rectangle(10,10,getmaxx()-120,getmaxy()-50);
line(getmaxx()-115,80,getmaxx()-20,80);
rectangle(10,10,getmaxx()-120,getmaxy()-50);
delay(200);
setfillstyle(SOLID_FILL,BLACK);
setcolor(BLACK);
fillellipse(bx,boy,brx,bry);
if(by<=5)
{
by=400;
gotoxy(75,7);
cout<3)
{
cleardevice();
setcolor(WHITE);
settextstyle(1,0,5);
outtextxy(200,300,”GAME OVER”);/////////
getch();
exit(1);
}
}
}
}
};
class arrow:public ballon
{
int x,y,sa,ea,r,lx,ly,lx1,ly1;
int rtx,rty,rtx1,rty1;
int ubx,uby,dbx,dby;
public:
arrow():x(100),y(100),sa(270),ea(90),r(30),lx(100),ly(70),lx1(100),ly1(130),
rtx(100),rty(100),rtx1(135),rty1(100),ubx(bx),uby(by),dbx(bx),dby(by)
{}
void snd()
{
sound(2500);
delay(100);
nosound();
}
void score()
{
static int sc=100;
gotoxy(74,3);
cout<<<“\r”;
}
void dw()
{
char op=’/0′;
int oy,oly,oly1;
setcolor(YELLOW);
arc(x,y,sa,ea,r);
line(lx,ly,lx1,ly1);
line(rtx,rty,rtx1,rty1);
ballon::move();
if(kbhit())
{
op=getch();
switch(op)
{
down:
case ‘s’:case ‘S’:
{
while(rty<=390)
{
oy=y,oly=ly,oly1=ly1;
setcolor(YELLOW);
arc(x,y+=10,sa,ea,r);
line(lx,ly+=10,lx1,ly1+=10);
line(rtx,rty+=10,rtx1,rty1+=10);
setcolor(BLACK);
arc(x,oy,sa,ea,r);
line(lx,oly,lx1,oly1);
line(rtx,rty-10,rtx1,rty1-10);
setcolor(YELLOW);
arc(x,y,sa,ea,r);
line(lx,ly,lx1,ly1);
line(rtx,rty,rtx1,rty1);
ballon::move();
op=getch();
if(op==’s’||op==’S’)
continue;
else if(op==’w’||op==’W’)
goto up;
else if(op==’e’||op==’E’)
exit(1);
else
goto fire;
}
}
up:
case ‘w’:case ‘W’:
{
while(rty1>=50)
{
oy=y,oly=ly,oly1=ly1;
setcolor(YELLOW);
arc(x,y-=10,sa,ea,r);
line(lx,ly-=10,lx1,ly1-=10);
line(rtx,rty-=10,rtx1,rty1-=10);
setcolor(BLACK);
arc(x,oy,sa,ea,r);
line(lx,oly,lx1,oly1); ///////////
line(rtx,rty+10,rtx1,rty1+10);
setcolor(YELLOW);
arc(x,y,sa,ea,r);
line(lx,ly,lx1,ly1);
line(rtx,rty,rtx1,rty1);
ballon::move();
op=getch();
if(op==’w’||op==’W’)
continue;
else if(op==’s’||op==’S’)
goto down;
else if(op==’e’||op==’E’)
exit(1);
else
goto fire;
}
}
//////////////fire///////////
fire: ///////////////////////
case ‘i’:
{
bx=bx,by=by;
while(!kbhit())
{
static int sc=100;
int ox=rtx,ox1=rtx1,boy=by;
setcolor(YELLOW);
arc(x,y,sa,ea,r);
line(lx,ly,lx1,ly1);
line(rtx+=15,rty,rtx1+=15,rty1);
if(rtx1>=getmaxx()-130)
{
break;
}
setcolor(YELLOW);
line(100,rty,135,rty1);
setfillstyle(SOLID_FILL,clor);
setcolor(WHITE);
fillellipse(bx,by-=10,brx,bry);
rectangle(10,10,getmaxx()-120,getmaxy()-50);
line(getmaxx()-115,80,getmaxx()-20,80);
rectangle(10,10,getmaxx()-120,getmaxy()-50);
delay(100);
setcolor(BLACK);
line(ox,rty,ox1,rty1);
setfillstyle(SOLID_FILL,BLACK);
setcolor(BLACK);
fillellipse(bx,boy,brx,bry);
if(rtx==bx&&(rty<=by+40&&rty>=by-40))
{
int x=bx,y=by;
setfillstyle(SOLID_FILL,BLACK);
setcolor(BLACK);
fillellipse(bx,by,brx,bry);
setcolor(clor);
ballon::draw_burst(rtx1-30,rty1);
snd();
delay(1000);
bx=400,by=400;
score();
clor++;
setcolor(BLACK);
line(rtx,rty,rtx1,rty1);
delay(300);
break;
}
}
setcolor(BLACK);
ballon::olddraw_burst(rtx1-30,rty1);
setcolor(BLACK);
line(rtx,rty,rtx1,rty1);
ballon::move();
rtx=100,rtx1=135;
}
default:
op=getch();
if(op==’w’||op==’W’)
goto up;
else if(op==’s’||op==’S’)
goto down;
else if(op==’e’||op==’E’)
exit(1);
else
goto fire;
}
}
}
};
class bground
{
public:
void drb()
{
setcolor(WHITE);
rectangle(10,10,getmaxx()-120,getmaxy()-50);
line(getmaxx()-115,80,getmaxx()-20,80);
line(getmaxx()-115,150,getmaxx()-20,150);
rectangle(getmaxx()-115,10,getmaxx()-20,getmaxy()-50);
setcolor(YELLOW);
settextstyle(0,0,1);
outtextxy(530,37,”SCORE:”);
outtextxy(530,100,”MISSED:”);
outtextxy(530,170,”CONTROLS:”);
outtextxy(530,197,”W:MOVE UP”);
outtextxy(530,210,”S:MOVE DOWN”);
outtextxy(530,185,”I:FIRE”);
outtextxy(530,220,”E:EXIT”);
setcolor(14);
settextstyle(4,0,5);
outtextxy(70,430,”BALLON POKING”);
}
};
class start
{
public:
void draw()
{
int c=0;
int d=DETECT,m;
initgraph(&d,&m,”c:\\tc\\bgi”);
setcolor(YELLOW);
setusercharsize(25,15,20,4);
settextstyle(4,0,6);
outtextxy(55,120,”BALLOON POKING”);
settextstyle(0,0,2);
setcolor(WHITE);
outtextxy(85,200,”PRESS ANY KEY TO CONTINUE”);
outtextxy(85,400,”ALL RIGHTS RESERVED(C) 2006″);
outtextxy(85,259,”THIS IS A GAME BY EHSAN UL HAQ”);
getch();
cleardevice();
setcolor(YELLOW);
outtextxy(35,120,”CAUTION:”);
outtextxy(35,140,”DONT PRESS (E) WHILE LOADING”);
setcolor(WHITE);
outtextxy(85,200,”PRESS ANY KEY TO CONTINUE”);
getch();
cleardevice();
while(c!=3)
{
setcolor(WHITE);
settextstyle(1,0,3);
outtextxy(280,300,”LOADING”);
delay(600);
outtextxy(400,300,”.”);
delay(600);
outtextxy(430,300,”.”);
delay(600);
outtextxy(460,300,”.”);
delay(600);
outtextxy(490,300,”.”);
delay(600);
outtextxy(520,300,”.”);
delay(600);
outtextxy(550,300,”.”);
cleardevice();
outtextxy(280,300,”LOADING”);
c++;
}
cleardevice();
}
};
void main()
{
int d=DETECT,m;
initgraph(&d,&m,”c:\\tc\\bgi”);
cleardevice();
start s;
s.draw();
cleardevice();
bground b;
b.drb();
arrow t;
t.dw();
getch();
}[/code]