Monday, November 9, 2009

This is game...

#include "stdio.h"
#include "ctype.h"
#include "alloc.h"
#include "graphics.h"
#include "dos.h"
#include "stdlib.h"
#include "conio.h"

#define n 25
void start(void);
void end(void);
void rhits(void);
void yhits(void);
void phits(void);
char *msg;
void *ball, *ball1, *ball2, *gun, *bomb[n];

void *rhrt[n], *yhrt[n], *phrt[n];
int rflag[n], yflag[n], pflag[n];
int rx[n], ry[n], yx[n], yy[n], px[n], py[n];
int j, life = 3;
int rin=0, yin=0, pin=0;
unsigned int size,size1,size2,size3,size4;
int count = 0, r = 10, bct=0;
int nohits = 0, i;
int ats = 0;
int xend = 400, yend = 450;
char che = 3, ch;
int flag = 1, x = 5, gx = 4, hitflag[n];
int speed = 1, hity[n], hitx[n];
int x1 = 200, x2 = 377;
int ti=500;
int flag1 = 1, flag2 = 1;
int rhit = 0, yhit = 0, phit = 0;
struct time t;

void main(void)
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:\tc\bgi");

sprintf(msg,"%c",che);

setcolor(RED);
settextstyle(0,0,30);
outtextxy(getmaxx()/2-130,getmaxy()/2-100,msg);

setcolor(WHITE);
settextstyle(0,0,0);
outtextxy(getmaxx()/2-100,getmaxy()/2-50,"Heart Break Kid Game");
outtextxy(getmaxx()/2-100,getmaxy()/2,"From Prashanth Babu T");

getch();

cleardevice();

start();
for(i=0;i=15)
gx -= 15;
}
else if(ch==77)
{
if(gx<=xend-25) gx += 15; } putimage(gx,yend-14,gun,XOR_PUT); if(ch==72&&life>0)
{
ats += 1;
int remflag = 0;
for(i=0;i1)
{
hitflag[i]= 1;
remflag = 1;
hitx[i] = gx + 8 - 3;
hity[i] = yend - 14 - 15;
putimage(hitx[i],hity[i],bomb[i],XOR_PUT);
break;
}
}
if(remflag==0)
{
for(i=0;i=x&&hitx[i]<=x+20&&hity[i]>=5&&hity[i]<=25) { rhits(); count += 3; rhit += 1; hitflag[i] = 2; } if(hitx[i]>=x1&&hitx[i]<=x1+20&&hity[i]>=150&&hity[i]<=170) { yhits(); count += 2; yhit+=1; hitflag[i] = 2; } if(hitx[i]>=x2&&hitx[i]<=x2+20&&hity[i]>=250&&hity[i]<=270) { phits(); count += 1; phit+=1; hitflag[i] = 2; } if(hity[i]<=2) { hitflag[i] = 2; } if(hitflag[i]==1) { putimage(hitx[i],hity[i],bomb[i],XOR_PUT); } } if(ti>=500)
{
gettime(&t);
sprintf(msg," Current Time:%2d:%02d:%02d",t.ti_hour, t.ti_min,
t.ti_sec);

setfillstyle(1,12);
bar(xend+3,yend+3,getmaxx()-4,getmaxy()-4);
setcolor(BLACK);
settextstyle(0,0,0);

outtextxy(xend+15,yend+10,msg);
ti = 0;
}


putimage(x,5,ball,XOR_PUT);
putimage(x1,150,ball1,XOR_PUT);
putimage(x2,250,ball2,XOR_PUT);

if(flag==1)
x += speed;
else
x -= speed;

