saalek
مدیر بازنشسته
در اين تاپيك سورسهاي گرافيكي سي را قرار خواهيم داد.
سورسهايي را كه اجرا مي شوند قرار خواهم داد. و همه با توربو سي چك مي شوند.
.
سورسهايي را كه اجرا مي شوند قرار خواهم داد. و همه با توربو سي چك مي شوند.
.
#include<conio.h>
#include<iostream.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
#include<stdlib.h>
#include<alloc.h>
void main()
{
int d=DETECT,m,r=50;
float gx,gy,x,y,x1,y1,xm,ym,xh,yh,k=0,i,j,ii,l;
initgraph(&d,&m,"c:\\tc\\bgi");
struct time t;
void *mem;
int size;
ii=13.89;
setcolor(14);
line(159,100,159,387);
line(450,100,450,382);
line(159,100,450,100);
setcolor(14);
arc(300,100,236,307,250);
arc(300,100,244,298,320);
//14.36,13.89
while(1)
{
while(ii<14.36)
{
if(kbhit())
exit(1);
// second's pixel
for(i=11;i<=17.3;i+=0.105)
{
gx=55*cos(i);
gy=55*sin(i);
putpixel(gx+300,gy+200,4);
}
// outer circle
setcolor(12);
circle(300,200,85);
circle(300,200,87);
circle(300,200,90);
setcolor(15);
circle(300,200,80);
setcolor(4);
outtextxy(330,143,"1");
outtextxy(350,165,"2");
outtextxy(360,197,"3");
outtextxy(352,228,"4");
outtextxy(328,252,"5");
outtextxy(298,260,"6");
outtextxy(264,252,"7");
outtextxy(242,226,"8");
outtextxy(235,197,"9");
outtextxy(235,165,"10");
outtextxy(260,140,"11");
outtextxy(292,135,"12");
//time function
///*
gettime(&t);
gotoxy(35,20);
cout<<int(t.ti_hour)<<":"<<int(t.ti_min)<<":"<<int(t.ti_sec)<<"";
i=(int(t.ti_sec)*(0.105))+11;
j=(int(t.ti_min)*(0.105))+11;
k=((int(t.ti_hour)*(0.105))*5+11);
int min=int (t.ti_min);
int rem=min/12;
k=k+(rem*0.105);
///*/
//calculations for second hand
x=r*cos(i);
y=r*sin(i);
setcolor(14);
line(300,200,x+300,y+200);
//calculations for minute hand
xm=(r-5)*cos(j);
ym=(r-5)*sin(j);
setcolor(9);
line(300,200,xm+300,ym+200);
//calculations for hour hand
xh=(r-20)*cos(k);
yh=(r-20)*sin(k);
setcolor(6);
line(300,200,xh+300,yh+200);
delay(200.5);
int pks=0;
if(kbhit())
exit(1);
float l,m;
for(pks=1;pks<=4;pks++)
{
l=200*cos(ii);
m=200*sin(ii);
setcolor(4);
line(300,290,300+l,190+m);
setcolor(14);
setfillstyle(SOLID_FILL,14);
circle(l+300,m+190,15);
floodfill(l+300,m+190,14);
ii+=.105;
delay(200.5);
setcolor(0);
setfillstyle(SOLID_FILL,0);
circle(l+300,m+190,15);
floodfill(l+300,m+190,0);
line(300,290,300+l,190+m);
}
setcolor(0);
line(300,200,x+300,y+200);
line(300,200,xm+300,ym+200);
line(300,200,xh+300,yh+200);
}
while(ii>13.89)
{
if(kbhit())
exit(1);
for(i=11;i<=17.3;i+=0.105)
{
gx=55*cos(i);
gy=55*sin(i);
putpixel(gx+300,gy+200,4);
}
setcolor(12);
circle(300,200,85);
circle(300,200,87);
circle(300,200,90);
setcolor(15);
setfillstyle(SOLID_FILL,0);
circle(300,200,80);
floodfill(300,200,0);
setcolor(4);
outtextxy(330,143,"1");
outtextxy(350,165,"2");
outtextxy(360,197,"3");
outtextxy(352,228,"4");
outtextxy(328,252,"5");
outtextxy(298,260,"6");
outtextxy(264,252,"7");
outtextxy(242,226,"8");
outtextxy(235,197,"9");
outtextxy(235,165,"10");
outtextxy(260,140,"11");
outtextxy(292,135,"12");
gettime(&t);
gotoxy(35,20);
cout<<int(t.ti_hour)<<":"<<int(t.ti_min)<<":"<<int(t.ti_sec)<<"";
i=(int(t.ti_sec)*(0.105))+11;
j=(int(t.ti_min)*(0.105))+11;
k=((int(t.ti_hour)*(0.105))*5+11);
int min=int (t.ti_min);
int rem=min/12;
k=k+(rem*0.105);
x=r*cos(i);
y=r*sin(i);
setcolor(14);
line(300,200,x+300,y+200);
xm=(r-5)*cos(j);
ym=(r-5)*sin(j);
setcolor(9);
line(300,200,xm+300,ym+200);
xh=(r-20)*cos(k);
yh=(r-20)*sin(k);
setcolor(6);
line(300,200,xh+300,yh+200);
delay(200.5);
if(kbhit())
exit(1);
for(int pks=1;pks<=4;pks++)
{
l=200*cos(ii);
m=200*sin(ii);
setcolor(4);
line(300,290,300+l,190+m);
setcolor(14);
setfillstyle(SOLID_FILL,14);
circle(l+300,m+190,15);
floodfill(l+300,m+190,14);
ii-=0.105;
delay(200.5);
setcolor(0);
setfillstyle(SOLID_FILL,0);
circle(l+300,m+190,15);
floodfill(l+300,m+190,0);
line(300,290,300+l,190+m);
}
setcolor(0);
line(300,200,x+300,y+200);
line(300,200,xm+300,ym+200);
line(300,200,xh+300,yh+200);
}
}
}
#include<iostream.h>
#include<graphics.h>
#include<iomanip.h>
#include<fstream.h>
#include<stdlib.h>
#include<string.h>
#include<alloc.h>
#include<conio.h>
#include<stdio.h>
#include<time.h>
#include<bios.h>
#include<dos.h>
int j=15,h=1;
class mouse
{
private:
union REGS i,o;
public:
mouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
if(o.x.ax==0)
{
closegraph();
restorecrtmode();
cout<<"Mouse driver not loaded !";
exit(1);
}
}
void showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
}
void restrictmouseptr(int x1,int y1,int x2,int y2)
{
i.x.ax=7;
i.x.cx=x1;
i.x.dx=x2;
int86(0x33,&i,&o);
i.x.ax=8;
i.x.cx=y1;
i.x.dx=y2;
int86(0x33,&i,&o);
}
void getmousepos(int *button,int *x,int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}
void hidemouseptr()
{
i.x.ax=2;
int86(0x33,&i,&o);
}
}m;
void start()
{
int flow=1,y=500,x=220,xx=75,n=45,i=1,a,b,c,mx,my;
mx=getmaxx();
my=getmaxy();
time_t tt,st;
setbkcolor(0);
setcolor(11);
tt=time(NULL);
while(time(NULL)<=tt+30)
{
if(flow==1)
y-=3;
else
y+=3;
cleardevice();
settextstyle(10,0,7);
outtextxy(x-126,y,"ART PAD");
delay(50);
if(y<=0)
flow=0;
if(y>=100&&flow==0)
{
st=time(NULL);
while(time(NULL)<=st+1)
{
a=random(mx);
b=random(my);
c=random(15);
putpixel(a,b,c);
delay(1);
}
while(time(NULL)<=st+5)
{
setcolor(i++);
outtextxy(x-126,y,"ART PAD");
delay(100);
setcolor(3);
outtextxy(x-126,y,"ART PAD");
}
break;
}
}
setcolor(14);
settextstyle(7,0,2);
xx+=40;
outtextxy(xx+178,280,"B");
delay(300);
xx+=n-25;
outtextxy(xx+178,280,"Y");
delay(300);
xx+=n-12;
st=time(NULL);
while(time(NULL)<=st+5)
{
xx=119;
setcolor(i++);
settextstyle(7,0,4);
outtextxy(xx,360,"S");
delay(10);
xx+=n-5;
outtextxy(xx,360,".");
delay(10);
xx+=n-25;
outtextxy(xx,360,"R");
delay(10);
xx+=n-13;
outtextxy(xx,360,"A");
delay(10);
xx+=n-15;
outtextxy(xx,360,"M");
delay(10);
xx+=n-15;
outtextxy(xx,360,"A");
delay(10);
xx+=n-15;
outtextxy(xx,360,"C");
delay(10);
xx+=n-15;
outtextxy(xx,360,"H");
delay(10);
xx+=n-15;
outtextxy(xx,360,"A");
delay(10);
xx+=n-15;
outtextxy(xx,360,"N");
delay(10);
delay(10);
xx+=n-15;
outtextxy(xx,360,"D");
delay(10);
delay(10);
xx+=n-15;
outtextxy(xx,360,"R");
delay(10);
delay(10);
xx+=n-15;
outtextxy(xx,360,"E");
delay(10);
delay(10);
xx+=n-15;
outtextxy(xx,360,"N");
delay(10);
}
}
void box(int l,int t,int r,int b,int ch)
{
int a,bb,lt1,lt2;
if(ch==0)
{
a=8;
bb=15;
}
else if(ch==1)
{
a=15;
bb=8;
}
setcolor(bb);
line(l,t,r,t);
line(l,t,l,b);
setcolor(a);
line(l,b,r,b);
line(r,b,r,t);
}
void name(char str[])
{
int max=20;
void far *blank;
settextstyle(0,0,1);
blank=farmalloc(imagesize(1,461,439,476));
if(blank==NULL)
{
closegraph();
cout<<"ALLOCATION ERROR";
return;
}
getimage(1,461,439,476,blank);
char ch=0;
int len=0;
str[len]='\0';
char st[100];
while(ch!=13)
{
setcolor(11);
outtextxy(349,465,"(HIT ENTER)");
strcpy(st,"Enter file name: ");
strcat(st,str);
outtextxy(5,465,st);
ch=getch();
if(ch==8)
{
if(len!=0)
len--;
str[len]='\0';
}
else if(ch!=13&&ch!=0&&ch>=32)
{
if(len!=max)
{
str[len]=ch;
len++;
str[len]='\0';
}
}
putimage(1,461,blank,COPY_PUT);
}
putimage(1,461,blank,COPY_PUT);
farfree(blank);
}
void save()
{
char str[100];
m.hidemouseptr();
name(str);
ofstream f(str,ios::binary|ios::trunc);
setcolor(11);
outtextxy(5,465,"Status : Saving file ");
for(int x=1;x<=439;x++)
{
for(int y=1;y<=460;y++)
f.put(getpixel(x,y));
f.put('\n');
}
f.close();
setcolor(0);
outtextxy(5,465,"Status : Saving file ");
m.showmouseptr();
}
void load()
{
char str[100];
m.hidemouseptr();
name(str);
ifstream f(str,ios::binary|ios::trunc);
if(f.bad())
{
setcolor(11);
outtextxy(5,465,"ERROR OPENING FILE ");
outtextxy(349,465,"(HIT ENTER)");
getch();
setcolor(0);
outtextxy(5,465,"ERROR OPENING FILE ");
outtextxy(349,465,"(HIT ENTER)");
return;
}
setcolor(11);
outtextxy(5,465,"Status : Loading file ");
char ch;
for(int x=1;x<=439;x++)
{
for(int y=1;y<=460;y++)
{
ch=f.get();
putpixel(x,y,ch);
}
ch=f.get();
}
f.close();
setcolor(0);
outtextxy(5,465,"Status : Loading file ");
m.showmouseptr();
}
void load_help()
{
m.hidemouseptr();
ifstream f("help.hlp",ios::binary|ios::trunc);
if(f.bad())
{
setcolor(11);
outtextxy(5,465,"ERROR OPENING FILE ");
outtextxy(349,465,"(HIT ENTER)");
getch();
setcolor(0);
outtextxy(5,465,"ERROR OPENING FILE ");
outtextxy(349,465,"(HIT ENTER)");
return;
}
char ch;
for(int y=1;y<=460;y++)
{
for(int x=1;x<=439;x++)
{
ch=f.get();
putpixel(x,y,ch);
}
ch=f.get();
}
f.close();
m.showmouseptr();
}
void load_credits()
{
m.hidemouseptr();
ifstream f("credits.cdt",ios::binary|ios::trunc);
if(f.bad())
{
setcolor(11);
outtextxy(5,465,"ERROR OPENING FILE ");
outtextxy(349,465,"(HIT ENTER)");
getch();
setcolor(0);
outtextxy(5,465,"ERROR OPENING FILE ");
outtextxy(349,465,"(HIT ENTER)");
return;
}
char ch;
for(int y=1;y<=460;y++)
{
for(int x=1;x<=439;x++)
{
ch=f.get();
putpixel(x,y,ch);
}
ch=f.get();
}
f.close();
m.showmouseptr();
}
void set_buttons()
{
int i,up=485,dn=320,a,b,run,w=20,ht=60,wd=20,c=0;
setfillstyle(SOLID_FILL,7);
bar(440,1,637,477);
setfillstyle(SOLID_FILL,j);
bar(486,408,620,422);
box(495,440,610,460,0);
box(482,205,624,225,0);
box(482,233,624,253,0);
box(482,175,624,195,0);
box(482,261,624,281,0);
box(482,289,624,309,0);
box(447,16,467,145,0);
box(447,165,467,294,0);
box(447,314,467,431,0);
box(482,65,624,85,0);
box(482,95,624,115,0);
rectangle(475,15,632,430);
rectangle(482,390,624,425);
a=up;
b=dn;
run=1;
for(;b<=dn+ht;)
{
for(;a<=639-wd;run++)
{
setcolor(0);
if(c<=15)
{
setfillstyle(SOLID_FILL,c++);
bar(a,b,a+w,b+w);
}
rectangle(a,b,a+w,b+w);
a+=w+3;
}
a=up;
b+=w+3;
}
line(478,140,538,140);
line(515,164,591,164);
line(486,185,620,185);
line(486,215,620,215);
line(486,216,620,216);
line(486,243,620,243);
line(486,244,620,244);
line(486,242,620,242);
line(486,271,620,271);
line(486,272,620,272);
line(486,270,620,270);
line(486,269,620,269);
line(482,405,624,405);
setcolor(7);
line(0,460,439,460);
settextstyle(4,0,4);
setcolor(4);
outtextxy(480,10,"A");
setcolor(13);
outtextxy(502,10,"R");
setcolor(9);
outtextxy(524,10,"T");
setcolor(10);
outtextxy(566,10,"P");
setcolor(11);
outtextxy(588,10,"A");
setcolor(12);
outtextxy(610,10,"D");
setcolor(0);
settextstyle(2,0,5);
outtextxy(478,125,"POSITION:");
outtextxy(528,291,"ERASER");
outtextxy(515,150,"BRUSH SIZE");
outtextxy(505,442,"CLEAR SCREEN");
settextstyle(0,0,1);
outtextxy(536,72,"HELP");
outtextxy(525,102,"CREDITS");
settextstyle(14,0,5);
outtextxy(502,395,"CHOSEN COLOUR");
settextstyle(2,0,7);
outtextxy(453,23,"S");
outtextxy(453,53,"A");
outtextxy(453,83,"V");
outtextxy(453,113,"E");
outtextxy(453,172,"L");
outtextxy(453,202,"O");
outtextxy(453,232,"A");
outtextxy(453,262,"D");
outtextxy(453,325,"Q");
outtextxy(453,350,"U");
outtextxy(455,375,"I");
outtextxy(453,400,"T");
setcolor(4);
settextstyle(2,0,5);
outtextxy(502,463,"www.artpad.com");
}
void reset()
{
setcolor(12);
switch(h)
{
case 1:
{
line(486,185,620,185);
box(482,175,624,195,1);
break;
}
case 2:
{
line(486,215,620,215);
line(486,216,620,216);
box(482,205,624,225,1);
break;
}
case 3:
{
line(486,243,620,243);
line(486,244,620,244);
line(486,242,620,242);
box(482,233,624,253,1);
break;
}
case 4:
{
line(486,271,620,271);
line(486,272,620,272);
line(486,270,620,270);
line(486,269,620,269);
box(482,261,624,281,1);
break;
}
case 5:
{
settextstyle(2,0,5);
setcolor(12);
outtextxy(528,291,"ERASER");
box(482,289,624,309,1);
break;
}
}
}
void main()
{
int gd=DETECT,gm,xx,yy,x,y,button;
initgraph(&gd,&gm,"c:\\tc\\bgi");
start();
setcolor(7);
rectangle(0,0,getmaxx(),getmaxy());
setviewport(1,1,getmaxx()-1,getmaxy()-1,0);
m.restrictmouseptr(3,3,getmaxx(),getmaxy()-5);
clearviewport();
setfillstyle(SOLID_FILL,3);
set_buttons();
setcolor(12);
line(486,185,620,185);
box(482,175,624,195,1);
m.showmouseptr();
while(1)
{
m.getmousepos(&button,&x,&y);
if(x>=482&&x<=624&&y>=65&&y<=85&&(button&1)==1)
{
m.hidemouseptr();
set_buttons();
settextstyle(0,0,1);
setcolor(12);
outtextxy(536,72,"HELP");
box(482,65,624,85,1);
load_help();
}
if(x>=483&&x<=624&&y>=95&&y<=114&&(button&1)==1)
{
m.hidemouseptr();
set_buttons();
settextstyle(0,0,1);
setcolor(12);
outtextxy(525,102,"CREDITS");
box(482,95,624,115,1);
load_credits();
}
if(x>=483&&x<=624&&y>=175&&y<=195&&(button&1)==1)
{
h=1;
m.hidemouseptr();
set_buttons();
setcolor(12);
line(486,185,620,185);
box(482,175,624,195,1);
}
if(x>=483&&x<=624&&y>=205&&y<=225&&(button&1)==1)
{
h=2;
m.hidemouseptr();
set_buttons();
setcolor(12);
line(486,215,620,215);
line(486,216,620,216);
box(482,205,624,225,1);
}
if(x>=483&&x<=624&&y>=233&&y<=253&&(button&1)==1)
{
h=3;
m.hidemouseptr();
set_buttons();
setcolor(12);
line(486,243,620,243);
line(486,244,620,244);
line(486,242,620,242);
box(482,233,624,253,1);
}
if(x>=483&&x<=624&&y>=261&&y<=281&&(button&1)==1)
{
h=4;
m.hidemouseptr();
set_buttons();
setcolor(12);
line(486,271,620,271);
line(486,272,620,272);
line(486,270,620,270);
line(486,269,620,269);
box(482,261,624,281,1);
}
if(x>=483&&x<=625&&y>=289&&y<=309&&(button&1)==1)
{
h=0;
m.hidemouseptr();
set_buttons();
settextstyle(2,0,5);
setcolor(12);
outtextxy(528,291,"ERASER");
box(482,289,624,309,1);
}
if((button&1)==1)
{
xx=x;
yy=y;
while(x<=437&&y<=456)
{
if((button&1)==1&&x<=470&&y<=477)
{
m.hidemouseptr();
setcolor(j);
switch(h)
{
case 1:
{
line(xx,yy,x,y);
break;
}
case 2:
{
line(xx,yy,x,y);
line(xx+1,yy+1,x+1,y+1);
break;
}
case 3:
{
line(xx,yy,x,y);
line(xx+1,yy+1,x+1,y+1);
line(xx-1,yy-1,x-1,y-1);
break;
}
case 4:
{
line(xx,yy,x,y);
line(xx+1,yy+1,x+1,y+1);
line(xx-1,yy-1,x-1,y-1);
line(xx+2,yy+2,x+2,y+2);
break;
}
case 5:
{
line(xx,yy,x,y);
line(xx+1,yy+1,x+1,y+1);
line(xx-1,yy-1,x-1,y-1);
line(xx+2,yy+2,x+2,y+2);
line(xx-2,yy-2,x-2,y-2);
break;
}
default:
{
setcolor(0);
line(xx,yy,x,y);
line(xx+1,yy+1,x+1,y+1);
line(xx-1,yy-1,x-1,y-1);
line(xx+2,yy+2,x+2,y+2);
line(xx-2,yy-2,x-2,y-2);
break;
}
}
xx=x;
yy=y;
m.showmouseptr();
}
xx=x;
yy=y;
m.getmousepos(&button,&x,&y);
}
}
if(x>=448&&x<=467&&y>=16&&y<=145&&(button&1)==1)
{
reset();
m.hidemouseptr();
setcolor(12);
settextstyle(2,0,7);
outtextxy(453,23,"S");
outtextxy(453,53,"A");
outtextxy(453,83,"V");
outtextxy(453,113,"E");
box(447,16,467,145,1);
save();
delay(300);
set_buttons();
reset();
}
if(x>=448&&x<=468&&y>=166&&y<=295&&(button&1)==1)
{
reset();
m.hidemouseptr();
setcolor(12);
settextstyle(2,0,7);
outtextxy(453,172,"L");
outtextxy(453,202,"O");
outtextxy(453,232,"A");
outtextxy(453,262,"D");
box(447,165,467,294,1);
load();
delay(300);
set_buttons();
reset();
}
if(x>=496&&x<=611&&y>=441&&y<=461&&(button&1)==1)
{
reset();
settextstyle(2,0,5);
setcolor(12);
m.hidemouseptr();
outtextxy(505,442,"CLEAR SCREEN");
box(495,440,610,460,1);
delay(50);
clearviewport();
set_buttons();
setfillstyle(SOLID_FILL,j);
bar(486,408,620,422);
reset();
}
if(x>=448&&x<=468&&y>=315&&y<=432&&(button&1)==1)
{
settextstyle(2,0,7);
m.hidemouseptr();
setcolor(12);
settextstyle(2,0,7);
outtextxy(453,325,"Q");
outtextxy(453,350,"U");
outtextxy(455,375,"I");
outtextxy(453,400,"T");
box(447,314,467,431,1);
return;
}
if(x>=487&&x<=620&&y>=322&&y<=386&&(button&1)==1)
{
m.hidemouseptr();
j=getpixel(x,y);
m.showmouseptr();
setfillstyle(SOLID_FILL,j);
bar(486,408,620,422);
}
setcolor(0);
settextstyle(2,0,5);
outtextxy(543,125,"X=");
outtextxy(590,125,"Y=");
gotoxy(71,9);
cout<<setw(3)<<x;
gotoxy(77,9);
cout<<setw(3)<<y;
m.showmouseptr();
}
}
//Essential Library
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
int main(void)
{
int gdriver = DETECT;
int gmode,errorcode,a,b,s;
float k,x,y,i,j;
float pi = 3.14159;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
errorcode = graphresult();
if ( errorcode != grOk)
{
exit(1);
}
s = 0;
setcolor(12);
do {
i = 38+100*cos(pi*s/190);
j = 175+100*sin(pi*s/190);
x = (int)i;
y = (int)j;
circle(x+s,y,(int)y/6);
s=s+3;
} while (s<550);
getch();
closegraph();// Return into text mode
return 0;
}//End of program
/*********By : FARSHAD MOJTABAI*********/
/***********With Graphic****************/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
int place(int);
void queen(int);
void Board();
void Q(int,int);
void CounT(int,int,int);
int XYGraphic(int);
int x[9];
int main(void)
{
queen(8);
return 0;
}
void queen(int n)
{
int k= 1,z,X,Y,counter=0,x2,y2,loc;
int extern x[9];
char answer;
int gdriver = DETECT, gmode, errorcode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
x[1] = 0;
printf("WHETHER YOU WANT TO CHOOSE A COORDINATE <Press C> OR\n");
printf("COMPUTER TAKES ALL POSSIBLE CASES <Press A>:");
scanf("%c",&answer);
if(answer == 'c' || answer == 'C')
{
printf("X,Y:");
scanf("%d%d",&x2,&y2);
}
clearviewport();
while(k > 0)
{
x[k]++ ;
while(x[k] <= n && !place(k))
x[k]++;
if(x[k] <= n)
{
if(k == n)
{
if(answer == 'a' || answer == 'A')
{
Board();
counter++;
for(int m=1;m<9;m++)
{
z=x[m];
X = XYGraphic(m);
Y = XYGraphic(z);
Q(X,Y);
CounT(m,z,counter);
}
delay(3000);
}
else if(answer == 'c' || answer == 'C')
{
for(int i=1;i<9;i++)
if(i==x2 && x[i]==y2)
loc = 1;
if(loc == 1)
{
Board();
counter++;
for(int m=1;m<9;m++)
{
z=x[m];
X = XYGraphic(m);
Y = XYGraphic(z);
Q(X,Y);
CounT(m,z,counter);
}
loc = 0;
delay(3000);
}
}
if(kbhit())
exit(0);
clearviewport();
}
else
{
k++;x[k]=0;}
}
else
k--;
}
}
int place(int l)
{
int i=1;
int extern x[9];
while(i < l)
{
if((x[i] == x[l]) || abs(x[i] -x[l]) == abs(i - l))
return(0);
i +=1;
}
return(1);
}
int XYGraphic(int p)
{
switch(p)
{
case 1: return 65;
case 2: return 115;
case 3: return 165;
case 4: return 215;
case 5: return 265;
case 6: return 315;
case 7: return 365;
case 8: return 415;
}
return 0;
}
void CounT(int x3,int y3,int c)
{
gotoxy(60,4);
printf("[%d]",c);
gotoxy(59,6+x3);
printf("(%c,%d)",96+x3,y3);
}
void Q(int x1,int y1)
{
for(int i=0;i<=15;i++)
{
setcolor(i);
circle(x1,y1,i);
}
}
void Board()
{
int m,n;
outtextxy(65,20,"a");
outtextxy(115,20,"b");
outtextxy(165,20,"c");
outtextxy(215,20,"d");
outtextxy(265,20,"e");
outtextxy(315,20,"f");
outtextxy(365,20,"g");
outtextxy(415,20,"h");
outtextxy(20,65,"1");
outtextxy(20,115,"2");
outtextxy(20,165,"3");
outtextxy(20,215,"4");
outtextxy(20,265,"5");
outtextxy(20,315,"6");
outtextxy(20,365,"7");
outtextxy(20,415,"8");
for(int j=0;j<8;j++)
for(int i=0; i<8;i++)
rectangle(50*i+40,50*j+40,50*(i+1)+40,50*(j+1)+40);
for(int l=0;l<8;l++)
{
if(l%2 == 0)
{m=0; n=0;}
else
{m=1; n=50;}
for(int k=0;k<4+m;k++)
{
setfillstyle(SOLID_FILL,getmaxcolor());
floodfill(100*k-n+41,50*l+41,getmaxcolor());
}
}
}
/****************************************************************
Chess Game V1.0
If u like this Program then pls vote it
/*****************************************************************/
//THIS PROGRAM WILL CREATE A TWO PLAYER CHESS
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<process.h>
#include<math.h>
#include<dos.h>
void move_control (int[8][8],int[],int x1=171,int y1=171,int x2=221, int y2=221); //specifying default values
void move_right (int&,int,int&,int,int);
void move_left (int&,int,int&,int,int);
void move_down (int,int&,int,int&,int);
void move_up (int,int&,int,int&,int);
void decolorize_shadow (int,int,int,int);
void chessboard (void);
void piece_position ( int[8][8] );
void place_pieces (int[8][8],int[8][8]);
void draw_pawn(int,int,int,int);
void draw_knight(int,int,int,int);
void draw_bishop(int,int,int,int);
void draw_rook(int,int,int,int);
void draw_king(int,int,int,int);
void draw_queen(int,int,int,int);
void coordinate_manager(int*,int*);
int verify_move (int,int,int,int,int[8][8]);
int jump_test (int,int,int,int,int[8][8]);
int move_pawn (int,int,int,int,int,int[8][8],int[8][8],int*);
void update_pawns(int[8][8],int,int,int,int,int);
void move_piece (int,int,int,int,int[8][8],int[8][8]);
void king_status(int[8][8]);
void rubber(int,int,int);
void messages (int);
extern int turn = 0; //global variable
void main (void)
{
clrscr();
int positions[8][8] = {0}; //contains positions of all pieces on the board
int colormap[8][8] = {0}; //contains color with which pieces will be drawn
int move_info[4]; //contains informations of a piece's (that has been moved) old and new positions [newx] [newy] [oldx] [oldy]
int gatekeeper = 0;
int gdriver = DETECT, gmode;
initgraph (&gdriver, &gmode, "C:\\TC\\BGI"); //starting graphics engine
while ( 1 )
{
if ( gatekeeper == 0 )
{
chessboard (); //drawing chessboard
piece_position ( positions ); //placing pieces (internally)
place_pieces ( positions,colormap ); //placing pieces (graphically)
}
messages ( 0 );
move_control ( positions,move_info ); //piece to move
move_piece ( move_info[0],move_info[1],move_info[2],move_info[3],positions,colormap); //moves a piece
king_status ( positions );
if ( turn == 0 )
turn = 1;
else
turn = 0;
gatekeeper++;
}//end of while
}//end of main function
void chessboard (void)
{
clrscr();
setfillstyle(SOLID_FILL,LIGHTGREEN); //colours the
floodfill(320,240,2); //background
setlinestyle (SOLID_LINE,1,THICK_WIDTH); //for thick edge of the board
setcolor(BLACK);
int x1=21,y1=21,x2=71,y2=71;
for (int j=1; j <= 8; j++)
{
for (int i=1; i <= 8; i++)
{
rectangle(x1,y1,x2,y2);
if ( j%2 == 0)
if ( i%2 == 0 )
setfillstyle (SOLID_FILL, BLACK); //colouring
else
setfillstyle (SOLID_FILL, WHITE);
else //alternate
if ( i%2 == 0 )
setfillstyle (SOLID_FILL, WHITE);
else //boxes
setfillstyle (SOLID_FILL, BLACK);
floodfill (x1+3, y1+3, BLACK);
x1 += 50;
x2 += 50;
}//end of loop (that prints boxes in horizontal)
x1 = 21;
x2 = 71;
y1 += 50;
y2 += 50;
}//end of for loop (that prints boxes in vertical)
setcolor(WHITE);
setlinestyle (SOLID_LINE,1,THICK_WIDTH);
setfillstyle (SOLID_FILL, BLACK); //draws the
rectangle (473,21,619,91); //message window
floodfill (483,25,WHITE);
setlinestyle (SOLID_LINE,1,NORM_WIDTH);
}//end of chessboard function
void piece_position ( int positions[8][8] )
{
enum {WHITE_PAWN=1, WHITE_ROOK, WHITE_KNIGHT, WHITE_BISHOP,//specifying constants ranging
WHITE_QUEEN, WHITE_KING, BLACK_PAWN, BLACK_ROOK, //from 1 to 12. e.g., 6 represent white_king
BLACK_KNIGHT, BLACK_BISHOP, BLACK_QUEEN, BLACK_KING};//and 11 represents black_queen
positions[0][0] = ( positions[7][0] = BLACK_ROOK );
positions[1][0] = ( positions[6][0] = BLACK_KNIGHT );
positions[2][0] = ( positions[5][0] = BLACK_BISHOP );
positions[3][0] = BLACK_QUEEN;
positions[4][0] = BLACK_KING;
for ( int xindx=0; xindx < 8; xindx++ )
positions[xindx][1] = BLACK_PAWN;
positions[0][7] = ( positions[7][7] = WHITE_ROOK );
positions[1][7] = ( positions[6][7] = WHITE_KNIGHT );
positions[2][7] = ( positions[5][7] = WHITE_BISHOP );
positions[3][7] = WHITE_QUEEN;
positions[4][7] = WHITE_KING;
for ( xindx=0; xindx < 8; xindx++ )
positions[xindx][6] = WHITE_PAWN;
}//end of piece_position function
void place_pieces (int positions[8][8],int colormap[8][8])
{
int color, i, j;
enum Team {BLACK, WHITE}; //specifying constants
Team turn; //declaring a variable whose 0 value is equal to BLACK and 1 equal to WHITE
turn = BLACK;
for (int y=0; y<8; y++)
for (int x=0; x<8; x++)
{
if ( ((y+1)%2) == 0 )
{
if ( ((x+1)%2) == 0 )
colormap[x][y] = 15;
else
colormap[x][y] = 0;
}
else
{
if ( ((x+1)%2) == 0 )
colormap[x][y] = 0;
else
colormap[x][y] = 15;
}
}//end of 'x' for
for (int Y=0; Y < 8; Y++)
for (int X=0; X < 8; X++)
{
i = X; //will be sent to
j = Y; //coordinate manager
if ( positions[X][Y] >= 1 && positions[X][Y] <= 6 )
turn = WHITE;
color = colormap[X][Y];
coordinate_manager ( &i,&j ); //converting into screen coordinates
switch ( positions[X][Y] )
{
case 1:
case 7: rubber (i,j,color);
draw_pawn (i, j, turn, color);
break;
case 2:
case 8: rubber (i,j,color);
draw_rook (i, j, turn, color);
break;
case 3:
case 9: rubber (i,j,color);
draw_knight (i, j, turn, color);
break;
case 4:
case 10: rubber (i,j,color);
draw_bishop (i, j, turn, color);
break;
case 5:
case 11: rubber (i,j,color);
draw_queen (i, j, turn, color);
break;
case 6:
case 12: rubber (i,j,color);
draw_king (i, j, turn, color);
break;
}//end of draw_piece switch structure
}//end of loop with X
}//end of draw_pieces function
void coordinate_manager (int *x, int *y)
{
if (*x >= 0 && *x <= 7) //to differentiate if the coordinates are to be changed according to board or to the screen
{
*x = (*x * 50) + 21; //row-no = (row-no * horizontal lenght of a box) + distance from left side of screen
*y = (*y * 50) + 21; //converting board coordinates into screen coodinates
}
else
{
*x = (*x - 21) / 50; //converting screen coordinates into board coordinates
*y = (*y - 21) / 50;
}
}//end of coordinate_manager
void rubber(int x,int y, int color)
{
int tempcolor=0;
if ( color == 0 )
tempcolor = 15;
setfillstyle (SOLID_FILL,tempcolor);
bar (x+10,y+10,x+40,y+40); //rubbing the previous contents
}//end of rubber box
void draw_pawn (int x,int y,int turn,int color)
{
setcolor (color);
rectangle (x+10,y+10,x+40,y+40);
setfillstyle (CLOSE_DOT_FILL,WHITE);
floodfill (x+32,y+32,color);
if (turn == 0)
setfillstyle (SOLID_FILL,BLACK);
else
setfillstyle (SOLID_FILL,WHITE);
setcolor(LIGHTGRAY);
circle (x+25,y+25,7);
floodfill (x+25,y+25,LIGHTGRAY);
}//end of draw_pawn function
void draw_rook (int x,int y,int turn,int color)
{
setcolor (color);
rectangle (x+10,y+10,x+40,y+40);
setfillstyle (INTERLEAVE_FILL,WHITE);
floodfill (x+25,y+25,color);
if (turn == 0)
setfillstyle (SOLID_FILL,BLACK);
else
setfillstyle (SOLID_FILL,WHITE);
setcolor (LIGHTGRAY);
bar (x+16,y+14,x+23,y+22); //upper left
bar (x+27,y+14,x+34,y+22); //upper right
bar (x+27,y+28,x+34,y+36); //lower right
bar (x+16,y+28,x+23,y+36); //lower left
}//end of draw_rook function
void draw_knight (int x,int y,int turn,int color)
{
setcolor (color);
rectangle (x+10,y+10,x+40,y+40);
setfillstyle (XHATCH_FILL,WHITE);
floodfill (x+25,y+25,color);
if (turn == 0)
setfillstyle (SOLID_FILL,BLACK);
else
setfillstyle (SOLID_FILL,WHITE);
setcolor (LIGHTGRAY);
line (x+18,y+16,x+32,y+16); //top
line (x+18,y+16,x+18,y+27); //left
line (x+32,y+16,x+32,y+27); //right
arc (x+25,y+28,179,270,7);
arc (x+25,y+28,270,0,7);
floodfill(x+25,y+25,LIGHTGRAY);
if ( turn == 0 )
color = 15;
else
color = 0;
setcolor (color);
line (x+22,y+23,x+28,y+23);
line (x+25,y+19,x+25,y+31);
}//end of draw_knight function
void draw_bishop (int x,int y,int turn,int color)
{
setcolor (color);
rectangle (x+10,y+10,x+40,y+40);
setfillstyle (INTERLEAVE_FILL,WHITE);
floodfill (x+25,y+25,color);
if (turn == 0)
setcolor(BLACK);
else
setcolor(WHITE);
setlinestyle(SOLID_LINE,0,THICK_WIDTH);
line (x+16,y+22,x+34,y+22);
line (x+25,y+15,x+25,y+35);
setlinestyle(SOLID_LINE,1,NORM_WIDTH);
}//end of draw_bishop function
void draw_queen (int x,int y,int turn,int color)
{
setcolor (color);
rectangle (x+10,y+10,x+40,y+40);
setfillstyle (WIDE_DOT_FILL,WHITE);
floodfill (x+25,y+25,color);
setcolor (LIGHTGRAY);
line (x+15,y+29,x+18,y+19);
line (x+18,y+19,x+22,y+27);
line (x+22,y+27,x+24,y+19);
line (x+25,y+19,x+27,y+27);
line (x+27,y+27,x+30,y+19);
line (x+31,y+19,x+33,y+29);
arc (x+24,y+23,207,347,10);
if (turn == 0)
setfillstyle (SOLID_FILL,BLACK);
else
setfillstyle (SOLID_FILL,WHITE);
floodfill(x+25,y+24,LIGHTGRAY);
}//end of draw_queen function
void draw_king (int x,int y,int turn, int color)
{
setcolor (color);
rectangle (x+10,y+10,x+40,y+40);
setfillstyle(WIDE_DOT_FILL,WHITE);
floodfill(x+25,y+25,color);
setcolor (LIGHTGRAY);
line (x+18,y+31,x+20,y+18);
line (x+20,y+18,x+22,y+26);
line (x+22,y+26,x+24,y+18);
line (x+24,y+18,x+26,y+26);
line (x+26,y+26,x+28,y+18);
line (x+28,y+18,x+30,y+31);
arc (x+24,y+19,242,300,15);
if (turn == 0)
setfillstyle (SOLID_FILL,BLACK);
else
setfillstyle (SOLID_FILL,WHITE);
floodfill(x+24,y+21,LIGHTGRAY);
if ( turn == 0 )
color = 15;
else
color = 0;
setcolor(color);
line (x+24,y+31,x+24,y+25);
line (x+22,y+27,x+26,y+27);
}//end of draw_king function
void move_control (int positions[8][8],int move_info[],int x1,int y1,int x2, int y2)
{
int call=0, x, y;
int color = 2;
static int xx1=x1,yy1=y1,xx2=x2,yy2=y2; //to remove the image
setcolor(color);
setlinestyle (SOLID_LINE,1,THICK_WIDTH);
rectangle(x1,y1,x2,y2); //draws the box in its initial position as specified by the default values
do
{
char detect_zero,direction;
detect_zero = getch();
if ( detect_zero != 27 && detect_zero == 0) //avoiding the escape key
{
direction = getch();
switch ( direction )
{
case 77: move_right (x1,y1,x2,y2,color);
break;
case 80: move_down (x1,y1,x2,y2,color);
break;
case 75: move_left (x1,y1,x2,y2,color);
break;
case 72: move_up (x1,y1,x2,y2,color);
break;
default : messages ( 4 );
}//end of switch
}//end of 'avoiding escape key' if structure
color = 2;
setcolor(color); //changing color back to 2 because it is turn 0 after the switch structure
rectangle(x1,y1,x2,y2);
x = x1; //making copies
y = y1; //to send to coordinate manager
if ( detect_zero == 27 ) //exiting on escape key
exit(1);
if ( detect_zero == 13 ) //detecting enter key
{
coordinate_manager( &x,&y );
if ( call == 0 )
{
color = 4;
setcolor(color); //leavs an image
rectangle(x1,y1,x2,y2); //on the selected box
xx1=x1, xx2=x2, yy1=y1, yy2=y2; //updating values
if ( verify_move (x,y,turn,call,positions) == 0 )
{
color = 2;
messages ( 1 );
setcolor(color);
rectangle(x1,y1,x2,y2);
}
else
{
call = 1;
move_info[2] = x;
move_info[3] = y;
}
}
else
{
setcolor (0);
rectangle(xx1,yy1,xx2,yy2);
rectangle(x1,y1,x2,y2);
if ( verify_move (x,y,turn,call,positions) == 0 )
{
messages ( 2 );
call = 0;
}
else
{
move_info[0] = x;
move_info[1] = y;
setlinestyle(SOLID_LINE,1,NORM_WIDTH);
break;
}
}//end of else
}//end of if that detects enter key
}//end of while loop that controls the box movement
while (1);
}//end of move_control function
void move_right (int &x1,int y1,int &x2,int y2,int color) //accepting as refrence variables
{
if ( x2 <= 371 ) //preventing the box to go out of the board
{
if ( color == 2 )
decolorize_shadow (x1,y1,x2,y2); //preventing the image from decolorizing
x1 += 50;
x2 += 50;
}
}//end of move_left function
void move_down (int x1,int &y1,int x2,int &y2,int color)
{
if ( y2 <= 371 )
{
if ( color == 2 )
decolorize_shadow (x1,y1,x2,y2);
y1 += 50;
y2 += 50;
}
}//end of move_down function
void move_left (int &x1,int y1,int &x2,int y2,int color)
{
if ( x1 > 21 )
{
if ( color == 2 )
decolorize_shadow (x1,y1,x2,y2);
x1 -= 50;
x2 -= 50;
}
}//end of move_left function
void move_up (int x1,int &y1,int x2,int &y2,int color)
{
if ( y1 > 21)
{
if ( color == 2 )
decolorize_shadow (x1,y1,x2,y2);
y1 -= 50;
y2 -= 50;
}
color = 1;
}//end of move_up function
void decolorize_shadow (int x1,int y1,int x2,int y2)
{
setcolor (0);
rectangle (x1,y1,x2,y2);
}//end of decolorize_shadow
int verify_move (int x,int y,int turn,int call,int positions[8][8])
{
int pid=0;
static int knight_check; //used later to aviod calling jump_test function
static int oldx,oldy; //stores x,y from 1st call to this function
static int copy_array = 0;
static int pawn_positions[8][8] = {0};
if ( copy_array == 0 )
{
int pid = 1;
for (int j=0; j<8; j++)
for (int i=0; i<8; i++)
if ( positions[i][j] == 1 || positions[i][j] == 7 )
{
pawn_positions[i][j] = pid; //pawn ID
pid++;
}
copy_array = 1; //so that pawn_positions is not re-copied next time
}
if ( call == 0 )
{
oldx = x;
oldy = y; //storing old values for later use
if ( positions[x][y] == 0 )
return 0; //invalid box
else if ( turn == 0 )
if ( positions[x][y] >= 7 && positions[x][y] <= 12 )
{
if ( positions[x][y] == 9 )
knight_check = 1; //black knight found
else
knight_check = 0; //black knight not found
return 1; //valid piece
}
else
return 0; //invalid piece
else
if ( positions[x][y] >= 1 && positions[x][y] <= 6 )
{
if ( positions[x][y] == 3 )
knight_check = 1; //white knight found
else
knight_check = 0; //white knight not found
return 1;
}
else
return 0;
}//end of first call if structure
else
{
switch ( positions[oldx][oldy] )
{
case 1:
case 7: if ( move_pawn(oldy,y,oldx,x,turn,positions,pawn_positions,&pid) )
break;
else
return 0;
case 2:
case 8: if ( oldx!=x && oldy==y )
break;
else if ( oldy!=y && oldx==x )
break;
else
return 0;
case 3:
case 9: if ( abs(oldx-x)==2 && abs(oldy-y)==1 )
break;
else if ( abs(oldx-x)==1 && abs(oldy-y)==2 )
break;
else
return 0;
case 4:
case 10: if ( abs(oldx-x) == abs(oldy-y) )
break;
else
return 0;
case 5:
case 11: if ( oldx!=x && oldy==y )
break;
else if ( oldx==x && oldy!=y )
break;
else if ( abs(oldx-x) == abs(oldy-y) )
break;
else
return 0;
case 6:
case 12: if ( abs(oldx-x) == 1 )
break;
else if ( abs(oldy-y) == 1 )
break;
else
return 0;
}//end of switch
if ( positions[x][y] == 0 )
{
if ( knight_check != 1 )
{
if ( jump_test(oldx,oldy,x,y,positions) )
{
update_pawns(pawn_positions,oldx,oldy,x,y,pid);
return 1;
}
else
return 0;
}//end of knight check
else
return 1;
}//end of empty box found
if ( turn == 0 )
{
if ( positions[x][y] >= 1 && positions[x][y] <= 6 )
{
if ( knight_check != 1 )
{
if ( jump_test(oldx,oldy,x,y,positions) )
{
update_pawns(pawn_positions,oldx,oldy,x,y,pid);
return 1;
}
else
return 0;
}//end of knight check
return 1;
}//end of white piece found
}//end of black team's turn
else
{
if ( positions[x][y] >= 7 && positions[x][y] <= 12 )
{
if ( knight_check != 1 )
{
if ( jump_test(oldx,oldy,x,y,positions) )
{
update_pawns(pawn_positions,oldx,oldy,x,y,pid);
return 1;
}
else
return 0;
}//end of knight check
return 1;
}//end of black piece found
}//end of white team's turn
}//end of second call if structure
return 0;
}//end of verify_move function
int jump_test (int oldx,int oldy,int x,int y,int positions[8][8])
{
int jumps = 0;
int temp;
int piece_id = positions[oldx][oldy]; //because the following if structure may change the values of oldx and oldy (used in the switch)
do
{
if ( positions[oldx][oldy]==4 || positions[oldx][oldy]==10 || positions[oldx][oldy]==5 || positions[oldx][oldy]==11 ) //don't want to swap the values in case of left to right diagonal movements
{
if ( (oldx>x) && (oldy<y) )
break; //breaking out in case of left
else if ( (oldx<x) && (oldy>y) )
break; //to right diagonal movement
}
if ( positions[oldx][oldy]!=1 && positions[oldx][oldy]!=7 ) //excluding pawns because they work differently
{
if ( oldx < x ) //storing larger value in oldx & oldy to simplify the following switch structure
{
temp = oldx;
oldx = x;
x = temp;
}
if ( oldy < y )
{
temp = oldy;
oldy = y;
y = temp;
}
}
break;
}
while ( 1 ); //the loop is used only because break statement was required
switch ( piece_id )
{
case 1: while ( oldy>y && oldx==x)
{
if ( positions[x][oldy-1] != 0 )
jumps++;
oldy--;
}break;
case 7: while ( oldy<y && oldx==x)
{
if ( positions[x][oldy+1] != 0 )
jumps++;
oldy++;
}break;
case 2:
case 8: while ( oldx > x+1 )
{
if ( positions[oldx-1][y] != 0 )
jumps++;
oldx--;
}
while ( oldy > y+1 )
{
if ( positions[x][oldy-1] != 0 )
jumps++;
oldy--;
}break;
case 4:
case 10: while ( (oldx>x+1) && (oldy>y+1) )
{
if ( positions[oldx-1][oldy-1] != 0 )
{
jumps++;
break;
}
oldx--;
oldy--;
}//end of while
while ( (oldx<x-1) && (oldy>y+1) )
{
if ( positions[oldx+1][oldy-1] != 0 )
jumps++;
oldx++;
oldy--;
}//end of while
while ( (oldx>x+1) && (oldy<y-1) )
{
if ( positions[oldx-1][oldy+1] != 0 )
jumps++;
oldx--;
oldy++;
}//end of while
break;
case 5:
case 11: while ( (oldx>x+1) && (oldy==y) )
{
if ( positions[oldx-1][y] != 0 )
jumps++;
oldx--;
}
while ( (oldy>y+1) && (oldx==x) )
{
if ( positions[x][oldy-1] != 0 )
jumps++;
oldy--;
}
while ( (oldx>x+1) && (oldy>y+1) )
{
if ( positions[oldx-1][oldy-1] != 0 )
jumps++;
oldx--;
oldy--;
}
while ( (oldx<x-1) && (oldy>y+1) )
{
if ( positions[oldx+1][oldy-1] != 0 )
jumps++;
oldx++;
oldy--;
}//end of while
while ( (oldx>x+1) && (oldy<y-1) )
{
if ( positions[oldx-1][oldy+1] != 0 )
jumps++;
oldx--;
oldy++;
}//end of while
break;
}//end of switch
if ( jumps == 0 )
return 1;
return 0;
}//end of jump_test function
int move_pawn (int oldy,int y,int oldx,int x,int turn,int positions[8][8],int pawn_positions[8][8],int *pid)
{
static int firstmove[16] = {0};
*pid = pawn_positions[oldx][oldy];
if ( turn == 0 )
{
if ( ((y-oldy)==1 || (y-oldy)==2) && oldx==x )
{
if ( (firstmove[*pid-1]==0) || (firstmove[*pid-1]!=0 && (y-oldy)==1) )
if ( jump_test(oldx,oldy,x,y,positions) )
{
firstmove[*pid-1] = 1;
return 1;
}
else if ( (y-oldy) == 1 )
return 1;
}
else if ( (y-oldy)==1 && abs(oldx-x)==1 )
{
if ( positions[x][y]>=1&&positions[x][y]<=6&&positions[x][y]!=0 )
{
firstmove[*pid-1] = 1;
return 1;
}
}
else
return 0;
}//black end
else
{
if ( ((oldy-y)==1 || (oldy-y)==2) && oldx==x )
{
if ( (firstmove[*pid-1]==0) || (firstmove[*pid-1]!=0 && (oldy-y)==1) )
if ( jump_test(oldx,oldy,x,y,positions) )
{
firstmove[*pid-1] = 1;
return 1;
}
else if ( (oldy-y) == 1 )
return 1;
}
else if ( (oldy-y)==1 && abs(oldx-x)==1 )
{
if ( positions[x][y]>=7&&positions[x][y]<=12 )
{
firstmove[*pid-1] = 1;
return 1;
}
}
else
return 0;
}//white end
return 0;
}//end of move_pawn function
void update_pawns (int pawn_positions[8][8],int oldx,int oldy,int x,int y,int pid)
{
for (int j=0; j<8; j++)
for (int i=0; i<8; i++)
if ( pawn_positions[i][j] == pid )
{
pawn_positions[x][y] = pid;
pawn_positions[oldx][oldy] = 0;
break;
}
}//end of update_pawns function
void move_piece (int x,int y,int oldx,int oldy,int positions[8][8],int colormap[8][8])
{
positions[x][y] = positions[oldx][oldy]; //moving a piece internally
int i = oldx;
int j = oldy;
int color;
for (int count=0; count<2; count++) //moving graphically
{
color = colormap[i][j];
/* if ( count == 0 ) //to rub a piece from its
{ //old position
if ( colormap[i][j] == 1 )
color = 15;
else
color = 1;
}*/
switch ( positions[i][j] )
{
case 1:
case 7: coordinate_manager( &i,&j );
rubber (i,j,color);
if ( count )
draw_pawn(i,j,turn,color);
break;
case 2:
case 8: coordinate_manager( &i,&j );
rubber (i,j,color);
if ( count )
draw_rook(i,j,turn,color);
break;
case 3:
case 9: coordinate_manager( &i,&j );
rubber (i,j,color);
if ( count )
draw_knight(i,j,turn,color);
break;
case 4:
case 10: coordinate_manager( &i,&j );
rubber (i,j,color);
if ( count )
draw_bishop(i,j,turn,color);
break;
case 5:
case 11: coordinate_manager( &i,&j );
rubber (i,j,color);
if ( count )
draw_queen(i,j,turn,color);
break;
case 6:
case 12: coordinate_manager( &i,&j );
rubber (i,j,color);
if ( count )
draw_king(i,j,turn,color);
break;
}//end of switch
i = x;
j = y;
positions[oldx][oldy] = 0; //rubbing a piece internally
}//end of if
}//end of move-piece function
void king_status (int positions[8][8])
{
int king=0;
if ( turn == 0 )
{
for (int y=0; y<8; y++)
{
for (int x=0; x<8; x++)
if ( positions[x][y] == 6 )
{
king = 1;
break;
}
if ( x != 8 )//checking if upper break was executed
break;
}
if ( king == 0 )
{
messages ( 3 );
getch();
exit(1);
}
}//black end
else
{
for (int y=0; y<8; y++)
{
for (int x=0; x<8; x++)
if ( positions[x][y] == 12 )
{
king = 1;
break;
}
if ( x != 8 )
break;
}
if ( king == 0 )
{
messages ( 4 );
getch();
exit(1);
}
}//white end
}//end of king_status function
void messages ( int msgid )
{
gotoxy (61,5);
switch ( msgid )
{
case 0: gotoxy(63,3);
if ( turn == 0 )
cout<<"BLACK'S TURN";
else
cout<<"WHITE'S TURN";
break;
case 1: cout<<"COULDN'T SELECT";
break;
case 2: cout<<" ILLEGAL MOVE";
break;
case 3: cout<<" WHITE LOST";
break;
case 4: cout<<" BLACK LOST";
break;
case 5: cout<<" CAN'T DO";
break;
}//end of switch
if ( msgid != 0 )
{
delay (1000);
gotoxy (61,5);
textcolor (0);
cout<<" ";
}
}//end of msgind function
/*Project Name:-Chess Mania */
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include<dos.h>
struct game{
int cp[8][8][2];
int kingp[3][3];
int onep[8][8],turn;
int twop[8][8];
int checked,checkmate;
};
game n;
int p[4],goon=1,c=1;
int po[8][2];
void ffp(int x,int y)
{
floodfill(25+x,30+y,15);
floodfill(25+x,37+y,15);
floodfill(25+x,44+y,15); }
void ffk(int x,int y)
{
floodfill(25+x,40+y,15);
floodfill(25+x,3+y,15); }
void ffc(int x,int y)
{ floodfill(25+x,25+y,15); }
void ffcam(int x,int y)
{
floodfill(25+x,13+y,15);
floodfill(25+x,20+y,15);
floodfill(23+x,28+y,15);
floodfill(25+x,40+y,15);
floodfill(25+x,47+y,15); }
void ffq(int x,int y)
{
floodfill(25+x,7+y,15);
floodfill(25+x,12+y,15);
floodfill(25+x,22+y,15);
floodfill(25+x,24+y,15);
floodfill(25+x,30+y,15); }
void ffh(int x,int y)
{ floodfill(25+x,45+y,15);
}
void drawpawn(int x,int y)
{
circle(25+x,30+y,5);
line(15+x,35+y,35+x,35+y);
line(15+x,35+y,15+x,38+y);
line(35+x,35+y,35+x,38+y);
line(15+x,38+y,35+x,38+y);
arc(25+x,50+y,0,180,12);
line(13+x,50+y,37+x,50+y); }
void drawking(int x,int y)
{
line(25+x,0+y,22+x,2+y);
line(25+x,0+y,28+x,2+y);
line(22+x,2+y,25+x,5+y);
line(28+x,2+y,25+x,5+y);
line(25+x,5+y,15+x,9+y);
line(25+x,5+y,35+x,9+y);
line(15+x,9+y,21+x,15+y);
line(35+x,9+y,29+x,15+y);
line(21+x,15+y,15+x,18+y);
line(29+x,15+y,35+x,18+y);
line(15+x,18+y,15+x,20+y);
line(35+x,18+y,35+x,20+y);
line(15+x,20+y,20+x,20+y);
line(35+x,20+y,30+x,20+y);
line(20+x,20+y,18+x,40+y);
line(30+x,20+y,32+x,40+y);
line(18+x,40+y,10+x,45+y);
line(32+x,40+y,40+x,45+y);
line(10+x,45+y,13+x,48+y);
line(40+x,45+y,37+x,48+y);
line(13+x,48+y,10+x,50+y);
line(37+x,48+y,40+x,50+y);
line(10+x,50+y,40+x,50+y); }
void drawcastle(int x,int y)
{
line(15+x,50+y,35+x,50+y);
line(15+x,50+y,15+x,47+y);
line(35+x,50+y,35+x,47+y);
line(15+x,47+y,18+x,47+y);
line(35+x,47+y,32+x,47+y);
line(18+x,47+y,20+x,27+y);
line(32+x,47+y,30+x,27+y);
line(20+x,27+y,15+x,27+y);
line(30+x,27+y,35+x,27+y);
line(15+x,27+y,15+x,20+y);
line(35+x,27+y,35+x,20+y);
line(15+x,20+y,20+x,20+y);
line(35+x,20+y,30+x,20+y);
line(20+x,20+y,20+x,25+y);
line(30+x,20+y,30+x,25+y);
line(20+x,25+y,23+x,25+y);
line(30+x,25+y,27+x,25+y);
line(23+x,25+y,23+x,20+y);
line(27+x,25+y,27+x,20+y);
line(23+x,20+y,27+x,20+y); }
void drawhorse(int x,int y)
{
line(13+x,50+y,37+x,50+y);
line(13+x,50+y,22+x,34+y);
line(37+x,50+y,32+x,26+y);
line(22+x,35+y,8+x,31+y);
line(32+x,26+y,36+x,23+y);
line(36+x,23+y,31+x,20+y);
line(31+x,20+y,28+x,15+y);
line(28+x,15+y,25+x,20+y);
line(25+x,20+y,22+x,15+y);
line(22+x,15+y,19+x,20+y);
line(19+x,20+y,8+x,27+y);
line(8+x,27+y,15+x,29+y);
line(15+x,29+y,8+x,31+y);
circle(25+x,25+y,1); }
void drawcamel(int x,int y)
{
circle(25+x,13+y,2);
line(24+x,14+y,18+x,20+y);
line(26+x,14+y,32+x,20+y);
line(18+x,20+y,22+x,27+y);
line(32+x,20+y,28+x,27+y);
line(22+x,27+y,28+x,27+y);
line(22+x,27+y,22+x,30+y);
line(28+x,27+y,28+x,30+y);
line(22+x,30+y,28+x,30+y);
line(22+x,30+y,15+x,45+y);
line(28+x,30+y,35+x,45+y);
line(15+x,45+y,35+x,45+y);
line(15+x,45+y,15+x,50+y);
line(35+x,45+y,35+x,50+y);
line(15+x,50+y,35+x,50+y); }
void drawqueen(int x,int y)
{
line(10+x,50+y,40+x,50+y);
line(10+x,50+y,10+x,45+y);
line(40+x,50+y,40+x,45+y);
line(10+x,45+y,15+x,45+y);
line(40+x,45+y,35+x,45+y);
line(15+x,45+y,20+x,40+y);
line(35+x,45+y,30+x,40+y);
line(20+x,40+y,20+x,25+y);
line(30+x,40+y,30+x,25+y);
line(15+x,25+y,35+x,25+y);
line(15+x,25+y,15+x,23+y);
line(35+x,25+y,35+x,23+y);
line(15+x,23+y,35+x,23+y);
line(15+x,23+y,20+x,20+y);
line(35+x,23+y,30+x,20+y);
line(20+x,20+y,30+x,20+y);
line(20+x,20+y,20+x,15+y);
line(30+x,20+y,30+x,15+y);
line(20+x,15+y,15+x,13+y);
line(30+x,15+y,35+x,13+y);
line(15+x,13+y,15+x,10+y);
line(35+x,13+y,35+x,10+y);
line(15+x,10+y,20+x,13+y);
line(35+x,10+y,30+x,13+y);
line(20+x,13+y,24+x,8+y);
line(30+x,13+y,26+x,8+y);
circle(25+x,7+y,2); }
void drawcoin(int x,int y,int i,int j,int f)
{
if(n.cp[i][j][1]==1)
{ drawpawn(x,y);
if(f)
ffp(x,y); }
if(n.cp[i][j][1]==2)
{ drawcastle(x,y);
if(f)
ffc(x,y);
}
if(n.cp[i][j][1]==3)
{ drawhorse(x,y);
if(f)
ffh(x,y); }
if(n.cp[i][j][1]==4)
{ drawcamel(x,y);
if(f)
ffcam(x,y);}
if(n.cp[i][j][1]==5)
{ drawqueen(x,y);
if(f)
ffq(x,y); }
if(n.cp[i][j][1]==6)
{ drawking(x,y);
if(f)
ffk(x,y); }
}
void setcoins()
{
int i,j,c,x,y;
for(i=0;i<8;i++)
for(j=0;j<8;j++)
{ x=169+j*50;
y=39+i*50;
if(n.cp[i][j][0]==15&&(i+j)%2==0)//white coin and white background
{ setcolor(0);
floodfill(x+25,y+25,15);
drawcoin(x,y,i,j,0);
}
if(n.cp[i][j][0]==15&&(i+j)%2!=0) //white coin and black background
{ setcolor(15);
drawcoin(x,y,i,j,1);
}
if(n.cp[i][j][0]==0&&(i+j)%2!=0) // black coin and black background
{ setcolor(15);
drawcoin(x,y,i,j,0);
}
if(n.cp[i][j][0]==0&&(i+j)%2==0) // black coin and white background
{ setcolor(15);
drawcoin(x,y,i,j,0);
floodfill(x+5,y+5,15);
floodfill(x+45,y+5,15);
}
if(n.cp[i][j][0]==-1&&(i+j)%2==0)
{ setcolor(15);
floodfill(x+25,y+25,15);
}
}
}
void drawboard()
{ int i,j;
int xmin=169,xmax=569,ymin=39,ymax=439;
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "\\tc\\bgi\\");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
for(i=ymin;i<=ymax;i+=50)
line(xmin,i,xmax,i);
for(i=xmin;i<=xmax;i+=50)
line(i,ymin,i,ymax);
outtextxy(589,64,"eight");
outtextxy(589,114,"seven");
outtextxy(589,164,"six");
outtextxy(589,214,"five");
outtextxy(589,264,"four");
outtextxy(589,314,"three");
outtextxy(589,364,"two");
outtextxy(589,414,"one");
outtextxy(544,449,"H");
outtextxy(494,449,"G");
outtextxy(444,449,"F");
outtextxy(394,449,"E");
outtextxy(344,449,"D");
outtextxy(294,449,"C");
outtextxy(244,449,"B");
outtextxy(194,449,"A");
setcoins();
if(n.turn==1)
c=8;
else
c=1;
setfillstyle(CLOSE_DOT_FILL,c);
floodfill(50,50,15);
}
void givevalue()
{
int i,j;
for(i=0;i<8;i++) //making all null
for(j=0;j<8;j++)
n.cp[j][i][0]=-1;
for(i=0;i<8;i++) //giving color to coins
for(j=0;j<2;j++)
n.cp[j][i][0]=0;
for(i=0;i<8;i++)
for(j=6;j<8;j++)
n.cp[j][i][0]=15;
for(i=0;i<8;i++) // placing the coins on the board
for(j=0;j<8;j++) //starting positons
{ n.cp[j][i][1]=-1;
if(j==1||j==6)
n.cp[j][i][1]=1;
if((j==0||j==7)&&(i==0||i==7))
n.cp[j][i][1]=2;
if((j==0||j==7)&&(i==1||i==6))
n.cp[j][i][1]=3;
if((j==0||j==7)&&(i==2||i==5))
n.cp[j][i][1]=4;
if((j==0||j==7)&&i==3)
n.cp[j][i][1]=5;
if((j==0||j==7)&&i==4)
n.cp[j][i][1]=6;
}
}
void open()
{
FILE *fp;
fp=fopen("save.txt","r");
printf("\n\n\t\t\t");
if(fp==NULL)
cprintf("Cannot open file");
else
{ fread(&n,sizeof(n),1,fp);
drawboard();
}
}
void leaf(int f)
{
int gdriver = DETECT, gmode, errorcode,i;
initgraph(&gdriver, &gmode, "\\tc\\bgi\\");
arc(370,540,120,160,330);
arc(260,540,20,60,330);
//first leaf
line(80,385,90,315);
line(90,315,95,330);
line(95,330,120,275);
line(120,275,120,293);
line(120,293,155,250);
line(155,250,150,270);
line(150,270,187,233);
line(187,233,183,250);
line(183,250,251,226);
line(251,226,196,277);
line(196,277,208,280);
line(208,280,164,301);
line(164,301,177,305);
line(177,305,135,330);
line(135,330,148,331);
line(148,331,113,356);
line(113,356,126,356);
line(126,356,80,383);
//right leaf
line(550,380,500,360);
line(500,360,515,357);
line(515,357,470,333);
line(470,333,483,332);
line(483,332,440,304);
line(440,304,454,304);
line(454,304,414,277);
line(414,277,432,279);
line(432,279,372,225);
line(372,225,445,245);
line(445,245,438,230);
line(438,230,478,266);
line(478,266,473,250);
line(473,250,511,298);
line(511,298,508,283);
line(508,283,535,331);
line(535,331,535,315);
line(535,315,550,380);
setfillstyle(3,2);
floodfill(440,250,15);
floodfill(90,350,15);
//king
int x=79,y=50,x1=3,y1=4;
line((25+x)*x1,(0+y)*y1,(25+x)*x1,(50+y)*y1);
line((25+x)*x1,(0+y)*y1,(22+x)*x1,(2+y)*y1);
line((25+x)*x1,(0+y)*y1,(28+x)*x1,(2+y)*y1);
line((22+x)*x1,(2+y)*y1,(25+x)*x1,(5+y)*y1);
line((28+x)*x1,(2+y)*y1,(25+x)*x1,(5+y)*y1);
line((25+x)*x1,(5+y)*y1,(15+x)*x1,(9+y)*y1);
line((25+x)*x1,(5+y)*y1,(35+x)*x1,(9+y)*y1);
line((15+x)*x1,(9+y)*y1,(21+x)*x1,(15+y)*y1);
line((35+x)*x1,(9+y)*y1,(29+x)*x1,(15+y)*y1);
line((21+x)*x1,(15+y)*y1,(15+x)*x1,(18+y)*y1);
line((29+x)*x1,(15+y)*y1,(35+x)*x1,(18+y)*y1);
line((15+x)*x1,(18+y)*y1,(15+x)*x1,(20+y)*y1);
line((35+x)*x1,(18+y)*y1,(35+x)*x1,(20+y)*y1);
line((15+x)*x1,(20+y)*y1,(20+x)*x1,(20+y)*y1);
line((35+x)*x1,(20+y)*y1,(30+x)*x1,(20+y)*y1);
line((20+x)*x1,(20+y)*y1,(18+x)*x1,(40+y)*y1);
line((30+x)*x1,(20+y)*y1,(32+x)*x1,(40+y)*y1);
line((18+x)*x1,(40+y)*y1,(10+x)*x1,(45+y)*y1);
line((32+x)*x1,(40+y)*y1,(40+x)*x1,(45+y)*y1);
line((10+x)*x1,(45+y)*y1,(13+x)*x1,(48+y)*y1);
line((40+x)*x1,(45+y)*y1,(37+x)*x1,(48+y)*y1);
line((13+x)*x1,(48+y)*y1,(10+x)*x1,(50+y)*y1);
line((37+x)*x1,(48+y)*y1,(40+x)*x1,(50+y)*y1);
line((10+x)*x1,(50+y)*y1,(40+x)*x1,(50+y)*y1);
setfillstyle(1,15);
floodfill((21+x)*x1,(40+y)*y1,15);
floodfill((23+x)*x1,(3+y)*y1,15);
setfillstyle(CLOSE_DOT_FILL,8);
floodfill(50,50,15);
printf("\n====================================Creators====================================");
printf("\n DERRICK====================SHRUTI ");
if(f)
{
printf("\n THANK YOU FOR PLAYING CHESS MANIA ");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\n================================================================================");
}
else{
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\n================================================================================");
} delay(3500);
closegraph();
}
void openmenu()
{
clrscr();
textcolor(CYAN + BLINK);
printf("\n\n\n\n\n \t\t\t");
cprintf("Welcome_to_Chess_Mania");
textcolor(CYAN );
printf("\n\n\t\t\t");
cprintf(" Hit Enter to play");
printf("\n\n\t\t\t");
cprintf(" Hit Esc to exit");
int a;
if(getch()==27)
{exit(0);
}
else
{ clrscr();
printf("\n\n");
printf("\n\n\t\t\t");
cprintf("Start new game hit enter");
printf("\n\n\t\t\t");
cprintf(" Load saved game hit L");
printf("\n\n\t\t\t");
cprintf(" Hit Esc to exit");
a=getch();
if(a==27)
{exit(0);
}
else if(a=='l'||a=='L')
{
open();
}
else
{ clrscr();
printf("\n\n\t\t\t");
givevalue();
drawboard();
}}}
void save()
{ FILE *fp;
fp=fopen("save.txt","w");
fwrite(&n,sizeof(n),1,fp);
exit(0);
}
void menu()
{
closegraph();
printf("\n\n\t\t\t");
cprintf("Save game and exit::s");
printf("\n\n\t\t\t");
cprintf(" Exit::E");
printf("\n\n\t\t\t");
cprintf("return to game:any key");
char s=getch();
if(s=='s'||s=='S')
{ leaf(1); save(); }
else if(s=='e'||s=='E')
{
leaf(1);
exit(0);
}
else
{drawboard();
}
}
void calppp(int e)
{ int i,j;
if(e)
for(i=0;i<8;i++)
for(j=0;j<8;j++)
n.onep[i][j]=-1;
if(n.turn) //white pawn
{ //reset
if(p[0]==6)
{ if(n.cp[5][p[1]][0]!=15&&n.cp[5][p[1]][0]!=0)
n.onep[5][p[1]]=1;
if(n.cp[4][p[1]][0]!=15&&n.cp[4][p[1]][0]!=0&&n.cp[5][p[1]][0]==-1)
n.onep[4][p[1]]=1;
}
if(p[0]-1>=0)
{ i=p[0]-1;
j=p[1];
if(n.cp[i][j][0]!=15&&n.cp[i][j][0]!=0)
n.onep[i][j]=1;
if(p[1]+1<8)
if(n.cp[p[0]-1][p[1]+1][0]==0)
n.onep[p[0]-1][p[1]+1]=1;
if(p[1]-1>=0)
if(n.cp[p[0]-1][p[1]-1][0]==0)
n.onep[p[0]-1][p[1]-1]=1;
}
} //turn end
else
{ //for black pawn checkin possibility
if(p[0]==1)
{ if(n.cp[2][p[1]][0]!=15&&n.cp[2][p[1]][0]!=0)
n.onep[2][p[1]]=1;
if(n.cp[3][p[1]][0]!=15&&n.cp[3][p[1]][0]!=0&&n.cp[2][p[1]][0]==-1)
n.onep[3][p[1]]=1;
}
if(p[0]+1<8)
{ i=p[0]+1;
j=p[1];
if(n.cp[i][j][0]!=15&&n.cp[i][j][0]!=0)
n.onep[i][j]=1;
if(p[1]+1<8)
if(n.cp[p[0]+1][p[1]+1][0]==15)
n.onep[p[0]+1][p[1]+1]=1;
if(p[1]-1>=0)
if(n.cp[p[0]+1][p[1]-1][0]==15)
n.onep[p[0]+1][p[1]-1]=1;
}
}
}
void calppc(int e)
{ int i,j,flag=1;
if(e)
for(i=0;i<8;i++) //reset
for(j=0;j<8;j++)
n.onep[i][j]=-1;
if(n.turn) {
for(i=p[1]+1;i<8&&n.cp[p[0]][i][0]!=15&&flag;i++) //marking the right side
{ if(n.cp[p[0]][i][0]==0)
flag=0;
n.onep[p[0]][i]=1;
} flag=1;
for(i=p[1]-1;i>=0&&n.cp[p[0]][i][0]!=15&&flag;i--) //marking the left side
{ if(n.cp[p[0]][i][0]==0)
flag=0;
n.onep[p[0]][i]=1;
} flag=1;
for(i=p[0]+1;i<8&&n.cp[i][p[1]][0]!=15&&flag;i++) //marking the down side
{ if(n.cp[p[0]][i][0]==0)
flag=0;
n.onep[i][p[1]]=1;
} flag=1;
for(i=p[0]-1;i>=0&&n.cp[i][p[1]][0]!=15&&flag;i--) //marking the top side
{ if(n.cp[p[0]][i][0]==0)
flag=0;
n.onep[i][p[1]]=1;
}
}
else
{ flag=1;
for(i=p[1]+1;i<8&&n.cp[p[0]][i][0]!=0&&flag;i++) //marking the right side
{ if(n.cp[p[0]][i][0]==15)
flag=0;
n.onep[p[0]][i]=1;
} flag=1;
for(i=p[1]-1;i>=0&&n.cp[p[0]][i][0]!=0&&flag;i--) //marking the left side
{ if(n.cp[p[0]][i][0]==15)
flag=0;
n.onep[p[0]][i]=1;
} flag=1;
for(i=p[0]+1;i<8&&n.cp[i][p[1]][0]!=0&&flag;i++) //marking the down side
{ if(n.cp[p[0]][i][0]==15)
flag=0;
n.onep[i][p[1]]=1;
} flag=1;
for(i=p[0]-1;i>=0&&n.cp[i][p[1]][0]!=0&&flag;i--) //marking the top side
{ if(n.cp[p[0]][i][0]==15)
flag=0;
n.onep[i][p[1]]=1;
}}}
void calpph(int a)
{
int i,j;
if(a)
for(i=0;i<8;i++) //reset
for(j=0;j<8;j++)
n.onep[i][j]=-1;
if(n.turn)
{ if(p[1]+1<8)
{ if(p[0]-2>=0)
if(n.cp[p[0]-2][p[1]+1][0]!=15)
n.onep[p[0]-2][p[1]+1]=1;
if(p[0]+2<8)
if(n.cp[p[0]+2][p[1]+1][0]!=15)
n.onep[p[0]+2][p[1]+1]=1;
}
if(p[1]+2<8)
{ if(p[0]-1>=0)
if(n.cp[p[0]-1][p[1]+2][0]!=15)
n.onep[p[0]-1][p[1]+2]=1;
if(p[0]+1<8)
if(n.cp[p[0]+1][p[1]+2][0]!=15)
n.onep[p[0]+1][p[1]+2]=1;
}
if(p[1]-1>=0)
{ if(p[0]-2>=0)
if(n.cp[p[0]-2][p[1]-1][0]!=15)
n.onep[p[0]-2][p[1]-1]=1;
if(p[0]+2<8)
if(n.cp[p[0]+2][p[1]-1][0]!=15)
n.onep[p[0]+2][p[1]-1]=1;
}
if(p[1]-2>=0)
{ if(p[0]-1>=0)
if(n.cp[p[0]-1][p[1]-2][0]!=15)
n.onep[p[0]-1][p[1]-2]=1;
if(p[0]+1<8)
if(n.cp[p[0]+1][p[1]-2][0]!=15)
n.onep[p[0]+1][p[1]-2]=1;
}
}
else
{
if(p[1]+1<8)
{ if(p[0]-2>=0)
if(n.cp[p[0]-2][p[1]+1][0]!=0)
n.onep[p[0]-2][p[1]+1]=1;
if(p[0]+2<8)
if(n.cp[p[0]+2][p[1]+1][0]!=0)
n.onep[p[0]+2][p[1]+1]=1;
}
if(p[1]+2<8)
{ if(p[0]-1>=0)
if(n.cp[p[0]-1][p[1]+2][0]!=0)
n.onep[p[0]-1][p[1]+2]=1;
if(p[0]+1<8)
if(n.cp[p[0]+1][p[1]+2][0]!=0)
n.onep[p[0]+1][p[1]+2]=1;
}
if(p[1]-1>=0)
{ if(p[0]-2>=0)
if(n.cp[p[0]-2][p[1]-1][0]!=0)
n.onep[p[0]-2][p[1]-1]=1;
if(p[0]+2<8)
if(n.cp[p[0]+2][p[1]-1][0]!=0)
n.onep[p[0]+2][p[1]-1]=1;
}
if(p[1]-2>=0)
{ if(p[0]-1>=0)
if(n.cp[p[0]-1][p[1]-2][0]!=0)
n.onep[p[0]-1][p[1]-2]=1;
if(p[0]+1<8)
if(n.cp[p[0]+1][p[1]-2][0]!=0)
n.onep[p[0]+1][p[1]-2]=1;
}
}}
void calppca(int e)
{
int i,j,flag=1;
if(e)
for(i=0;i<8;i++) //reset
for(j=0;j<8;j++)
n.onep[i][j]=-1;
if(n.turn)
{ //checkin left top
for(i=p[0]-1,j=p[1]-1;i>=0&&j>=0&&flag&&n.cp[i][j][0]!=15;i--,j--)
{ if(n.cp[i][j][0]==0)
flag=0;
n.onep[i][j]=1;
} flag=1;
//right top
for(i=p[0]-1,j=p[1]+1;i>=0&&j<8&&flag&&n.cp[i][j][0]!=15;i--,j++)
{ if(n.cp[i][j][0]==0)
flag=0;
n.onep[i][j]=1;
} flag=1;
// right bottom
for(i=p[0]+1,j=p[1]+1;i<8&&j<8&&flag&&n.cp[i][j][0]!=15;i++,j++)
{ if(n.cp[i][j][0]==0)
flag=0;
n.onep[i][j]=1;
} flag=1;
// left bottom
for(i=p[0]+1,j=p[1]-1;i<8&&j>=0&&flag&&n.cp[i][j][0]!=15;i++,j--)
{ if(n.cp[i][j][0]==0)
flag=0;
n.onep[i][j]=1;
}
//End of white
}
else // begin of black
{
for(i=p[0]-1,j=p[1]-1;i>=0&&j>=0&&flag&&n.cp[i][j][0]!=0;i--,j--)
{ if(n.cp[i][j][0]==15)
flag=0;
n.onep[i][j]=1;
} flag=1;
for(i=p[0]-1,j=p[1]+1;i>=0&&j<8&&flag&&n.cp[i][j][0]!=0;i--,j++)
{ if(n.cp[i][j][0]==15)
flag=0;
n.onep[i][j]=1;
} flag=1;
for(i=p[0]+1,j=p[1]+1;i<8&&j<8&&flag&&n.cp[i][j][0]!=0;i++,j++)
{ if(n.cp[i][j][0]==15)
flag=0;
n.onep[i][j]=1;
} flag=1;
for(i=p[0]+1,j=p[1]-1;i<8&&j>=0&&flag&&n.cp[i][j][0]!=0;i++,j--)
{ if(n.cp[i][j][0]==15)
flag=0;
n.onep[i][j]=1;
}
}}
void calppq(int e)
{
int i,j;
if(e)
for(i=0;i<8;i++) //reset possibility array
for(j=0;j<8;j++)
n.onep[i][j]=-1;
calppc(0);
calppca(0);
}
void calppk()
{
int i,j;
for(i=0;i<8;i++) //reset possibility array
for(j=0;j<8;j++)
n.onep[i][j]=-1;
if(n.turn)
{
if(p[1]+1<8)
{ if(p[0]-1>=0)
if(n.cp[p[0]-1][p[1]+1][0]!=15)
n.onep[p[0]-1][p[1]+1]=1;
if(p[0]+1<8)
if(n.cp[p[0]+1][p[1]+1][0]!=15)
n.onep[p[0]+1][p[1]+1]=1;
if(n.cp[p[0]][p[1]+1][0]!=15)
n.onep[p[0]][p[1]+1]=1;
}
if(p[1]-1>=0)
{ if(p[0]-1>=0)
if(n.cp[p[0]-1][p[1]-1][0]!=15)
n.onep[p[0]-1][p[1]-1]=1;
if(p[0]+1<8)
if(n.cp[p[0]+1][p[1]-1][0]!=15)
n.onep[p[0]+1][p[1]-1]=1;
if(n.cp[p[0]][p[1]-1][0]!=15)
n.onep[p[0]][p[1]-1]=1;
}
if(p[0]+1<8)
if(n.cp[p[0]+1][p[1]][0]!=15)
n.onep[p[0]+1][p[1]]=1;
if(p[0]-1>=0)
if(n.cp[p[0]-1][p[1]][0]!=15)
n.onep[p[0]-1][p[1]]=1;
}
else
{ if(p[1]+1<8)
{ if(p[0]-1>=0)
if(n.cp[p[0]-1][p[1]+1][0]!=0)
n.onep[p[0]-1][p[1]+1]=1;
if(p[0]+1<8)
if(n.cp[p[0]+1][p[1]+1][0]!=0)
n.onep[p[0]+1][p[1]+1]=1;
if(n.cp[p[0]][p[1]+1][0]!=0)
n.onep[p[0]][p[1]+1]=1;
}
if(p[1]-1>=0)
{ if(p[0]-1>=0)
if(n.cp[p[0]-1][p[1]-1][0]!=0)
n.onep[p[0]-1][p[1]-1]=1;
if(p[0]+1<8)
if(n.cp[p[0]+1][p[1]-1][0]!=0)
n.onep[p[0]+1][p[1]-1]=1;
if(n.cp[p[0]][p[1]-1][0]!=0)
n.onep[p[0]][p[1]-1]=1;
}
if(p[0]+1<8)
if(n.cp[p[0]+1][p[1]][0]!=0)
n.onep[p[0]+1][p[1]]=1;
if(p[0]-1>=0)
if(n.cp[p[0]-1][p[1]][0]!=0)
n.onep[p[0]-1][p[1]]=1;
}
}
int promote()
{ int value=1;
r:
printf("\n Promote Pawn to:\nQueen==5\nBishop==4\nKnight==3\nCastle==2");
printf("\nEnter a no:");
scanf("%d",&value);
if(value>1&&value<6)
return(value);
else
goto r;
}
int kingind(int h,int v)
{ int ret=0,count=0;
int i,j,king,found=1,x,y,nc;
//find the king
if(n.turn)
{ king=15; nc=0;}
else
{ king=0; nc=15;}
for(i=0;i<8&&found;i++)
for(j=0;j<8&&found;j++)
if(n.cp[i][j][0]==king&&n.cp[i][j][1]==6)
found=0;
x=p[0]; y=p[1];
p[0]=i-1; p[1]=j-1;
calppq(1);
for(i=0;i<8;i++)
for(j=0;j<8;j++)
if(n.onep[i][j]==1&&n.cp[i][j][0]==nc&&n.cp[i][j][1]!=1&&n.cp[i][j][1]!=3&&n.cp[i][j][1]!=6)
{ ret=1; count++;}
else
n.onep[i][j]=-1;
if(h)
calpph(0);
if(h)
{ for(i=0;i<8;i++)
for(j=0;j<8;j++)
if(n.onep[i][j]==1&&n.cp[i][j][0]==nc&&n.cp[i][j][1]==3)
{ ret=1; count++;}
if(n.turn)
{ if((n.cp[p[0]-1][p[1]+1][0]==nc&&n.cp[p[0]-1][p[1]+1][1]==1)||(n.cp[p[0]-1][p[1]-1][1]==1&&n.cp[p[0]-1][p[1]-1][1]==nc))
{ ret=1; count++; } }
else
{ if((n.cp[p[0]+1][p[1]+1][1]==1&&n.cp[p[0]+1][p[1]+1][0]==nc)||(n.cp[p[0]+1][p[1]-1][1]==1&&n.cp[p[0]+1][p[1]-1][1]==nc))
{ ret=1; count++;}
}
}
p[0]=x; p[1]=y;
if(v==0)
return(ret);
else
return count;
}
void restore(int coin,int rc,int rco)
{
printf("\n The move will\n cause the game to end!!");
getch();
n.cp[p[2]][p[3]][0]=rc;
n.cp[p[2]][p[3]][1]=rco;
if(n.turn)
n.cp[p[0]][p[1]][0]=15;
else
n.cp[p[0]][p[1]][0]=0;
n.cp[p[0]][p[1]][1]=coin;
}
int checkmate()
{
int i,j,v,color,found,c=1,enemy;
v=kingind(1,1);
if(n.turn)
{ color=15; enemy=0; }
else
{ color=0; enemy=15;}
//calculating the next move for all the pieces
for(i=0;i<8;i++)
for(j=0;j<8;j++)
n.onep[i][j]=-1;
for(i=0;i<8;i++)
for(j=0;j<8;j++)
if(n.cp[i][j][0]==color)
{ p[0]=i; p[1]=j;
if(n.cp[i][j][1]==1)
calppp(0);
if(n.cp[i][j][1]==2)
calppc(0);
if(n.cp[i][j][1]==3)
calpph(0);
if(n.cp[i][j][1]==4)
calppca(0);
if(n.cp[i][j][1]==5)
calppq(0);
}
//find the coins attackin the king
for(i=0;i<8&&found;i++)
for(j=0;j<8&&found;j++)
if(n.cp[i][j][0]==color&&n.cp[i][j][1]==6)
found=0;
int x=i-1,y=j-1,z=0,no=1,ii;
for(i=x-1;i>=0&&no;i--)
{ po[z][0]=i; po[z][1]=y; z++;
if(n.cp[i][y][0]==enemy&&n.cp[i][y][1]!=1&&n.cp[i][y][1]!=3&&n.cp[i][y][1]!=6&&n.cp[i][y][1]!=-1)
for(j=0;j<z;j++)
{n.twop[po[j][0]][po[j][1]]=1;
no=0;
}
} z=0; no=1;
for(i=x+1;i<8&&no;i++)
{ po[z][0]=i; po[z][1]=y; z++;
if(n.cp[i][y][0]==enemy&&n.cp[i][y][1]!=1&&n.cp[i][y][1]!=3&&n.cp[i][y][1]!=6&&n.cp[i][y][1]!=-1)
for(j=0;j<z;j++)
{n.twop[po[j][0]][po[j][1]]=1; no=0;
}
} z=0; no=1;
for(i=y-1;i>=0&&no;i--)
{ po[z][0]=x; po[z][1]=i; z++;
if(n.cp[x][i][0]==enemy&&n.cp[x][i][1]!=1&&n.cp[x][i][1]!=3&&n.cp[x][i][1]!=6&&n.cp[x][i][1]!=-1)
for(j=0;j<z;j++)
{n.twop[po[j][0]][po[j][1]]=1; no=0;
}
} z=0; no=1;
for(i=y+1;i<8&&no;i++)
{ po[z][0]=x; po[z][1]=i; z++;
if(n.cp[x][i][0]==enemy&&n.cp[x][i][1]!=1&&n.cp[x][i][1]!=3&&n.cp[x][i][1]!=6&&n.cp[x][i][1]!=-1)
for(j=0;j<z;j++)
{n.twop[po[j][0]][po[j][1]]=1; no=0;
}
} z=0; no=1;
for(i=x+1,j=y+1;i<8&&j<8&&no;i++,j++)
{
po[z][0]=i; po[z][1]=j; z++;
if(n.cp[i][j][0]==enemy&&n.cp[i][j][1]!=1&&n.cp[i][j][1]!=3&&n.cp[i][j][1]!=6&&n.cp[i][j][1]!=-1)
for(ii=0;ii<z;ii++)
{n.twop[po[ii][0]][po[ii][1]]=1; no=0;
}
} z=0; no=1;
for(i=x-1,j=y-1;i>=0&&j>=0&&no;i--,j--)
{
po[z][0]=i; po[z][1]=j; z++;
if(n.cp[i][j][0]==enemy&&n.cp[i][j][1]!=1&&n.cp[i][j][1]!=3&&n.cp[i][j][1]!=6&&n.cp[i][j][1]!=-1)
for(ii=0;ii<z;ii++)
{n.twop[po[ii][0]][po[ii][1]]=1; no=0;
}
} z=0; no=1;
for(i=x+1,j=y-1;i<8&&j>=0&&no;i++,j--)
{
po[z][0]=i; po[z][1]=j; z++;
if(n.cp[i][j][0]==enemy&&n.cp[i][j][1]!=1&&n.cp[i][j][1]!=3&&n.cp[i][j][1]!=6&&n.cp[i][j][1]!=-1)
for(ii=0;ii<z;ii++)
{n.twop[po[ii][0]][po[ii][1]]=1; no=0;
}
} z=0;no=1;
for(i=x-1,j=y+1;i>=0&&j<8&&no;i--,j++)
{
po[z][0]=i; po[z][1]=j; z++;
if(n.cp[i][j][0]==enemy&&n.cp[i][j][1]!=1&&n.cp[i][j][1]!=3&&n.cp[i][j][1]!=6&&n.cp[i][j][1]!=-1)
for(ii=0;ii<z;ii++)
{n.twop[po[ii][0]][po[ii][1]]=1; no=0;
}
}
int h=0;
if(n.cp[x-2][y-1][0]==enemy&&n.cp[x-2][y-1][1]==3&&x-2>=0&&y-1>=0)
{ h=1; n.twop[x-2][y-1]=3;}
if(n.cp[x-1][y-2][0]==enemy&&n.cp[x-1][y-2][1]==3&&x-1>=0&&y-2>=0)
{ h=1; n.twop[x-1][y-2]=3;}
if(n.cp[x+1][y-2][0]==enemy&&n.cp[x+1][y-2][1]==3&&x+1<8&&y-2>=0)
{ h=1; n.twop[x+1][y-2]=3;}
if(n.cp[x+2][y-1][0]==enemy&&n.cp[x+2][y-1][1]==3&&x+2<8&&y-1>=0)
{ h=1; n.twop[x+2][y-1]=3;}
if(n.cp[x-2][y+1][0]==enemy&&n.cp[x-2][y+1][1]==3&&x-2>=0&&y+1<8)
{ h=1; n.twop[x-2][y+1]=3;}
if(n.cp[x-1][y+2][0]==enemy&&n.cp[x-1][y+2][1]==3&&x-1>=0&&y+2<8)
{ h=1; n.twop[x-1][y+2]=3;}
if(n.cp[x+1][y+2][0]==enemy&&n.cp[x+1][y+2][1]==3&&x+1<8&&y+2<8)
{ h=1; n.twop[x+1][y+2]=3;}
if(n.cp[x+2][y+1][0]==enemy&&n.cp[x+2][y+1][1]==3&&x+2<8&&y+1<8)
{ h=1; n.twop[x+2][y+1]=3;}
if(n.turn)
{ if(n.cp[x-1][y-1][0]==enemy&&n.cp[x-1][y-1][1]==1&&x-1>=0&&y-1>=0)
n.twop[x-1][y-1]=1;
if(n.cp[x-1][y+1][0]==enemy&&n.cp[x-1][y+1][1]==1&&x-1>=0&&y+1<8)
n.twop[x-1][y+1]=1;
}
else
{
if(n.cp[x+1][y-1][0]==enemy&&n.cp[x-1][y-1][1]==1&&x+1<8&&y-1>=0)
n.twop[x-1][y-1]=1;
if(n.cp[x+1][y+1][0]==enemy&&n.cp[x-1][y+1][1]==1&&x+1<8&&y+1<8)
n.twop[x-1][y+1]=1;
}
// check if any coin can block the single attack
if(v==1)
for(i=0;i<8;i++)
for(j=0;j<8;j++)
{ if(n.twop[i][j]==1&&n.onep[i][j]==1)
c=0;
if(h)
if(n.twop[i][j]==3&&n.onep[i][j]==1)
c=0;
}
// see if the king can move
for(i=0;i<8&&found;i++)
for(j=0;j<8&&found;j++)
if(n.cp[i][j][0]==color&&n.cp[i][j][1]==6)
found=0;
p[0]=i-1-1; p[1]=j-1-1;
n.kingp[1][1]=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if((p[0]+i)>=0&&(p[0]+i)<8&&(p[1]+j)>=0&&(p[1]+j)<8)
if(n.cp[p[0]+i][p[1]+j][0]!=color)
{ p[0]=p[0]+i; p[1]=p[1]+j;
if(!kingind(1,0))
n.kingp[i][j]=1;
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(n.kingp[i][j]==1&&i!=1&&j!=1)
c=0;
return c;
}
void calpos()
{ int rc,rco;
if(n.cp[p[0]][p[1]][1]==-1)
printf("\nNo Coin\nselected\n");
else
{
if(n.cp[p[0]][p[1]][1]==1) //coin to move is a pawn
{ calppp(1); //calculate possible position for that pawn
if(n.onep[p[2]][p[3]]==1)
{ int j=1;
if(p[2]==0||p[2]==7)
j=promote();
n.cp[p[0]][p[1]][0]=-1;
n.cp[p[0]][p[1]][1]=-1;
if(n.turn)
{ rc=n.cp[p[2]][p[3]][0]; n.cp[p[2]][p[3]][0]=15; }
else
{ rc=n.cp[p[2]][p[3]][0]; n.cp[p[2]][p[3]][0]=0; }
rco=n.cp[p[2]][p[3]][1]; n.cp[p[2]][p[3]][1]=j;
if(kingind(1,0))
{ restore(1,rc,rco);
return;
}
n.turn=(n.turn+1)%2;
}
else
printf("\nNot a\n correct\nmove ");
}
if(n.cp[p[0]][p[1]][1]==2) //coin to move is a castle
{ calppc(1);
if(n.onep[p[2]][p[3]]==1)
{
n.cp[p[0]][p[1]][0]=-1;
n.cp[p[0]][p[1]][1]=-1;
if(n.turn)
{ rc=n.cp[p[2]][p[3]][0]; n.cp[p[2]][p[3]][0]=15; }
else
{ rc=n.cp[p[2]][p[3]][0]; n.cp[p[2]][p[3]][0]=0; }
rco=n.cp[p[2]][p[3]][1]; n.cp[p[2]][p[3]][1]=2;
if( kingind(1,0))
{ restore(2,rc,rco);
return;
}
n.turn=(n.turn+1)%2;
}
else
printf("\nNot a\n correct\nmove ");
}
if(n.cp[p[0]][p[1]][1]==3) //coin to move is a horse
{ calpph(1);
if(n.onep[p[2]][p[3]]==1)
{ n.cp[p[0]][p[1]][0]=-1;
n.cp[p[0]][p[1]][1]=-1;
if(n.turn)
{ rc=n.cp[p[2]][p[3]][0]; n.cp[p[2]][p[3]][0]=15; }
else
{ rc=n.cp[p[2]][p[3]][0]; n.cp[p[2]][p[3]][0]=0; }
rco=n.cp[p[2]][p[3]][1]; n.cp[p[2]][p[3]][1]=3;
if( kingind(1,0))
{ restore(3,rc,rco);
return;
}
n.turn=(n.turn+1)%2;
}
else
printf("\nNot a\n correct\nmove ");
}
if(n.cp[p[0]][p[1]][1]==4) //coin to move is a camel
{ calppca(1);
if(n.onep[p[2]][p[3]]==1)
{ n.cp[p[0]][p[1]][0]=-1;
n.cp[p[0]][p[1]][1]=-1;
if(n.turn)
{ rc=n.cp[p[2]][p[3]][0]; n.cp[p[2]][p[3]][0]=15; }
else
{ rc=n.cp[p[2]][p[3]][0]; n.cp[p[2]][p[3]][0]=0; }
rco=n.cp[p[2]][p[3]][1]; n.cp[p[2]][p[3]][1]=4;
if( kingind(1,0))
{ restore(4,rc,rco);
return;
}
n.turn=(n.turn+1)%2;
}
else
printf("\nNot a\n correct\nmove ");
}
if(n.cp[p[0]][p[1]][1]==5) //coin to move is a queen
{ calppq(1);
if(n.onep[p[2]][p[3]]==1)
{ n.cp[p[0]][p[1]][0]=-1;
n.cp[p[0]][p[1]][1]=-1;
if(n.turn)
{ rc=n.cp[p[2]][p[3]][0]; n.cp[p[2]][p[3]][0]=15; }
else
{ rc=n.cp[p[2]][p[3]][0]; n.cp[p[2]][p[3]][0]=0; }
rco=n.cp[p[2]][p[3]][1]; n.cp[p[2]][p[3]][1]=5;
if( kingind(1,0))
{ restore(5,rc,rco);
return;
}
n.turn=(n.turn+1)%2;
}
else
printf("\nNot a\n correct\nmove ");
}
if(n.cp[p[0]][p[1]][1]==6) //coin to move is a king
{ calppk();
if(n.onep[p[2]][p[3]]==1)
{ n.cp[p[0]][p[1]][0]=-1;
n.cp[p[0]][p[1]][1]=-1;
if(n.turn)
{ rc=n.cp[p[2]][p[3]][0]; n.cp[p[2]][p[3]][0]=15; }
else
{ rc=n.cp[p[2]][p[3]][0]; n.cp[p[2]][p[3]][0]=0; }
rco=n.cp[p[2]][p[3]][1]; n.cp[p[2]][p[3]][1]=66;
if( kingind(1,0))
{ restore(6,rc,rco);
return;
}
n.turn=(n.turn+1)%2;
}
else
printf("\nNot a\n correct\nmove ");
}
if(kingind(1,0))
{ n.checked=1;
n.checkmate=checkmate();
}
else
n.checked=0;
if(n.checkmate)
{ closegraph();
drawboard();
if(n.turn)
printf("\n White Loses ");
else
printf("\n Black loses");
openmenu();
}
}}
void main()
{
clrscr();
n.turn=1;
n.checked=0;
leaf(0);
openmenu();
int a,b,c,d;
while(1){
goon=1;
printf("\nEnter coordinates");
if(n.turn)
printf(" for white");
else
printf(" for black");
if(n.checked)
printf(" YOU HAVE BEEN CHECKED");
if(goon)
{
printf("\nrow:");
a=getch();
if(a==27)
{ menu();
goon=0;
}
if(goon)
printf("%d",a-48);
}
if(goon)
{
printf("\ncolumn:");
b=getche();
if(b==27)
{ menu();
goon=0;
}
if(goon)
printf("%c",b);
}
if(goon)
{
printf("\nrow:");
c=getche();
if(c==27)
{ menu();
goon=0;
}
if(goon)
printf("%d",c-48);}
if(goon)
{
printf("\ncolumn:");
d=getche();
if(d==27)
{ menu();
goon=0;
}
if(goon)
printf("%c",d);
}
if(goon)
{ p[0]=(a-48-8)*-1;
b=toupper(b);
p[1]=b-65;
p[2]=(c-48-8)*-1;
d=toupper(d);
p[3]=d-65;
calpos();
getch();
}
closegraph();
drawboard();
}
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
int board[10], turn = 1, flag = 0, player, comp;
int x1 = 220, y1 = 70, x2 = 230, y2 = 130;
int key, cp = 1, cx = 0, cy = 0;
enum { up = 72, left = 75, right = 77, down = 80} direction;
enum { yes , no } selected;
void menu();
void reset();
void go(int n);
void start_game();
void check_draw();
void draw_board();
void take_input();
void status_bar();
void player_first();
void put_X_O(char *ch,int pos);
void user_choice(int ycolor,int ncolor,char *str1,char *str2);
void main()
{
int gd = DETECT, gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
reset();
menu();
getch();
}
void reset()
{
int i;
for(i=1;i<10;i++)
board[i] = 2;
turn = 1;
flag = 0;
x1 = 170, y1 = 70, x2 = 230, y2 = 130;
}
void menu()
{
cleardevice();
if(yesno(0))
{
player = 0;
comp = 1;
cleardevice();
start_game();
}
else
{
player = 1;
comp = 0;
cleardevice();
player_first();
}
}
int make2()
{
if(board[5] == 2)
return 5;
if(board[2] == 2)
return 2;
if(board[4] == 2)
return 4;
if(board[6] == 2)
return 6;
if(board[8] == 2)
return 8;
return 0;
}
int make4()
{
if(board[1] == 2)
return 1;
if(board[3] == 2)
return 3;
if(board[7] == 2)
return 7;
if(board[9] == 2)
return 9;
return 0;
}
int posswin(int p)
{
// p==1 then X p==0 then O
int i;
int check_val,pos;
if(p == 1)
check_val = 18;
else
check_val = 50;
i = 1;
while(i<=9)//row check
{
if(board[i] * board[i+1] * board[i+2] == check_val)
{
if(board[i] == 2)
return i;
if(board[i+1] == 2)
return i+1;
if(board[i+2] == 2)
return i+2;
}
i+=3;
}
i = 1;
while(i<=3)//column check
{
if(board[i] * board[i+3] * board[i+6] == check_val)
{
if(board[i] == 2)
return i;
if(board[i+3] == 2)
return i+3;
if(board[i+6] == 2)
return i+6;
}
i++;
}
if(board[1] * board[5] * board[9] == check_val)
{
if(board[1] == 2)
return 1;
if(board[5] == 2)
return 5;
if(board[9] == 2)
return 9;
}
if(board[3] * board[5] * board[7] == check_val)
{
if(board[3] == 2)
return 3;
if(board[5] == 2)
return 5;
if(board[7] == 2)
return 7;
}
return 0;
}
void go(int n)
{
if(turn % 2)
board[n] = 3;
else
board[n] = 5;
turn++;
}
void player_first()
{
check_draw();
draw_board();
status_bar();
take_input();
}
void start_game()
{
// p==1 then X p==0 then O
if(posswin(comp))
{
go(posswin(comp));
flag = 1;
}
else
if(posswin(player))
go(posswin(player));
else
if(make2())
go(make2());
else
go(make4());
draw_board();
if(flag)
{
settextstyle(1,0,4);
settextjustify(1,1);
setcolor(128+RED);
outtextxy(320,380,"Computer wins");
getch();
exit(0);
}
else
player_first();
}
void check_draw()
{
if(turn > 9)
{
settextstyle(1,0,4);
settextjustify(1,1);
setcolor(128+RED);
outtextxy(320,380,"Game Draw");
getch();
exit(0);
}
}
void put_X_O(char *ch,int pos)
{
int m;
int x = 170, y = 70;
m = pos;
if(m > 3)
{
while(m > 3)
{
y += 100;
m -= 3;
}
}
if(pos % 3 == 0)
x += 200;
else
{
pos %= 3;
pos--;
while(pos)
{
x += 100;
pos--;
}
}
settextstyle(1,0,7);
settextjustify(1,1);
setcolor(9);
outtextxy(x+30,y+20,ch);
}
void draw_board()
{
int j;
setfillstyle(1,3);
bar(150,50,450,350);
setlinestyle(0,0,3);
setcolor(4);
rectangle(148,48,452,352);
line(250,50,250,350);
line(350,50,350,350);
line(150,150,450,150);
line(150,250,450,250);
setcolor(9);
rectangle(x1,y1,x2,y2);
for(j=1;j<10;j++)
{
if(board[j] == 3)
put_X_O("X",j);
else
if(board[j] == 5)
put_X_O("O",j);
}
}
void take_input()
{
status_bar();
while(1)
{
if(kbhit())
{
flushall();
key = getch();
//if status bar invoked
switch (key)
{
case 13:
if(board[cp] != 2)
break;
if(cp == posswin(player))
{
go(cp);
draw_board();
settextstyle(1,0,4);
settextjustify(1,1);
setcolor(128+RED);
outtextxy(320,380,"Player Wins");
getch();
exit(0);
}
go(cp);
draw_board();
start_game();
break;
case 32:
settextstyle(1,0,4);
settextjustify(1,1);
setcolor(128+BLUE);
outtextxy(320,240,"Press Space bar to continue...");
while(getch() != 32)
continue;
setcolor(0);
outtextxy(320,240,"Press Space bar to continue...");
draw_board();
break;
case 78:
case 110:
if(yesno(1))
{
cp = 1;
cx = 0;
cy = 0;
reset();
main();
}
cleardevice();
draw_board();
status_bar();
break;
case 88:
case 120:
if(yesno(1))
exit(0);
cleardevice();
status_bar();
draw_board();
break;
case up:
if(cx > 0 )
{
setcolor(3);
rectangle(x1,y1,x2,y2);
setcolor(9);
rectangle(x1,y1-100,x2,y2-100);
y1=y1-100;
y2=y2-100;
cx=cx-1;
cp=cp-3;
}
break;
case down:
if(cx < 2 )
{
setcolor(3);
rectangle(x1,y1,x2,y2);
setcolor(9);
rectangle(x1,y1+100,x2,y2+100);
y1=y1+100;
y2=y2+100;
cx=cx+1;
cp=cp+3;
}
break;
case left:
if(cy > 0 )
{
setcolor(3);
rectangle(x1,y1,x2,y2);
setcolor(9);
rectangle(x1-100,y1,x2-100,y2);
x1=x1-100;
x2=x2-100;
cy=cy-1;
cp=cp-1;
}
break;
case right:
if(cy < 2 )
{
setcolor(3);
rectangle(x1,y1,x2,y2);
setcolor(9);
rectangle(x1+100,y1,x2+100,y2);
x1=x1+100;
x2=x2+100;
cy=cy+1;
cp=cp+1;
}
break;
}
}
}
}
int yesno(int choice)
{
int user_key;
char *s1, *s2, *s3;
selected = no;
settextstyle(1,0,4);
settextjustify(1,1);
setcolor(128+BLUE);
if(choice)
{
s1 = "Are you sure ?";
s2 = "YES";
s3 = "NO";
}
else
{
s1 = "Select your Symbol";
s2 = "O";
s3 = "X";
}
outtextxy(320,200,s1);
user_choice(0,2,s2,s3);
while(1)
{
user_key = getch();
switch(user_key)
{
case 75:
case 77:
if(selected == no)
{
user_choice(2,0,s2,s3);
selected=yes;
}
else
{
user_choice(0,2,s2,s3);
selected=no;
}
break;
case 13:
if(selected == yes)
return 1;
return 0;
}
}
}
void user_choice(int ycolor,int ncolor,char *str1,char *str2)
{
setfillstyle(1,ycolor);
bar(215,240,305,280);
outtextxy(260,260,str1);
setfillstyle(1,ncolor);
bar(335,240,425,280);
outtextxy(380,260,str2);
}
void status_bar()
{
setfillstyle(1,BLUE);
bar(95,430,490,460);
setcolor(GREEN);
settextstyle(1,0,3);
settextjustify(0,0);
outtextxy(100,450,"N : New");
outtextxy(220,450,"Space : Pause");
outtextxy(400,450,"X : Exit");
setlinestyle(0,1,4);
}
void menu();
void reset();
void go(int n);
void start_game();
void check_draw();
void draw_board();
void take_input();
void status_bar();
void player_first();
void put_X_O(char *ch,int pos);
void user_choice(int ycolor,int ncolor,char *str1,char *str2);
[COLOR="Red"]
int yesno(int choice);[/COLOR]
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
/*******************************************************
* MYCPLUS Sample Code - http://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 *
*******************************************************/
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<dos.h>
#include<stdlib.h>
#include<iostream.h>
#include<graphics.h>
#include<math.h>
#include<string.h>
float *mem;
int X=0, Y=0;
int row=17,col=5;
char dummy;
char flag='d',flagp='0';
char bflag='u',bflagp='u';
int mflag=0;
char ch,ch1,ch2;
int sflag=0;
int midx,midy;
# define UNCLICKED 0
# define CLICKED 1
# define PI 3.14159
char str1[]={"Muhammad Saqib Roll# 014"};
void typeit (int x,int y,int spacing,char string[])
{
char temp[2];
for (int i=0;i<strlen(string);i++)
{
delay(100);
temp[0]=string[i];
temp[1]='\0';
outtextxy(x+(i+1)*spacing,y,temp);
}//endfor
}
void front()
{
int x,y,h;
for(x=0;x<=100;x++)
{
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(1);
settextstyle(1,0,4);
setusercharsize(x,6,x,3);
setcolor(14);
moveto(310,135);
outtext("..");
setcolor(6);
moveto(310,130);
outtext("I I");
if(x<50)
delay(30);
else
delay(20);
}
for(y=0;y<=100;y++)
{
setcolor(0);
settextstyle(1,0,4);
setusercharsize(y,6,y,3);
moveto(310,135);
outtext("..");
moveto(310,130);
outtext("I I");
if(y>20)
{
settextstyle(7,0,3);
setusercharsize(y-20,35,y-20,30);
setcolor(9);
outtext("CALCULATER");
setcolor(2);
outtext("___________");
delay(15);
if(y<100)
{
settextstyle(7,0,3);
setusercharsize(y-20,35,y-20,30);
setcolor(0);
outtext("CALCULATER");
}
}
}
//delay(1000);
settextstyle(3,0,2);
delay(50);
outtextxy(midx-200,midy,"Group Members:-");
//x=10,y=10;
setcolor(6);
settextstyle(4,0,4);
typeit(midx-200,midy+50,15,str1);
getch();
//closegraph();
}
char input();
double add(double,double,char);
double angle_conv(double);
void basecng(double,double);
/************************************************************/
/* */
/* THIS FUNCTION DRAWS THE BUTTONS OF THE CALCULATER */
/* */
/************************************************************/
void button_3d(int x1,int y1,int x2,int y2,int check,char* text,int color)
{
int up,low;
setfillstyle(1,7);
bar(x1,y1,x2,y2);
if(check==0) //Unclicked
up=15,low=8;
else
up=8,low=15; //Clicked
setcolor(low);
line(x2,y1,x2,y2);
line(x2-1,y1,x2-1,y2);
line(x1,y2,x2,y2);
line(x1+1,y2-1,x2,y2-1);
setcolor(up);
line(x1,y1,x2,y1);
line(x1+1,y1+1,x2-1,y1+1);
line(x1,y1,x1,y2);
line(x1+1,y1+1,x1+1,y2-1);
setcolor(color);
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(x1+(x2 - x1)/2,(y1+(y2 - y1)/2)-2, text);
}
/*********************************************************************/
/* */
/* This function makes the opening screen */
/* */
/*********************************************************************/
void frontpage(void)
{
int mx, my;
mx = (getmaxx() / 2);
my = (getmaxy() / 2);
//SET baqckground color
setfillstyle(9, 1);
bar(0,0,getmaxx(),getmaxy());
//DRAW a bar, and make it look like a 3d bar
setfillstyle(1,7);
bar(50,20,600,400);
//DRAW lines for the top and left side
setcolor(15);
line(50,20,600,20);
line(51,21,599,21);
line(50,20,50,400);
line(51,21,51,399);
//DRAW lines for the bottom and right side
setcolor(8);
line(600,20,600,400);
line(599,21,599,400);
line(50,400,600,400);
line(51,399,600,399);
//DRAW two 3D bars for the left and right side
setfillstyle(9,8);
bar(70,40,100,380);
//getch();
bar(545,40,575,380);
setcolor(8);
rectangle(70,40,100,380);
rectangle(545,40,575,380);
setcolor(15);
line(100,40,100,380);
line(70,380,100,380);
line(575,40,575,380);
line(545,380,575,380);
//DRAW two 3D divider lines on both sides
setcolor(8);
line(110, 40, 110, 380);
line(535, 40, 535, 380);
setcolor(15);
line(111, 40, 111, 380);
line(536, 40, 536, 380);
//PRINT 3D text CALENDAR 2002
settextstyle(1, 0, 4);
settextjustify(1,1);
setcolor(15);
outtextxy(mx+2, my - 46, "MY CALCULATER");
setcolor(7);
outtextxy(mx + 1, my - 45, "MY CALCULATER");
setcolor(8);
outtextxy(mx + 2, my - 44, "MY CALCULATER");
//PRINT 3D text 2002
setcolor(15);
outtextxy(mx, my + 10, "2002");
setcolor(7);
outtextxy(mx + 1, my + 11, "2002");
setcolor(8);
outtextxy(mx + 2, my + 12, "2002");
//PRINT copyright notice
settextstyle(2, 0, 5);
setcolor(1);
outtextxy(mx + 1, my + 85, "Copyright 2002 by ASAS Creations");
getch(); //PAUSE for a while
}
/*********************************************************************/
/* */
/* This function makes the claculating screen */
/* */
/*********************************************************************/
void screen(int x1, int y1, int x2, int y2)
{
setlinestyle(0,0,1);
setfillstyle(SOLID_FILL, 8);
bar(x1, y1, x2, y2);
setfillstyle(SOLID_FILL, BLACK);
bar(x1+1, y1+1, x2-1, y2-1);
settextjustify(CENTER_TEXT, CENTER_TEXT);
setcolor(15);
line(x1+1, y1+1, x1+1, y2-1);
line(x1+1, y1+1, x2-1, y1+1);
line(x1+2, y1+2, x1+2, y2-2);
line(x1+2, y1+2, x2-2, y1+2);
setcolor(8);
line(x1+1, y2-1, x2-1, y2-1);
line(x2-1, y1+1, x2-1, y2-1);
line(x1+2, y2-2, x2-2, y2-2);
line(x2-2, y1+2, x2-2, y2-2);
}
/************************************************************************/
/* */
/* Mouse Related Functions */
/* */
/************************************************************************/
void init_mouse()
{
union REGS iregs, oregs;
iregs.x.ax = 0;
int86 (0x33, &iregs, &oregs);
if (oregs.x.ax == 0)
{
cleardevice();
printf("mouse not installed\n");
getch();
exit(1);
}
iregs.x.ax = 1;
int86 (0x33, &iregs ,&oregs);
}
/*************************************************************/
void mouse()
{
int button,x1,y1;
union REGS iregs, oregs;
iregs.x.ax = 3;
int86 (0x33, &iregs ,&oregs);
button = oregs.x.bx & 3;
x1 = oregs.x.cx;
y1 = oregs.x.dx;
if(oregs.x.bx & 1)
{
X = x1 ; Y = y1;
}
if(button == 3)
exit(0);
}
/*************************************************************/
void hide_mouse()
{
union REGS ioRegs;
ioRegs.x.ax=2;
int86(0x33,&ioRegs,&ioRegs);
}
/*************************************************************/
void show_mouse()
{
union REGS ioRegs;
ioRegs.x.ax=1;
int86(0x33,&ioRegs,&ioRegs);
}
/*************************************************************/
void remove_mouse()
{
union REGS ioRegs;
ioRegs.x.ax=0;
int86(0x33,&ioRegs,&ioRegs);
}
/*************************************************************************/
/* */
/* THIS FUNCTION DRAWS THE CALCULATER ON THE SCREEN */
/* */
/*************************************************************************/
void structure()
{
init_mouse();
setbkcolor(0);
cleardevice();
hide_mouse();
//**********************************************************
// Buttons Making
front();
frontpage();
settextstyle(2,0,4);
button_3d(50,20,600,400,UNCLICKED,"",1); // main box
screen(100,50,545,120); // screen
setfillstyle(1,8);
bar(52,22,598,42);
button_3d(575,23,595,40,UNCLICKED,"x",0);
setcolor(0);
outtextxy(120,30,"Calculater v1.0");
button_3d(108,140,208,160,UNCLICKED,"DEC",15); // box of decimal
button_3d(218,140,318,160,UNCLICKED,"OCT",0); // box of octal
button_3d(328,140,428,160,UNCLICKED,"HEX",0); // box of hexal
button_3d(438,140,538,160,UNCLICKED,"BIN",0); // box of binary
button_3d(350,205,380,225,UNCLICKED,"7",0); // Box Of 7
button_3d(390,205,420,225,UNCLICKED,"8",0); // Box Of 8
button_3d(430,205,460,225,UNCLICKED,"9",0); // Box Of 9
button_3d(350,230,380,250,UNCLICKED,"4",0); // Box Of 4
button_3d(390,230,420,250,UNCLICKED,"5",0); // Box Of 5
button_3d(430,230,460,250,UNCLICKED,"6",0); // Box Of 6
button_3d(480,230,510,250,UNCLICKED,"*",0); // Box Of *
button_3d(515,230,545,250,UNCLICKED,"/",0); // Box Of \
button_3d(480,205,510,225,UNCLICKED,"AC",4); //Box Of AllClear (AC)
button_3d(515,205,545,225,UNCLICKED,"CE",4); //Box Of Clear (C)
button_3d(350,255,380,275,UNCLICKED,"1",0); // Box Of 1
button_3d(390,255,420,275,UNCLICKED,"2",0); // Box Of 2
button_3d(430,255,460,275,UNCLICKED,"3",0); // Box Of 3
button_3d(350,280,380,300,UNCLICKED,"0",0); // Box Of Zero (0)
button_3d(390,280,420,300,UNCLICKED,".",0); // Box Of Period (.)
button_3d(430,280,460,300,UNCLICKED,"pi",0); // Box Of PhiFunction
button_3d(480,255,510,275,UNCLICKED,"-",0); // Box Of -
button_3d(515,255,545,275,UNCLICKED,"+",0); // Box Of +
button_3d(350,305,460,325,UNCLICKED,"=",0); // Box Of Equality
button_3d(480,305,545,325,UNCLICKED,"shift",BLUE); // Box Of shift
button_3d(480,280,510,300,UNCLICKED,"sqrt",0); //Box of x^n
button_3d(515,280,545,300,UNCLICKED,"inv",0); //box of 1/x
button_3d(100,205,150,230,UNCLICKED,"Sin",0); // Box OfSin Function
button_3d(160,205,210,230,UNCLICKED,"Cos",0); // Box Of CosFunction
button_3d(220,205,270,230,UNCLICKED,"Tan",0); // Box Of Tan Function
button_3d(100,250,150,275,UNCLICKED,"sin^-1",0); // Box Of sin^-1
button_3d(160,250,210,275,UNCLICKED,"cos^-1",0); // Box Of cos^-1
button_3d(220,250,270,275,UNCLICKED,"tan^-1",0); // Box Of tan^-1
button_3d(100,300,150,325,UNCLICKED,"ln",0); // Box Of ln
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(BLUE);
settextstyle(2,0,4);
outtextxy(125,290,"e");
outtextxy(185,290,"10^x");
outtextxy(245,290,"x^3");
button_3d(160,300,210,325,UNCLICKED,"log",0); // Box Of log
button_3d(220,300,270,325,UNCLICKED,"x^2",0); // Box Of x^2
button_3d(100,350,150,370,UNCLICKED,"deg",15);
button_3d(160,350,210,370,UNCLICKED,"rad",0);
button_3d(220,350,270,370,UNCLICKED,"gra",0);
button_3d(480,350,545,370,UNCLICKED,"Off",4);
button_3d(350,350,380,370,UNCLICKED,"M+",0);
button_3d(390,350,420,370,UNCLICKED,"M-",0);
button_3d(430,350,460,370,UNCLICKED,"MR",0);
}
/*********************************************************/
/* */
/* Main starts */
/* */
/*********************************************************/
void main()
{
clrscr();
double y=0,z=0,pnt,pnt1=0,x=0,r=0;
int gdriver = DETECT, gmode, errorcode;
int i;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
midx=getmaxx()/2;midy=getmaxy()/2;
structure();
gotoxy(row,col);
printf("\t\t\t\t\t");
gotoxy(row,col);
printf("0");
mem=(float*)malloc(y*sizeof(float));
while( ch!=27&&ch1!=27) //While Escape is not pressed
{ //and if base is not 10
pnt1=0;//no doubleing point entered Yet
ch2='0';
// for(int a=0;ch!=27;a++)//a indicates whether a no. has been entered or not
while(ch2!=27)
//a=0 means that no no. has been entered yet
{
if(bflagp!='u')
{
//gotoxy(row,col);
dummy=input();
if(dummy!='o')
{
gotoxy(row,col);
printf("The trail version does not support this feature");
input();
gotoxy(row,col);
printf("\t\t\t\t\t\t");
// ch='0';
}
y=0;z=0;ch='0';
gotoxy(row,col);
printf("\t\t\t\t\t\t");
gotoxy(row,col);
printf("0");
// bflagp='u';
}
ch=input();
if(ch=='>'||ch=='<'||ch=='?')
{ sflag=0;
if(ch=='>') //M+
*mem+=y;
if(ch=='<') //M-
*mem-=y;
if(ch=='?') //MR
{
y=*mem;
gotoxy(row,col);
printf("\t\t\t\t\t\t");
gotoxy(row,col);
printf("%g",y);
}
if(*mem==0)
mflag=0;
if(*mem!=0)
mflag=1;
}
if(mflag==0)
{
gotoxy(row,7);
printf(" ");
}
if(mflag!=0)
{
gotoxy(row,7);
printf("M");
}
gotoxy(row,col);
if(ch=='a')
{ sflag=0;
y=0;
gotoxy(row,col);
printf("\t\t\t\t\t");
gotoxy(row,col);
printf("0");
}
if(ch=='o')
//for clearing the screen of the calculater
{
sflag=0;
y=0;z=0;
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("0");
gotoxy(row,col);
break;
}
if(ch=='q')
{
sflag=0;
y=sqrt(y);
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("%g",y);
}
if(ch=='m')
{
sflag=0;
y=1/y;
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("%g",y);
}
if(ch=='+'||ch=='-'||ch=='/'||ch=='\\'||ch=='='||ch=='*')
{
sflag=0;
break;
}
if(ch=='.') //case for a decimal point
{
sflag=0;
if(pnt1==0) //ie no decimal has been entered yet
{
gotoxy(row,col);
printf("\t\t\t\t ");// double
gotoxy(row,col);
printf("%g.",y);
pnt1=.1; //ie one decimal point no has been entered
continue; //go back to the begining and get the next number
}
else //decimal point has alredy been entered and thus no change in the screen
{
sflag=0;
continue; //go back to the begining
}
}//out of the '.' condition
if(pnt1!=0) //ie we have a doubleing point
{ sflag=0;
if(ch<='9'&&ch>='0') //input integer
{
// printf("%c",ch);
x=(double)ch;//type cast the character into double to perforn further operations
x-=48; //since character digit indoubleing -48 gives the corresponding ASCII
x=x*pnt1; //make it a decimal
y=x+y; //add it in result
pnt1*=.1; //shift to the second doubleing point
gotoxy(row,col);
printf("%g",y);
gotoxy(row,col);
continue; //back to the top
}
}
//if no decimal point number then proceed
if(ch<='9'&&ch>='0')
{ sflag=0;
x=(double)ch; //typecast to double
x-=48; //get corresponding ASCII
y=(y*10)+x; //add to right of result
gotoxy(row,col); //go back to start of the calc screen
printf("\t\t\t\t "); //clear the screen
gotoxy(row,col);
printf("%g",y); //print the number
}
if(ch=='u'||ch=='v'||ch=='w'||ch=='x')
{ sflag=0;
if(bflagp==bflag&&bflag=='u')
continue;
else
basecng(y,pnt1);
}
if(ch=='d'||ch=='r'||ch=='g')
{sflag=0;
y=angle_conv(y);
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("%g",y);
// gotoxy(row,col);
// printf("%g",y);
// continue;
}
if(ch=='s'||ch=='c'||ch=='t'||ch=='i'||ch=='j'||ch=='k'||ch=='n'||ch=='l'||ch=='p'||ch=='h')
//ie the user opted for a function
{
if(ch=='s'||ch=='c'||ch=='t') //sin /cos/tan
{ sflag=0;
if(flag!='r')
{
flagp=flag;
flag='r';
y=angle_conv(y);
flag=flagp;
}
// gotoxy(row,col);
// printf("%g",y);getch();
switch(ch)
{
case 's': y=sin(y); break;
case 'c': y=cos(y); break;
case 't': y=tan(y); break;
}
}
if(ch=='i'||ch=='j'||ch=='k')
{sflag=0;
if(flag!='r')
{
// flagp=flag;
flagp='r';
//y=angle_conv(y);
}
switch(ch)
{
case 'i': y=asin(y); break;
case 'j': y=acos(y); break;
case 'k': y=atan(y); break;
}
if(flag!='r')
y=angle_conv(y);
}
else if(ch=='n')
{
if(sflag==1)
{
y=exp(y);
sflag=0;
}
else
y=log(y); //ln
}
else if(ch=='l')
{
if(sflag==1)
{
y=pow(10,y);
sflag=0;
}
else
y=log10(y); //log
}
else if(ch=='p')
{
if(sflag==1)
{
y=pow(y,3);
sflag=0;
}
else
y=pow(y,2); //square
}
else if(ch=='h')
{
sflag=0;
y=PI; //pi
}
gotoxy(row,col);
printf("\t\t\t\t ");//Clear the screen
gotoxy(row,col);
printf("%g",y);
}//else condition
}//out of second condition ie we now have the first no. or function or operater
for(;ch!=27&&ch1!='='&&ch!='=';)//ie the characters input are not ESCAPE or Equal to
{
pnt1=0;z=0;
if(ch=='o'||ch1=='o') // For Clear The Screen
{
sflag=0;
y=0;z=0;
gotoxy(row,col);
printf("\t\t\t\t ");
// gotoxy(col,row);
gotoxy(row,col);
printf("0");
gotoxy(row,col);
break;
}
for(;ch1!=27;)
{
gotoxy(row,col);
// printf("%g",z);
// z=0;
ch1=input();
if(ch1=='>'||ch1=='<'||ch1=='?')
{
if(ch1=='>') //M+
*mem+=z;
if(ch1=='<') //M-
*mem-=z;
if(ch1=='?') //MR
{
z=*mem;
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("%g",z);
}
if(*mem==0)
mflag=0;
if(*mem!=0)
mflag=1;
}
if(mflag==0)
{
gotoxy(row,7);
printf(" ");
}
if(mflag!=0)
{
gotoxy(row,7);
printf("M");
}
gotoxy(row,col);
if(ch1=='a')
{
z=0;
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("0");
}
if(ch=='o'||ch1=='o') // For Clear The Screen
{
y=0;z=0;
gotoxy(row,col);
//cout<<" ";
printf("\t\t\t\t ");
gotoxy(row,col);
printf("0");
gotoxy(row,col);
break;
}
if(ch1=='q')
{
z=sqrt(z);
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("%g",z);
}
if(ch1=='m')
{
z=1/z;
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("%g",z);
}
if(ch1=='.')
{
if(pnt1==0)
{
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
//cout<<z<<".";
printf("%g.",z);
pnt1=.1;
continue;
}
else
{
continue;
}
}
if(pnt1!=0)
{
if(ch1<='9'&&ch1>='0')
{
// printf("%c",ch1);
x=(double)ch1;
x-=48;
x=x*pnt1;
z=x+z;
pnt1=pnt1*.1;
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("%g",z);
continue;
}
}
if(ch1=='+'||ch1=='-'||ch1=='*'||ch1=='/'||ch1=='=')
break;
if(ch1>='0'&&ch1<='9')
{
x=(double)ch1;
x=x-48;
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
z=(z*10)+x;
printf("%g",z);
}
if(ch=='u')
if(ch=='d'||ch=='r'||ch=='g')
{
z=angle_conv(z);
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("%g",z);
// continue;
}
if(ch1=='s'||ch1=='c'||ch1=='t'||ch1=='i'||ch1=='j'||ch1=='k'||ch1=='n'||ch1=='l'||ch1=='p'||ch1=='h')
//ie the user opted for a function
{
if(ch1=='s'||ch1=='c'||ch1=='t') //sin
{
if(flag!='r')
{
flagp=flag;
flag='r';
angle_conv(z);
flag=flagp;
}
switch(ch1)
{
case 's': z=sin(z); break;
case 'c': z=cos(z); break;
case 't': z=tan(z); break;
}
}
if(ch1=='i'||ch1=='j'||ch1=='k')
{
if(flag!='r')
{
flagp='r';
}
switch(ch1)
{
case 'i': z=asin(z); break;
case 'j': z=acos(z); break;
case 'k': z=atan(z); break;
}
z=angle_conv(z);
}
else if(ch1=='l')
{
z=log10(z); //log
}
else if(ch1=='p')
{
z=pow(z,2); //square
}
else if(ch1=='h')
{
z=PI; //pi
}
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("%g",z);
gotoxy(row,col);
}
}
if(ch1=='+'||ch1=='-'||ch1=='=')
{
y=add(y,z,ch);
if(ch2!='0')
{
y=add(r,y,ch2);
ch2='0';
}
}
else
{
if(ch=='*'||ch=='/')
y=add(y,z,ch);
else
{
ch2=ch;
r=y;
y=z;
}
}
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("%g",y);
ch=ch1;
ch1='0';
if(ch=='='||ch1=='=')
break;
}
if(ch=='o'||ch1=='o') // For Clear The Screen
{ y=0;z=0;
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("0");
gotoxy(row,col);
continue;
}
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("%g",y);
z=0;
}
// getch();
closegraph();
remove_mouse();
exit(0);
}
/*************************************************************/
/* */
/* This function gets the user's Input */
/* */
/*************************************************************/
char input()
{
X=0;Y=0;
char ch;
show_mouse();
if(bflag!='u')
{
button_3d(108,140,208,160,UNCLICKED,"DEC",15);
button_3d(218,140,318,160,UNCLICKED,"OCT",0);
button_3d(328,140,428,160,UNCLICKED,"HEX",0);
button_3d(438,140,538,160,UNCLICKED,"BIN",0);
bflag='u';
}
do
{
mouse();
if (X>=350 && X<=380 && Y>=205 && Y<=225) // Condition For 7
{
hide_mouse();
button_3d(350,205,380,225,CLICKED,"7",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(350,205,380,225,UNCLICKED,"7",0);
show_mouse();
ch='7';
return ch;
}
//**********************************************
if (X>=390 && X<=420 && Y>=205 && Y<=225) // Condition For 8
{
hide_mouse();
button_3d(390,205,420,225,CLICKED,"8",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(390,205,420,225,UNCLICKED,"8",0);
show_mouse();
ch='8';
return ch;
}
//*****************************************
if (X>=430 && X<=460 && Y>=205 && Y<=225) // Condition For 9
{
hide_mouse();
button_3d(430,205,460,225,CLICKED,"9",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(430,205,460,225,UNCLICKED,"9",0);
show_mouse();
ch='9';
return ch;
}
//***********************************
if (X>=350 && X<=380 && Y>=230 && Y<=250) // Condition For 4
{
hide_mouse();
button_3d(350,230,380,250,CLICKED,"4",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(350,230,380,250,UNCLICKED,"4",0);
show_mouse();
ch='4';
return ch;
}
//***********************************
if (X>=390 && X<=420 && Y>=230 && Y<=250) // Condition For 5
{
hide_mouse();
button_3d(390,230,420,250,CLICKED,"5",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(390,230,420,250,UNCLICKED,"5",0);
show_mouse();
ch='5';
return ch;
}
//***********************************
if (X>=430 && X<=460 && Y>=230 && Y<=250) // Condition For 6
{
hide_mouse();
button_3d(430,230,460,250,CLICKED,"6",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(430,230,460,250,UNCLICKED,"6",0);
show_mouse();
ch='6';
return ch;
}
//***********************************
if (X>=480 && X<=510 && Y>=230 && Y<=250) // Condition For *
{
hide_mouse();
button_3d(480,230,510,250,CLICKED,"*",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(480,230,510,250,UNCLICKED,"*",0);
show_mouse();
ch='*';
return ch;
}
//***********************************
if (X>=515 && X<=545 && Y>=230 && Y<=250) // Condition For /
{
hide_mouse();
button_3d(515,230,545,250,CLICKED,"/",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(515,230,545,250,UNCLICKED,"/",0);
show_mouse();
ch='/';
return ch;
}
//***********************************
int a,b;
if (X>=350 && X<=380 && Y>=255 && Y<=275) // Condition For 1
{
hide_mouse();
button_3d(350,255,380,275,CLICKED,"1",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(350,255,380,275,UNCLICKED,"1",0);
show_mouse();
ch='1';
return ch;
}
// *************************************
if (X>=390 && X<=420 && Y>=255 && Y<=275) // Condition For 2
{
hide_mouse();
button_3d(390,255,420,275,CLICKED,"2",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(390,255,420,275,UNCLICKED,"2",0);
show_mouse();
ch='2';
return ch;
}
// *************************************
if (X>=430 && X<=460 && Y>=255 && Y<=275) // Condition For 3
{
hide_mouse();
button_3d(430,255,460,275,CLICKED,"3",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(430,255,460,275,UNCLICKED,"3",0);
show_mouse();
ch='3';
return ch;
}
// *************************************
if (X>=350 && X<=380 && Y>=280 && Y<=300) // Condition For 0
{
hide_mouse();
button_3d(350,280,380,300,CLICKED,"0",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(350,280,380,300,UNCLICKED,"0",0);
show_mouse();
ch='0';
return ch;
}
// *************************************
if (X>=390 && X<=420 && Y>=280 && Y<=300) // Condition For .
{
hide_mouse();
button_3d(390,280,420,300,CLICKED,".",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(390,280,420,300,UNCLICKED,".",0);
show_mouse();
ch='.';
return ch;
}
//**********************************************
if (X>=430 && X<=460 && Y>=280 && Y<=300) // Condition For pi
{
hide_mouse();
button_3d(430,280,460,300,CLICKED,"pi",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(430,280,460,300,UNCLICKED,"pi",0);
show_mouse();
ch='h';
return ch;
}
//***********************************************
if (X>=480 && X<=510 && Y>=255 && Y<=275) // Condition For -
{
hide_mouse();
button_3d(480,255,510,275,CLICKED,"-",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(480,255,510,275,UNCLICKED,"-",0);
show_mouse();
ch='-';
return ch;
}
//**************************************************
if (X>=515 && X<=545 && Y>=255 && Y<=275) // Condition For +
{
hide_mouse();
button_3d(515,255,545,275,CLICKED,"+",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(515,255,545,275,UNCLICKED,"+",0);
show_mouse();
ch='+';
return ch;
}
//*****************************************************
if (X>=350 && X<=460 && Y>=305 && Y<=325) // Condition For =
{
hide_mouse();
button_3d(350,305,460,325,CLICKED,"=",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(350,305,460,325,UNCLICKED,"=",0);
show_mouse();
ch='=';
return ch;
}
//*****************************************************
if (X>=480 && X<=545 && Y>=305 && Y<=325) // Condition For shift
{
hide_mouse();
button_3d(480,305,545,325,CLICKED,"shift",BLUE);
show_mouse();
delay(250);
hide_mouse();
button_3d(480,305,545,325,UNCLICKED,"shift",BLUE);
show_mouse();
ch='~';
sflag=1;
return ch;
}
//*************************************
if (X>=480 && X<=510 && Y>=205 && Y<=225) // Condition For AC
{
hide_mouse();
button_3d(480,205,510,225,CLICKED,"AC",4);
show_mouse();
delay(250);
hide_mouse();
button_3d(480,205,510,225,UNCLICKED,"AC",4);
show_mouse();
ch='o';
return ch;
}
/********************C*/
if (X>=515 && X<=545 && Y>=205 && Y<=225) // Condition For C
{
hide_mouse();
button_3d(515,205,545,225,CLICKED,"CE",4);
show_mouse();
delay(250);
hide_mouse();
button_3d(515,205,545,225,UNCLICKED,"CE",4);
show_mouse();
ch='a';
return ch;
}
// ****************************************
if (X>=100 && X<=150 && Y>=205 && Y<=230) // Condition For Sin
{
hide_mouse();
button_3d(100,205,150,230,CLICKED,"Sin",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(100,205,150,230,UNCLICKED,"Sin",0);
show_mouse();
ch='s';
return ch;
}
//***********************************
if (X>=160 && X<=210 && Y>=205 && Y<=230) // Condition For Cos
{
hide_mouse();
button_3d(160,205,210,230,CLICKED,"Cos",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(160,205,210,230,UNCLICKED,"Cos",0);
show_mouse();
ch='c';
return ch;
}
//***********************************
if(X>=515&&X<=545&&Y>=280&&Y<=300) //inverse
{
hide_mouse();
button_3d(515,280,545,300,CLICKED,"inv",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(515,280,545,300,UNCLICKED,"inv",0);
show_mouse();
ch='m';
return ch;
}
if (X>=220 && X<=270 && Y>=205 && Y<=230) // Condition For Tan
{
hide_mouse();
button_3d(220,205,270,230,CLICKED,"Tan",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(220,205,270,230,UNCLICKED,"Tan",0);
show_mouse();
ch='t';
return ch;
}
//*********************************** */
if (X>=100 && X<=150 && Y>=250 && Y<=275) // Condition For sin^-1
{
hide_mouse();
button_3d(100,250,150,275,CLICKED,"sin^-1",0);
show_mouse();
delay(150);
hide_mouse();
button_3d(100,250,150,275,UNCLICKED,"sin^-1",0);
show_mouse();
ch='i';
return ch;
}
//**************************
if (X>=160 && X<=210 && Y>=250 && Y<=275) // Condition For cos^-1
{
hide_mouse();
button_3d(160,250,210,275,CLICKED,"cos^-1",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(160,250,210,275,UNCLICKED,"cos^-1",0);
show_mouse();
ch='j';
return ch;
}
//**************************
if (X>=430 && X<=460 && Y>=350 && Y<=370) // Condition For MR
{
hide_mouse();
button_3d(430,350,460,370,CLICKED,"MR",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(430,350,460,370,UNCLICKED,"MR",0);
show_mouse();
ch='?';
return ch;
}
if (X>=390 && X<=420 && Y>=350 && Y<=370) // Condition For M-
{
hide_mouse();
button_3d(390,350,420,370,CLICKED,"M-",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(390,350,420,370,UNCLICKED,"M-",0);
show_mouse();
ch='<';
return ch;
}
if (X>=350 && X<=380 && Y>=350 && Y<=370) // Condition For M+
{
hide_mouse();
button_3d(350,350,380,370,CLICKED,"M+",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(350,350,380,370,UNCLICKED,"M+",0);
show_mouse();
ch='>';
return ch;
}
if (X>=220 && X<=270 && Y>=250 && Y<=275) // Condition For tan^-1
{
hide_mouse();
button_3d(220,250,270,275,CLICKED,"tan^-1",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(220,250,270,275,UNCLICKED,"tan^-1",0);
show_mouse();
ch='k';
return ch;
}
//**************************
if (X>=100 && X<=150 && Y>=300 && Y<=325) // Condition For ln
{
hide_mouse();
button_3d(100,300,150,325,CLICKED,"ln",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(100,300,150,325,UNCLICKED,"ln",0);
show_mouse();
ch='n';
return ch;
}
//**************************
if (X>=160 && X<=210 && Y>=300 && Y<=325) // Condition For log
{
hide_mouse();
button_3d(160,300,210,325,CLICKED,"log",0);
show_mouse();
delay(150);
hide_mouse();
button_3d(160,300,210,325,UNCLICKED,"log",0);
show_mouse();
ch='l';
return ch;
}
//**************************
if (X>=220 && X<=270 && Y>=300 && Y<=325) // Condition For X^2
{
hide_mouse();
button_3d(220,300,270,325,CLICKED,"x^2",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(220,300,270,325,UNCLICKED,"x^2",0);
show_mouse();
ch='p';
return ch;
}
if (X>=100 && X<=150 && Y>=350 && Y<=370) // Condition For deg
{
hide_mouse();
button_3d(100,350,150,370,CLICKED,"deg",15);
button_3d(160,350,210,370,UNCLICKED,"rad",0);
button_3d(220,350,270,370,UNCLICKED,"gra",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(100,350,150,370,UNCLICKED,"deg",15);
show_mouse();
ch='d';
flagp=flag;
flag=ch;
return ch;
} //**************************
if (X>=160 && X<=210 && Y>=350 && Y<=370) // Condition For rad
{
hide_mouse();
button_3d(100,350,150,370,UNCLICKED,"deg",0);
button_3d(160,350,210,370,CLICKED,"rad",15);
button_3d(220,350,270,370,UNCLICKED,"gra",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(160,350,210,370,UNCLICKED,"rad",15);
show_mouse();
ch='r';
flagp=flag;
flag=ch;
return ch;
}
if (X>=220 && X<=270 && Y>=350 && Y<=370) // Condition For gra
{
hide_mouse();
button_3d(100,350,150,370,UNCLICKED,"deg",0);
button_3d(160,350,210,370,UNCLICKED,"rad",0);
button_3d(220,350,270,370,CLICKED,"gra",15);
show_mouse();
delay(250);
hide_mouse();
button_3d(220,350,270,370,UNCLICKED,"gra",15);
show_mouse();
ch='g';
flagp=flag;
flag=ch;
return ch;
}
if ((X>=480 && X<=545 &&Y>=350 &&Y <=370)||(X>=575&&X<=595&&Y>=23&&Y<=40)) //OFF
{
free(mem);
exit(0);
}
if (X>=108 && X<=208 && Y>=140 && Y<=160) // Condition For dec
{
hide_mouse();
button_3d(108,140,208,160,CLICKED,"DEC",15);
button_3d(218,140,318,160,UNCLICKED,"OCT",0);
button_3d(328,140,428,160,UNCLICKED,"HEX",0);
button_3d(438,140,538,160,UNCLICKED,"BIN",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(108,140,208,160,UNCLICKED,"DEC",15);
show_mouse();
ch='u';
bflagp=bflag;
bflag=ch;
return ch;
}
if (X>=218 && X<=318 && Y>=140 && Y<=160) // Condition For oct
{
hide_mouse();
button_3d(108,140,208,160,UNCLICKED,"DEC",0);
button_3d(218,140,318,160,CLICKED,"OCT",15);
button_3d(328,140,428,160,UNCLICKED,"HEX",0);
button_3d(438,140,538,160,UNCLICKED,"BIN",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(218,140,318,160,UNCLICKED,"OCT",15);
show_mouse();
ch='v';
bflagp=bflag;
bflag=ch;
return ch;
}
if (X>=328 && X<=428 && Y>=140 && Y<=160) // Condition For hex
{
hide_mouse();
button_3d(108,140,208,160,UNCLICKED,"DEC",0);
button_3d(218,140,318,160,UNCLICKED,"OCT",0);
button_3d(328,140,428,160,CLICKED,"HEX",15);
button_3d(438,140,538,160,UNCLICKED,"BIN",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(328,140,428,160,UNCLICKED,"HEX",15);
show_mouse();
ch='w';
bflagp=bflag;
bflag=ch;
return ch;
}
if (X>=438 && X<=538 && Y>=140 && Y<=160) // Condition For dec
{
hide_mouse();
button_3d(108,140,208,160,UNCLICKED,"DEC",0);
button_3d(218,140,318,160,UNCLICKED,"OCT",0);
button_3d(328,140,428,160,UNCLICKED,"HEX",0);
button_3d(438,140,538,160,CLICKED,"BIN",15);
show_mouse();
delay(250);
hide_mouse();
button_3d(438,140,538,160,UNCLICKED,"BIN",15);
show_mouse();
ch='x';
bflagp=bflag;
bflag=ch;
return ch;
}
if(X>=480&&X<=510&&Y>=280&&Y<=300)
{
hide_mouse();
button_3d(480,280,510,300,CLICKED,"sqrt",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(480,280,510,300,UNCLICKED,"sqrt",0);
show_mouse();
ch='q';
return ch;
}
}while(kbhit() == 0);
ch=getch();
return ch;
}
/*************************************************************************/
/* */
/* This function performs the Calculations */
/* */
/*************************************************************************/
double add(double x,double y,char ch)
{
switch(ch)
{
case '+':
y=x+y;
break;
case '-':
y=x-y;
break;
case '*':
y=x*y;
break;
case '/':
y=x/y;
}
return y;
}
double angle_conv(double no)
{
if(flagp=='d')
{
if(flag=='r')
{
no=no*PI/180;
}
if(flag=='g')
{
no=no*1.1111111;
}
}
else if(flagp=='r')
{
if(flag=='d')
{
no=no*180/PI;
}
if(flag=='g')
{
no=no*180/PI*1.1111111;
}
}
else if(flagp=='g')
{
if(flag=='r')
{
no=no/(180*1.1111111)*PI;
}
if(flag=='d')
{
no=no/1.1111111;
}
}
return(no);
}
void basecng(double y,double pnt1)
{
char str[17];
if(pnt1!=0)
{
gotoxy(row,col);
printf("The trial version does not support this feature");
getch();
bflag='u';
bflagp='0';
main();
}
if(bflagp!='u')
{
gotoxy(row,col);
printf("The trial version does not support this feature ");
getch();
bflagp='0';
bflag='u';
main();
}
switch(bflag)
{
case 'v':
itoa(y,str,8);
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("%s",str);
bflagp='0';
break;
case 'w':
itoa(y,str,16);
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("%s",str);
bflagp='0';
// getch();
break;
case 'x':
itoa(y,str,2);
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("%s",str);
// getch();
bflagp='0';
break;
}
bflag='u';
}