1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
#include<graphics.h>
#include<stdio.h>
class Piece{
public:
Piece();
int move(int,int);
void setx(int);
void sety(int);
private:
int xvalue;
int yvalue;
};
Piece::Piece(){
xvalue=yvalue=0;
}
void Piece::setx(int xval){
xvalue=xval;
}
void Piece::sety(int yval){
yvalue=yval;
}
void board(){
clrscr();
int x=50;
int y=30;
for (int i=0;i<10;i++){
x=50;
for (int p=0;p<6;p++){
rectangle(x,y,x+40,y+40);
x=x+40;
}
y=y+40;
}
outtextxy(65,10,"1 2 3 4 5 6");
outtextxy(35,50,"1");
outtextxy(35,90,"2");
outtextxy(35,130,"3");
outtextxy(35,170,"4");
outtextxy(35,210,"5");
outtextxy(35,250,"6");
outtextxy(35,290,"7");
outtextxy(35,330,"8");
outtextxy(35,370,"9");
outtextxy(25,410,"10");
}
void main(){
Piece white[12];
Piece red[12];
int gd=DETECT,gm,error;
initgraph(&gd,&gm,"C:\TC\BGI");
error=graphresult();
if (error != grOk){
cout<<"There was an error of "<<grapherrormsg(error);
getch();
exit(1);
}
board();
int key=0;
int posx=70;
int posy=50;
do{
key=getch();
board();
setfillstyle(SOLID_FILL,1);
if ((key==77)&&(posx<270)){
posx=posx+40;
circle(posx,posy,5);
}else if ((key==75)&&(posx>70)){
posx=posx-40;
circle(posx,posy,5);
}else if ((key==72)&&(posy>50)){
posy=posy-40;
circle(posx,posy,5);
}else if ((key==80)&&(posy<410)){
posy=posy+40;
circle(posx,posy,5);
}
}while (key!=13);
clrscr();
board();
setfillstyle(SOLID_FILL,RED);
circle(posx,posy,15);
getch();
closegraph();
}
|