if(x>=xend-23)
{
flag = 0;
}
if(x<=1) { flag = 1; } if(flag1==1) x1 += 1+speed; else x1 -= 1+speed; if(x1>=xend-23)
{
flag1 = 0;
}
if(x1<=1) { flag1 = 1; } if(flag2==1) x2 += 2+speed; else x2 -= 2+speed; if(x2>=xend-23)
{
flag2 = 0;
}
if(x2<=1) { flag2 = 1; } putimage(x,5,ball,XOR_PUT); putimage(x1,150,ball1,XOR_PUT); putimage(x2,250,ball2,XOR_PUT); for(i=0;i=gx-5&&rx[i]<=gx+20&&ry[i]>=yend-15&&ry[i]<=yend-5) { // count -= 3; rflag[i] = 2; life--; } } } for(i=0;i=gx-5&&yx[i]<=gx+20&&yy[i]>=yend-15&&yy[i]<=yend-5) { // count -= 2; yflag[i] = 2; life--; } } } for(i=0;i=gx-5&&px[i]<=gx+20&&py[i]>=yend-15&&py[i]<=yend-5) { // count -= 1; pflag[i] = 2; life--; } } } for(i=0;i=yend-5)
{
rflag[i] = 2;
}

for(i=0;i=yend-5)
{
yflag[i] = 2;
}


for(i=0;i=yend-5)
{
pflag[i] = 2;
}


for(i=0;i=30) speed = 2;
if(count>=60) speed = 3;
if(count>=90) speed = 4;
if(count>=120) speed = 5;

delay(12-speed);
ti += 12-speed;
}
}
void end(void)
{
char m[3];
sprintf(m,"%c",3);
clrscr();
cleardevice();
restorecrtmode();
textattr(11);

cprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
gotoxy(20,3);
cprintf("THE SCORE BOARD FOR HEART BREAK KID");
printf("
");

cprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
gotoxy(20,7);
textattr(11);
cprintf("TOTAL NUMBER OF FIRE SHOOTED : %d",ats);
gotoxy(20,9);
cprintf("TOTAL NUMBER OF POINTS SCORED : %d",count);
gotoxy(20,11);
textattr(RED);
cprintf("TOTAL NUMBER OF HITS TO RED HEART : %d",rhit);
gotoxy(20,13);
textattr(YELLOW);
cprintf("TOTAL NUMBER OF HITS TO YELLOW HEART : %d",yhit);
gotoxy(20,15);
textattr(12);
cprintf("TOTAL NUMBER OF HITS OT PINK HEART : %d",phit);
printf("
");
textattr(11);

cprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
getch();
/* int gd=DETECT, gm;
initgraph(&gd,&gm,"c:\tc\bgi");
while(!kbhit())
{
setcolor(random(getmaxcolor()));
settextstyle(0,0,1);
outtextxy(random(getmaxx()),random(getmaxy()),m);
setcolor(12);
settextstyle(0,0,2);
outtextxy(100,250,"THANK YOU FOR PLAYING HBK");
}
closegraph();
restorecrtmode();*/
exit(0);
}
void start(void)
{
cleardevice();
settextstyle(10,0,3);
setcolor(12);
outtextxy(150,100,"HEART BREAK KID");
settextstyle(0,0,2);
outtextxy(200,200,"DEVELOPED BY");
settextstyle(0,0,1);
outtextxy(220, 250,"Mr. Prashanth Babu T");
outtextxy(230, 270,"Vth Semester B.C.A");
outtextxy(140, 300,"PADMASHREE INSTITUTE OF INFORMATION SCIENCES");
outtextxy(230,170,"Demo Version.007");
getch();
cleardevice();
}
void rhits(void)
{
int rflg = 0;
for(j=0;j1)
{
rflag[j] = 1;
rflg = 1;
rx[j] = x-1;
ry[j] = 26;
putimage(rx[j],ry[j],rhrt[j],XOR_PUT);
break;
}
}
if(rflg==0)
{
rflag[rin] = 1;
settextstyle(0,0,1);
setcolor(RED);
sprintf(msg,"%c",che);
outtextxy(x,28,msg);
size2 = imagesize(x-1,28-2,x+8,34);
rhrt[rin] = malloc(size2);
getimage(x-1,28-2,x+8,34,rhrt[rin]);
rx[rin] = x-1;
ry[rin] = 26;
for(j=0;j1)
{
yflag[j] = 1;
yflg = 1;
yx[j] = x1-1;
yy[j] = 171;
putimage(yx[j],yy[j],yhrt[j],XOR_PUT);
break;
}
}
if(yflg==0)
{
yflag[yin] = 1;
settextstyle(0,0,1);
setcolor(YELLOW);
sprintf(msg,"%c",che);
outtextxy(x1,171,msg);
size3 = imagesize(x1-1,171,x1+8,179);
yhrt[yin] = malloc(size3);
getimage(x1-1,171,x1+8,179,yhrt[yin]);
yx[yin] = x1-1;
yy[yin] = 171;
for(j=0;j1)
{
pflag[j] = 1;
pflg = 1;
px[j] = x2-1;
py[j] = 281;
putimage(px[j],py[j],phrt[j],XOR_PUT);
break;
}
}
if(pflg==0)
{
pflag[pin] = 1;
settextstyle(0,0,1);
setcolor(12);
sprintf(msg,"%c",che);
outtextxy(x2,281,msg);
size4 = imagesize(x2-1,281,x2+8,289);
phrt[pin] = malloc(size4);
getimage(x2-1,281,x2+8,289,phrt[pin]);
px[pin] = x2-1;
py[pin] = 281;
for(j=0;j if(pflag[j]==0)
{
pin = j;
break;
}
}
}

Monday, October 26, 2009

PROGRAM TO FIND THE SOLUTION OF ALGEBRIC EQUATIONS USING GAUSS-SEIDEL ITERATIVE METHOD

// SHUAIB SARKAR
// PROGRAM TO FIND THE SOLUTION OF
// ALGEBRIC EQUATIONS USING GAUSS-SEIDEL ITERATIVE METHOD

#include"stdio.h"
#include"conio.h"
#include"math.h"
#define FUNCX(y,z) (17-y+2*z)/20
#define FUNCY(x,z) (-18-3*x+z)/20
#define FUNCZ(x,y) (25-2*x+3*y)/20
void main()
{
float x1,y1,z1;
float a,b,c;
float x2,y2,z2;
int itr=1;
clrscr();
printf("\n\t\t\t GAUSS - SEIDEL ITERATION METHOD");
printf("\n\t\t\t=================================\n");
printf("\n\t\t\tValue Of X\t Value of Y\tValue of Z");
printf("\n======================================================");
x1=y1=z1=0;
do
{
a=FUNCX(y1,z1);
x2=x1;
x1=a;
b=FUNCY(x1,z1);
y2=y1;
y1=b;
c=FUNCZ(x1,y1);
z2=z1;
z1=c;
printf("\n Iterration : %d \t %f\t %f\t%f ",itr++,a,b,c);
}while(a!=x2 && b!=y2 && c!=z2);
printf("\n =====================================================");
printf("\n SOLUTION IS : \n\n X = %f \t Y= %f\t Z= %f",a,b,c);
getch();
}

Saturday, October 24, 2009

PROGRAM TO FIND THE ROOT OF AN EQUATION USING REGULA-FALSE METHOD

// SHUAIB SARKAR
// PROGRAM TO FIND THE ROOT OF AN EQUATION
// USING REGULA-FALSE METHOD

#include"stdio.h"
#include"conio.h"
#include"math.h"
#define FUNC(x) x*x*x-4*x-9

void roots(float x1,float x2)
{
int itr=1;
char trmtr='F';
float a,F1,F2;
do{
F1=FUNC(x1);
F2=FUNC(x2);
a=(x1*F2-F1*x2)/(F2-F1);
if(FUNC(a)<0) x1=a; else x2=a; printf("\n Iterration : %d \t\t %f\t\t %f ",itr,a,FUNC(a)); if(fabs(FUNC(a))<0.0001) { printf("\n=============================================================="); printf("\n Root is : %6.4f\n",a); trmtr='T'; } else { trmtr='F'; itr++; } }while(trmtr=='F'); } void main() { float x1,x2; clrscr(); printf("\n\t\t\t\t REGULA-FALSE METHOD\n"); printf("\n Enter the initial values : "); scanf("%f%f",&x1,&x2); if(FUNC(x1)<0 && FUNC(x2)>0)
{
printf("\n\t\t\t ITERATIONS INVOLVED \n");
printf("\n\t\t\t Aprox Root(s) \t Value of Function\n");
printf("\n===============================================");
roots(x1,x2);
}
else
{
printf("\n ROOTS of the Function don't lie between %3.0f and %3.0f",x1,x2);
getch();
exit(0);
}
getch();
}