Source code to create chess game using C++
#include
#include
#include
#include
#include
#define White 0
#define Black 1
void draw_piece(int);
int marker(int,short);
int valid_move(int,int);
int previous_move_pick=0,previous_move_put=0;
void chessboard();
void pawn(int,float,float);
void rook(int,float,float);
void knight(int,float,float);
void bishop(int,float,float);
void queen(int,float,float);
void king(int,float,float);
int dx,dy;
union REGS i,o;
int Square_Color[64]= { 1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1 };
int Board[64]= {15,12,13,17,19,13,12,15,
11,11,11,11,11,11,11,11,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,
5,2,3,7,9,3,2,5 };
void main()
{
int driver=DETECT,mode;
int x,y;
union REGS ii,oo;
initgraph(&driver,&mode,"");
x=getmaxx()/2;
y=getmaxy()/2;
chessboard();
struct palettetype pal;
getpalette(&pal);
setrgbpalette(pal.colors[6],35,33,25);
setfillstyle(SOLID_FILL,6);
floodfill(x+250,y,15);
for(int b=0;b<64;b++)
draw_piece(b);
int Marker=56;
marker(Marker,1);
int pick_up,Mode=0,put_down;
int turn=White;
int checker;
while(1)
{
if(kbhit())
{
ii.h.ah=0;
int86(22,&ii,&oo);
if(oo.h.ah==1)
{
closegraph();
exit(0);
}
if(oo.h.ah==77)
{
if((Marker+1)%8!=0)
{
marker(Marker,0);
Marker++;
marker(Marker,1);
}
}
if(oo.h.ah==75)
{
if(Marker%8!=0)
{
marker(Marker,0);
Marker--;
marker(Marker,1);
}
}
if(oo.h.ah==72)
{
if(Marker>7)
{
marker(Marker,0);
Marker-=8;
marker(Marker,1);
}
}
if(oo.h.ah==80)
{
if(Marker<56)
{
marker(Marker,0);
Marker+=8;
marker(Marker,1);
}
}
if(oo.h.ah==28)
{
if(Mode==0)
{
if(turn==White) {
if(Board[Marker]!=0&&Board[Marker]<10)
{
pick_up=Marker;
marker(Marker,3);
Mode=1;
} }
else if(turn==Black) {
if(Board[Marker]!=0&&Board[Marker]>10)
{
pick_up=Marker;
marker(Marker,3);
Mode=1;
} }
}
else if(Mode==1)
{
put_down=Marker;
if(put_down==pick_up)
{ Mode=0; marker(put_down,4); goto cancel; }
checker=valid_move(pick_up,put_down);
if(checker==0)
{ Mode=0; marker(pick_up,4); goto cancel; }
if(checker==2) {
Board[pick_up]=0;
marker(put_down,2);
for( b=0;b<64;b++)
draw_piece(b);
setcolor(6);
outtextxy(530,50,"choose piece");
}
if(checker==1) {
Board[put_down]=Board[pick_up];
Board[pick_up]=0;
marker(put_down,2);
for(b=0;b<64;b++)
draw_piece(b);
}
marker(pick_up,2);
setcolor(15);
rectangle(x-200,y-200,x+200,y+200);
Mode=0;
if(turn==White)
turn=Black;
else if(turn==Black)
turn=White;
previous_move_pick=pick_up;
previous_move_put=put_down;
cancel:
}
}
}
}
}
valid_move(int pick,int put)
{
int leftup,leftdown,rightup,rightdown;
int up,down,right,left;
int sx,sy;
int i;
int x=getmaxx()/2,y=getmaxy()/2;
if(Board[pick]<10 && Board[put]<10 && Board[put]!=0)
return 0;
if(Board[pick]>10 && Board[put]>10 && Board[put]!=0)
return 0;
if(Board[pick]==1)
{
if(pick>=48&&pick<=55)
{
if(put!=pick-8&&put!=pick-16&&put!=pick-7&&put!=pick-9)
return 0;
if(put==pick-16)
{
if( Board[pick-8]!=0 || Board[pick-16]!=0)
return 0;
}
else if(put==pick-8)
{
if(Board[pick-8]!=0)
return 0;
}
else if(put==pick-7)
{
if(Board[pick-7]==0||Board[pick-7]<10)
return 0;
}
else if(put==pick-9)
{
if(Board[pick-9]==0||Board[pick-9]<10)
return 0;
}
}
else if(pick<=47)
{
if(pick<=31 && pick>=24)
{
if(pick!=24)
if(previous_move_pick==(pick-17)&&previous_move_put==(pick-1)&&put==pick-9)
{
Board[pick-1]=0;
marker(pick-1,2);
return 1;
}
if(pick!=31)
if(previous_move_pick==(pick-15)&&previous_move_put==(pick+1)&&put==pick-7)
{
Board[pick+1]=0;
marker(pick+1,2);
return 1;
}
}
if(put!=pick-8&&put!=pick-7&&put!=pick-9)
return 0;
if(put==pick-8)
{
if(Board[pick-8]!=0)
return 0;
}
else if(put==pick-7)
{
if(Board[pick-7]==0||Board[pick-7]<10)
return 0;
}
else if(put==pick-9)
{
if(Board[pick-9]==0||Board[pick-9]<10)
return 0;
}
}
if(put>=0 && put<=7)
{
int piece=0;
setcolor(14);
outtextxy(x+225,y-80,"Enter: ");
outtextxy(x+225,y-60,"1-Queen");
outtextxy(x+225,y-40,"2-Rook");
outtextxy(x+225,y-20,"3-Bishop ");
outtextxy(x+225,y,"4-Knight");
gotoxy(72,17);
cin>>piece;
switch(piece)
{
case 1: Board[put]=7;break;
case 2: Board[put]=5;break;
case 3: Board[put]=3;break;
case 4: Board[put]=2;break;
default: Board[put]=7;break;
}
setcolor(6);
outtextxy(x+225,y-80,"Enter: ");
outtextxy(x+225,y-60,"1-Queen");
outtextxy(x+225,y-40,"2-Rook");
outtextxy(x+225,y-20,"3-Bishop ");
outtextxy(x+225,y,"4-Knight");
setfillstyle(SOLID_FILL,6);
bar(x+225,y,x+300,y+50);
return 2;
}
}
else if(Board[pick]==11)
{
if(pick>=8&&pick<=15)
{
if(put!=pick+8&&put!=pick+16&&put!=pick+7&&put!=pick+9)
return 0;
if(put==pick+16)
{
if( Board[pick+8]!=0 || Board[pick+16]!=0)
return 0;
}
else if(put==pick+8)
{
if(Board[pick+8]!=0)
return 0;
}
else if(put==pick+7)
{
if(Board[pick+7]==0||Board[pick+7]>10)
return 0;
}
else if(put==pick+9)
{
if(Board[pick+9]==0||Board[pick+9]>10)
return 0;
}
}
else if(pick>15)
{
if(pick<=39 && pick>=32)
{
if(pick!=39)
if(previous_move_pick==(pick+17)&&previous_move_put==(pick+1)&&put==pick+9)
{
Board[pick+1]=0;
marker(pick+1,2);
return 1;
}
if(pick!=32)
if(previous_move_pick==(pick+15)&&previous_move_put==(pick-1)&&put==pick+7)
{
Board[pick-1]=0;
marker(pick-1,2);
return 1;
}
}
if(put!=pick+8&&put!=pick+7&&put!=pick+9)
return 0;
if(put==pick+8)
{
if(Board[pick+8]!=0)
return 0;
}
else if(put==pick+7)
{
if(Board[pick+7]==0||Board[pick+7]>10)
return 0;
}
else if(put==pick+9)
{
if(Board[pick+9]==0||Board[pick+9]>10)
return 0;
}
}
if(put>=56 && put<=63)
{
int piece=0;
setcolor(14);
outtextxy(x+225,y-80,"Enter: ");
outtextxy(x+225,y-60,"1-Queen");
outtextxy(x+225,y-40,"2-Rook");
outtextxy(x+225,y-20,"3-Bishop ");
outtextxy(x+225,y,"4-Knight");
gotoxy(72,17);
cin>>piece;
switch(piece)
{
case 1: Board[put]=17;break;
case 2: Board[put]=15;break;
case 3: Board[put]=13;break;
case 4: Board[put]=12;break;
default: Board[put]=17;break;
}
setcolor(6);
outtextxy(x+225,y-80,"Enter: ");
outtextxy(x+225,y-60,"1-Queen");
outtextxy(x+225,y-40,"2-Rook");
outtextxy(x+225,y-20,"3-Bishop ");
outtextxy(x+225,y,"4-Knight");
setfillstyle(SOLID_FILL,6);
bar(x+225,y,x+300,y+50);
return 2;
}
}
else if(Board[pick]==2||Board[pick]==12)
{
if(put!=pick-17&&put!=pick-15&&put!=pick+17&&put!=pick+15&&put!=pick-10&&put!=pick+6&&put!=pick+10&&put!=pick-6)
return 0;
if(pick%8==0)
if(put==pick-17||put==pick+15||put==pick-10||put==pick+6)
return 0;
if(pick%8==1)
if(put==pick-10||put==pick+6)
return 0;
if(pick%8==7)
if(put==pick+17||put==pick-15||put==pick+10||put==pick-6)
return 0;
if(pick%8==6)
if(put==pick+10||put==pick-6)
return 0;
if(pick>=0&&pick<=7)
if(put==pick-17||put==pick-15||put==pick-10||put==pick-6)
return 0;
if(pick>=8&&pick<=15)
if(put==pick-17||put==pick-15)
return 0;
if(pick>=56&&pick<=63)
if(put==pick+17||put==pick+15||put==pick+10||put==pick+6)
return 0;
if(pick>=48&&pick<=55)
if(put==pick+17||put==pick+15)
return 0;
}
if(Board[pick]==3||Board[pick]==13||Board[pick]==17||Board[pick]==7)
{
sx=pick%8;
sy=pick/8;
if(sx>=sy) leftup=sy;
else leftup=sx;
if(sx>=(7-sy)) leftdown=7-sy;
else leftdown=sx;
if((7-sx)>=sy) rightup=sy;
else rightup=7-sx;
if((7-sx)>=(7-sy)) rightdown=7-sy;
else rightdown=7-sx;
for(i=1;i
{
if( put==(pick-9*i) ) return 1;
else if( Board[pick-9*i]!=0) break;
}
for(i=1;i
{
if( put==(pick+7*i) ) return 1;
else if( Board[pick+7*i]!=0) break;
}
for(i=1;i
{
if( put==(pick-7*i) ) return 1;
else if( Board[pick-7*i]!=0) break;
}
for(i=1;i
{
if( put==(pick+9*i) ) return 1;
else if( Board[pick+9*i]!=0) break;
}
if(Board[pick]==3||Board[pick]==13)
return 0;
}
if(Board[pick]==5||Board[pick]==15||Board[pick]==17||Board[pick]==7)
{
sx=pick%8;
sy=pick/8;
up=sy;
down=7-sy;
right=7-sx;
left=sx;
for(i=1;i
{
if( put==(pick-8*i) ) return 1;
else if( Board[pick-8*i]!=0) break;
}
for(i=1;i
{
if( put==(pick+8*i) ) return 1;
else if( Board[pick+8*i]!=0) break;
}
for(i=1;i
{
if( put==(pick-1*i) ) return 1;
else if( Board[pick-1*i]!=0) break;
}
for(i=1;i
{
if( put==(pick+1*i) ) return 1;
else if( Board[pick+1*i]!=0) break;
}
return 0;
}
if(Board[pick]==9||Board[pick]==19)
{
if(pick==60&&put==62)
{
if(Board[61]==0&&Board[62]==0&&Board[63]==5)
{
Board[63]=0;
Board[61]=5;
marker(63,2);
return 1;
}
}
if(pick==60&&put==58)
{
if(Board[59]==0&&Board[58]==0&&Board[57]==0&&Board[56]==5)
{
Board[56]=0;
Board[59]=5;
marker(56,2);
return 1;
}
}
if(pick==4&&put==6)
{
if(Board[5]==0&&Board[6]==0&&Board[7]==15)
{
Board[7]=0;
Board[5]=15;
marker(7,2);
return 1;
}
}
if(pick==4&&put==2)
{
if(Board[3]==0&&Board[2]==0&&Board[1]==0&&Board[0]==15)
{
Board[0]=0;
Board[3]=15;
marker(0,2);
return 1;
}
}
if(pick%8==0)
{
if(put!=pick-8&&put!=pick+8&&put!=pick-7&&put!=pick+9&&put!=pick+1)
return 0;
}
else if((pick+1)%8==0)
{
if(put!=pick-8&&put!=pick+8&&put!=pick-9&&put!=pick+7&&put!=pick-1)
return 0;
}
else if(pick<=6&&pick>=1)
{
if(put!=pick+8&&put!=pick+9&&put!=pick+7&&put!=pick-1&&put!=pick+1)
return 0;
}
else if(pick<=62&&pick>=57)
{
if(put!=pick-8&&put!=pick-9&&put!=pick-7&&put!=pick-1&&put!=pick+1)
return 0;
}
else if(pick==0)
{
if(put!=pick+8&&put!=pick+9&&put!=pick+1)
return 0;
}
else if(pick==7)
{
if(put!=pick+8&&put!=pick+7&&put!=pick-1)
return 0;
}
else if(pick==63)
{
if(put!=pick-8&&put!=pick-9&&put!=pick-1)
return 0;
}
else if(pick==56)
{
if(put!=pick-8&&put!=pick-7&&put!=pick+1)
return 0;
}
else
{
if(put!=pick-8&&put!=pick+8&&put!=pick-9&&put!=pick+7&&put!=pick-1&&put!=pick+9&&put!=pick-7&&put!=pick+1)
return 0;
}
}
return(1);
}
int marker(int position,short what)
{
int Dx,Dy;
switch(position)
{
case 0: Dx=-3; Dy=-3; break; case 1: Dx=-2; Dy=-3; break;
case 2: Dx=-1; Dy=-3; break; case 3: Dx=0; Dy=-3; break;
case 4: Dx=1; Dy=-3; break; case 5: Dx=2; Dy=-3; break;
case 6: Dx=3; Dy=-3; break; case 7: Dx=4; Dy=-3; break;
case 8: Dx=-3; Dy=-2; break; case 9: Dx=-2; Dy=-2; break;
case 10: Dx=-1; Dy=-2; break; case 11: Dx=0; Dy=-2; break;
case 12: Dx=1; Dy=-2; break; case 13: Dx=2; Dy=-2; break;
case 14: Dx=3; Dy=-2; break; case 15: Dx=4; Dy=-2; break;
case 16: Dx=-3; Dy=-1; break; case 17: Dx=-2; Dy=-1; break;
case 18: Dx=-1; Dy=-1; break; case 19: Dx=0; Dy=-1; break;
case 20: Dx=1; Dy=-1; break; case 21: Dx=2; Dy=-1; break;
case 22: Dx=3; Dy=-1; break; case 23: Dx=4; Dy=-1; break;
case 24: Dx=-3; Dy=0; break; case 25: Dx=-2; Dy=0; break;
case 26: Dx=-1; Dy=0; break; case 27: Dx=0; Dy=0; break;
case 28: Dx=1; Dy=0; break; case 29: Dx=2; Dy=0; break;
case 30: Dx=3; Dy=0; break; case 31: Dx=4; Dy=0; break;
case 32: Dx=-3; Dy=1; break; case 33: Dx=-2; Dy=1; break;
case 34: Dx=-1; Dy=1; break; case 35: Dx=0; Dy=1; break;
case 36: Dx=1; Dy=1; break; case 37: Dx=2; Dy=1; break;
case 38: Dx=3; Dy=1; break; case 39: Dx=4; Dy=1; break;
case 40: Dx=-3; Dy=2; break; case 41: Dx=-2; Dy=2; break;
case 42: Dx=-1; Dy=2; break; case 43: Dx=0; Dy=2; break;
case 44: Dx=1; Dy=2; break; case 45: Dx=2; Dy=2; break;
case 46: Dx=3; Dy=2; break; case 47: Dx=4; Dy=2; break;
case 48: Dx=-3; Dy=3; break; case 49: Dx=-2; Dy=3; break;
case 50: Dx=-1; Dy=3; break; case 51: Dx=0; Dy=3; break;
case 52: Dx=1; Dy=3; break; case 53: Dx=2; Dy=3; break;
case 54: Dx=3; Dy=3; break; case 55: Dx=4; Dy=3; break;
case 56: Dx=-3; Dy=4; break; case 57: Dx=-2; Dy=4; break;
case 58: Dx=-1; Dy=4; break; case 59: Dx=0; Dy=4; break;
case 60: Dx=1; Dy=4; break; case 61: Dx=2; Dy=4; break;
case 62: Dx=3; Dy=4; break; case 63: Dx=4; Dy=4; break;
default: gotoxy(3,3); cout<<"Error";break;
}
int x,y;
x=getmaxx()/2+50+50*Dx;
y=getmaxy()/2-50+50*Dy;
if(what==1)
setcolor(7);
else if(what==0)
{
if(Square_Color[position]==1)
setcolor(15);
else if(Square_Color[position]==0)
setcolor(0);
}
else if(what==2)
{
x-=100;
if(Square_Color[position]==1)
setfillstyle(SOLID_FILL,15);
else if(Square_Color[position]==0)
setfillstyle(SOLID_FILL,0);
bar(x,y,x+50,y+50);
return 0;
}
else if(what==3)
{
x-=100;
setcolor(LIGHTRED);
rectangle(x+2,y+2,x+50-2,y+50-2);
return 0;
}
else if(what==4)
{
if(Square_Color[position]==1)
setcolor(15);
else if(Square_Color[position]==0)
setcolor(0);
x-=100;
rectangle(x+2,y+2,x+50-2,y+50-2);
x+=100;
}
rectangle(x-100+1,y+1,x-50-1,y+50-1);
line(x-85,y+1,x-65,y+1);
line(x-85,y+49,x-65,y+49);
line(x-99,y+15,x-99,y+35);
line(x-51,y+15,x-51,y+35);
line(x-85+1,y+1+1,x-65-1,y+1+1);
line(x-85+1,y+49-1,x-65-1,y+49-1);
line(x-99+1,y+15+1,x-99+1,y+35-1);
line(x-51-1,y+15+1,x-51-1,y+35-1);
return 0;
}
void draw_piece(int position)
{
int Dx,Dy;
if(Board[position]!=0)
{
switch(position)
{
case 0: Dx=-3; Dy=-3; break; case 1: Dx=-2; Dy=-3; break;
case 2: Dx=-1; Dy=-3; break; case 3: Dx=0; Dy=-3; break;
case 4: Dx=1; Dy=-3; break; case 5: Dx=2; Dy=-3; break;
case 6: Dx=3; Dy=-3; break; case 7: Dx=4; Dy=-3; break;
case 8: Dx=-3; Dy=-2; break; case 9: Dx=-2; Dy=-2; break;
case 10: Dx=-1; Dy=-2; break; case 11: Dx=0; Dy=-2; break;
case 12: Dx=1; Dy=-2; break; case 13: Dx=2; Dy=-2; break;
case 14: Dx=3; Dy=-2; break; case 15: Dx=4; Dy=-2; break;
case 16: Dx=-3; Dy=-1; break; case 17: Dx=-2; Dy=-1; break;
case 18: Dx=-1; Dy=-1; break; case 19: Dx=0; Dy=-1; break;
case 20: Dx=1; Dy=-1; break; case 21: Dx=2; Dy=-1; break;
case 22: Dx=3; Dy=-1; break; case 23: Dx=4; Dy=-1; break;
case 24: Dx=-3; Dy=0; break; case 25: Dx=-2; Dy=0; break;
case 26: Dx=-1; Dy=0; break; case 27: Dx=0; Dy=0; break;
case 28: Dx=1; Dy=0; break; case 29: Dx=2; Dy=0; break;
case 30: Dx=3; Dy=0; break; case 31: Dx=4; Dy=0; break;
case 32: Dx=-3; Dy=1; break; case 33: Dx=-2; Dy=1; break;
case 34: Dx=-1; Dy=1; break; case 35: Dx=0; Dy=1; break;
case 36: Dx=1; Dy=1; break; case 37: Dx=2; Dy=1; break;
case 38: Dx=3; Dy=1; break; case 39: Dx=4; Dy=1; break;
case 40: Dx=-3; Dy=2; break; case 41: Dx=-2; Dy=2; break;
case 42: Dx=-1; Dy=2; break; case 43: Dx=0; Dy=2; break;
case 44: Dx=1; Dy=2; break; case 45: Dx=2; Dy=2; break;
case 46: Dx=3; Dy=2; break; case 47: Dx=4; Dy=2; break;
case 48: Dx=-3; Dy=3; break; case 49: Dx=-2; Dy=3; break;
case 50: Dx=-1; Dy=3; break; case 51: Dx=0; Dy=3; break;
case 52: Dx=1; Dy=3; break; case 53: Dx=2; Dy=3; break;
case 54: Dx=3; Dy=3; break; case 55: Dx=4; Dy=3; break;
case 56: Dx=-3; Dy=4; break; case 57: Dx=-2; Dy=4; break;
case 58: Dx=-1; Dy=4; break; case 59: Dx=0; Dy=4; break;
case 60: Dx=1; Dy=4; break; case 61: Dx=2; Dy=4; break;
case 62: Dx=3; Dy=4; break; case 63: Dx=4; Dy=4; break;
default: gotoxy(3,3); cout<<"Error";break;
}
switch(Board[position])
{
case 1: pawn(White,Dx,Dy); break;
case 11: pawn(Black,Dx,Dy); break;
case 5: rook(White,Dx,Dy); break;
case 15: rook(Black,Dx,Dy); break;
case 2: knight(White,Dx,Dy); break;
case 12: knight(Black,Dx,Dy); break;
case 3: bishop(White,Dx,Dy); break;
case 13: bishop(Black,Dx,Dy); break;
case 7: queen(White,Dx,Dy); break;
case 17: queen(Black,Dx,Dy); break;
case 9: king(White,Dx,Dy); break;
case 19: king(Black,Dx,Dy); break;
}
}
}
void chessboard()
{
int x,y,i;
x=getmaxx()/2;
y=getmaxy()/2;
/////////////////////////// chess board ////////////////////////
//making board
for(i=0;i<450;i+=50)
{line(x-200+i,y-200,x-200+i,y+200); }
for(i=0;i<450;i+=50)
{line(x-200,y-200+i,x+200,y-200+i); }
setlinestyle(SOLID_LINE,1,3);
//filling color in squares
for(int g=0;g<400;g+=100)
for(int w=0;w<400;w+=100)
{floodfill(x-149+w,y-102+g,15); }
for(g=0;g<400;g+=100)
for(w=0;w<400;w+=100)
{floodfill(x-199+w,y+102-g,15); }
setlinestyle(SOLID_LINE,1,1);
///////////////////////////// chess board completes ////////////////////
}
void bishop(int color,float dx,float dy)
{
float x,y;
x=getmaxx()/2-25+50*dx;
y=getmaxy()/2-10+50*dy;
int col=0;
if(color==0)
col=4;
else if(color==1)
col=1;
setcolor(col);
ellipse(x,y,0,360,12,4);
ellipse(x,y-4,0,360,8,3);
line(x-5,y-4,x-3,y-25);
line(x+5,y-4,x+3,y-25);
ellipse(x,y-25,0,360,8,3);
circle(x,y-28,6);
circle(x,y-35,2);
line(x-3,y-24,x+3,y-24);
setcolor(0);
line(x-5,y-28,x+5,y-28);
line(x-3,y-23,x+3,y-23);
line(x-4,y-7,x+4,y-7);
setfillstyle(SOLID_FILL,col);
floodfill(x,y-36,col);
if(color==0)
setfillstyle(SOLID_FILL,14);
else if(color==1)
setfillstyle(SOLID_FILL,3);
floodfill(x-7,y-25,col);
floodfill(x+7,y-25,col);
floodfill(x,y-23,col);
floodfill(x,y-28,col);
floodfill(x,y-18,col);
floodfill(x,y,col);
setfillstyle(SOLID_FILL,col);
floodfill(x,y-3,col);
floodfill(x-6,y-4,col);
floodfill(x+6,y-4,col);
}
void knight(int color,float dx,float dy)
{
float x,y;
x=getmaxx()/2-25+50*dx;
y=getmaxy()/2-10+50*dy;
int col=0;
if(color==0)
col=4;
else if(color==1)
col=1;
setcolor(col);
ellipse(x,y,0,360,14,4);
ellipse(x,y-4,150,360,9,3);
line(x-7,y-3,x-8,y-12);
line(x-6,y-18,x-8,y-12);
line(x-6,y-18,x-3,y-22);
line(x-6,y-24,x-3,y-22);
line(x-6,y-24,x-11,y-24);
line(x+8,y-3,x+7,y-12);
line(x+6,y-20,x+7,y-12);
line(x+6,y-20,x+7,y-24);
line(x+6,y-30,x+7,y-24);
line(x+6,y-30,x+7,y-34);
line(x+4,y-31,x+7,y-34);
line(x+4,y-32,x-2,y-32);
line(x-4,y-30,x-2,y-32);
line(x-4,y-30,x-8,y-30);
line(x-11,y-29,x-8,y-30);
line(x-11,y-29,x-12,y-27);
line(x-11,y-25,x-12,y-27);
circle(x-2,y-28,1);
setcolor(0);
line(x-6,y-4,x+6,y-4);
if(color==0)
setfillstyle(SOLID_FILL,14);
else if(color==1)
setfillstyle(SOLID_FILL,3);
floodfill(x,y-18,col);
floodfill(x,y,col);
}
void rook(int color,float dx,float dy)
{
float x,y;
x=getmaxx()/2-25+50*dx;
y=getmaxy()/2-10+50*dy;
int col=0;
if(color==0)
col=4;
else if(color==1)
col=1;
setcolor(col);
ellipse(x,y,180,360,13,4);
ellipse(x,y-4,0,360,13,4);
ellipse(x,y-20-2,180,360,10,3);
ellipse(x,y-24-2,0,360,10,3);
line(x-10,y-20-2,x-10,y-24-2);
line(x+10,y-20-2,x+10,y-24-2);
line(x-13,y,x-13,y-4);
line(x+13,y,x+13,y-4);
line(x+7,y-17-2,x+7,y-5);
line(x-7,y-17-2,x-7,y-5);
line(x-10,y-25-2,x-10,y-28-2);
line(x-5,y-27-2,x-5,y-31-2);
line(x-10,y-28-2,x-5,y-31-2);
line(x+10,y-25-2,x+10,y-28-2);
line(x+5,y-27-2,x+5,y-31-2);
line(x+10,y-28-2,x+5,y-31-2);
rectangle(x-4,y-24-2,x+4,y-22-2);
putpixel(x-6,y-27-2,col);
putpixel(x+6,y-27-2,col);
setcolor(0);
line(x-6,y-8,x+6,y-8);
line(x-9,y-25-2,x-6,y-26-2);
line(x+9,y-25-2,x+6,y-26-2);
if(color==0)
setfillstyle(SOLID_FILL,14);
else if(color==1)
setfillstyle(SOLID_FILL,3);
bar(x-3,y-23-2,x+3,y-21-2);
floodfill(x,y-25-2,col);
floodfill(x,y-10,col);
floodfill(x,y+1,col);
floodfill(x,y-21-2,col);
}
void pawn(int color,float dx,float dy)
{
float x,y;
x=getmaxx()/2-25+50*dx;
y=getmaxy()/2-10+50*dy;
int col=0;
if(color==0)
col=4;
else if(color==1)
col=1;
setcolor(col);
ellipse(x,y,0,360,8,2);
ellipse(x,y-3,0,360,6,2);
ellipse(x,y-18,0,360,6,2);
line(x-3,y-5,x-3,y-17);
line(x+3,y-5,x+3,y-17);
circle(x,y-23,4);
setcolor(0);
line(x-2,y-5,x+2,y-5);
line(x-3,y-2,x+3,y-2);
line(x-1,y-20,x+1,y-20);
if(color==0)
setfillstyle(SOLID_FILL,14);
else if(color==1)
setfillstyle(SOLID_FILL,3);
floodfill(x,y,col);
floodfill(x,y-21,col);
floodfill(x,y-18,col);
floodfill(x,y-10,col);
}
void queen(int color,float dx,float dy)
{
int x,y;
x=getmaxx()/2-25+50*dx;
y=getmaxy()/2-10+50*dy;
int col=0;
if(color==0)
col=4;
else if(color==1)
col=1;
setcolor(col);
ellipse(x,y,0,360,18,4);
ellipse(x,y-4,130,45,14,3);
line(x-2,y-5,x-1,y-28);
line(x+2,y-5,x+1,y-28);
line(x-2,y-5,x-9,y-25);
line(x-5,y-5,x-10,y-24);
line(x-4,y-5,x-15,y-16);
line(x-8,y-5,x-16,y-15);
line(x+2,y-5,x+9,y-25);
line(x+5,y-5,x+10,y-24);
line(x+4,y-5,x+15,y-16);
line(x+8,y-5,x+16,y-15);
circle(x,y-32,4);
circle(x-10,y-27,2);
circle(x-18,y-18,2);
circle(x+10,y-27,2);
circle(x+18,y-18,2);
setcolor(0);
line(x-7,y-4,x+7,y-4);
line(x-8,y-3,x-10,y-3);
line(x+8,y-3,x+10,y-3);
if(color==0)
setfillstyle(SOLID_FILL,14);
else if(color==1)
setfillstyle(SOLID_FILL,3);
floodfill(x,y,col);
floodfill(x,y-14,col);
setfillstyle(SOLID_FILL,col);
floodfill(x,y-32,col);
floodfill(x-10,y-27,col);
floodfill(x-18,y-18,col);
floodfill(x+10,y-27,col);
floodfill(x+18,y-18,col);
if(color==0)
setcolor(14);
else if(color==1)
setcolor(3);
circle(x,y-32,4);
circle(x-10,y-27,2);
circle(x-18,y-18,2);
circle(x+10,y-27,2);
circle(x+18,y-18,2);
}
void king(int color,float dx,float dy)
{
float x,y;
x=getmaxx()/2-25+50*dx;
y=getmaxy()/2-10+50*dy;
int col=0;
if(color==0)
col=4;
else if(color==1)
col=1;
setcolor(col);
ellipse(x,y,0,360,18,4);
ellipse(x,y-4,130,45,14,3);
line(x-3,y-10,x,y-16);
line(x+3,y-10,x,y-16);
line(x-3,y-10,x,y-4);
line(x+3,y-10,x,y-4);
line(x-8,y-25,x,y-18);
line(x-8,y-25,x-13,y-27);
line(x-16,y-26,x-13,y-27);
line(x-17,y-25,x-16,y-26);
line(x-17,y-25,x-18,y-20);
line(x-17,y-15,x-18,y-20);
line(x-17,y-15,x-9,y-7);
line(x+8,y-25,x,y-18);
line(x+8,y-25,x+13,y-27);
line(x+16,y-26,x+13,y-27);
line(x+17,y-25,x+16,y-26);
line(x+17,y-25,x+18,y-20);
line(x+17,y-15,x+18,y-20);
line(x+17,y-15,x+9,y-7);
ellipse(x,y-25,0,360,3,5);
line(x,y-30,x,y-37);
line(x-3,y-34,x+3,y-34);
setcolor(0);
line(x-7,y-4,x+7,y-4);
line(x-8,y-3,x-10,y-3);
line(x+8,y-3,x+10,y-3);
if(color==0)
setfillstyle(SOLID_FILL,14);
else if(color==1)
setfillstyle(SOLID_FILL,3);
floodfill(x,y,col);
floodfill(x,y-11,col);
floodfill(x,y-23,col);
setfillstyle(SOLID_FILL,col);
floodfill(x-8,y-11,col);
}
Thursday, May 27, 2010
creating a chess game on C++
12:38 AM
Unknown
0 comments:
Post a Comment