#include "stdio.h"
#include "graphics.h"
#include "stdlib.h"
#include "math.h"
#include "time.h"
#define BREADTH 30 //Breadth of card
#define HEIGHT 40 //Height of card
int
xco[4]={0,50,200,350},r=75,x,pos,SPEED=14;
void
swap(
int
a,
int
b,
int
c,
int
t)
{
int
y1,y2;
cleardevice();
if
(pos==a)
pos=b;
else
if
(pos==b)
pos=a;
for
(x=xco[a];x<=xco[b];x++)
{
cleardevice();
y1=200+
sqrt
((r*r)-((x-xco[a]-r)*(x-xco[a]-r)));
y2=200-
sqrt
((r*r)-((x-xco[a]-r)*(x-xco[a]-r)));
rectangle(xco[c],200,xco[c]+BREADTH,200+HEIGHT);
if
(t==1)
{
rectangle(x,y1,x+BREADTH,y1+HEIGHT);
rectangle(xco[b]+xco[a]-x,y2,xco[b]+xco[a]-x+BREADTH,y2+HEIGHT);
}
else
{
rectangle(x,y2,x+BREADTH,y2+HEIGHT);
rectangle(xco[b]+xco[a]-x,y1,xco[b]+xco[a]-x+BREADTH,y1+HEIGHT);
}
delay(SPEED);
}
}
void
start()
{
int
i;
char
str[2];
cleardevice();
for
(i=1;i<=3;i++)
{
rectangle(xco[i],200,xco[i]+BREADTH,200+HEIGHT);
sprintf
(str,
"%c"
,i+48);
outtextxy(xco[i]+BREADTH/2,200+HEIGHT+20,str);
}
for
(i=0;i<10;i++)
{
setfillstyle(SOLID_FILL,3+i);
floodfill(xco[pos]+15,200+15,15);
delay(250);
}
}
int
main()
{
int
gd,gm,a,b,c,t,i;
randomize();
detectgraph(&gd,&gm);
initgraph(&gd,&gm,
"c:\\tc\\bgi"
);
cleardevice();
setcolor(15);
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
pos=
rand
()%3+1;
start();
for
(i=0;i<30;i++)
{
a=
rand
()%2+1;
b=(a==1)?2:3;
c=(a==1)?3:1;
t=
rand
()%2;
swap(a,b,c,t);
if
(SPEED>3)
SPEED--;
}
printf
(
"\n\n\t\tPosition of the Card ? (1, 2 or 3)\n\t\t"
);
scanf
(
"%d"
,&t);
if
(t==pos)
printf
(
"\n\n\t\tCorrect!!!"
);
else
printf
(
"\n\n\t\tWrong!!!"
);
getch();
return
1;
}
No comments:
Post a Comment