#include<graphics.h>
![]()
#include"dos.h"
![]()
#include "stdio.h"
![]()
#include "alloc.h"
![]()
int num1,num2,num3,h0,cy[66];
![]()
void plot1(int ,int ,int ,int );
![]()
void move(char getone,char putone)
![]()
![]() { int x0=40,x,y,w,h,tx,ty,tw,th,x1,x2,y1,y2,xm1,ym1,xm2,ym2;
![]()
int i,n,size;
![]()
void *buffer,*buffer1;
![]()
switch(getone)
![]()
![]() {
![]()
case 'A':num1--;break;
![]()
case 'B':num2--;break;
![]()
case 'C':num3--;break;
![]()
default: exit(0);
![]()
}
![]()
switch(putone)
![]()
![]() {
![]()
case 'A':num1++;break;
![]()
case 'B':num2++;break;
![]()
case 'C':num3++;break;
![]()
default: exit(0);
![]()
}
![]()
switch(getone)
![]()
![]() {
![]()
case 'A':x=120;y1=cy[num1+1]-h0;break;
![]()
case 'B':x=320;y1=cy[num2+1]-h0;break;
![]()
case 'C':x=520;y1=cy[num3+1]-h0;break;
![]()
default: exit(0);
![]()
}
![]()
switch(putone)
![]()
![]() {
![]()
case 'A':tx=120-50;ty=cy[num1]-h0;break;
![]()
case 'B':tx=320-50;ty=cy[num2]-h0;break;
![]()
case 'C':tx=520-50;ty=cy[num3]-h0;break;
![]()
default: exit(0);
![]()
}
![]()
x1=x-50;
![]()
x2=x+50;
![]()
y2=y1+h0;
![]()
xm1=(x1+tx)/2;
![]()
ym1=(y1+ty)/2;
![]()
xm2=xm1+100;
![]()
ym2=ym1+h0;
![]()
![]()
size=imagesize(x1,y1,x2,y2);
![]()
buffer=malloc(size);
![]()
getimage(x1,y1,x2,y2,buffer);
![]()
setfillstyle(SOLID_FILL,3);
![]()
bar(x1,y1,x2,y2);
![]()
setcolor(YELLOW);
![]()
line((x1+x2)/2,y1,(x1+x2)/2,y2);
![]()
buffer1=malloc(size);
![]()
n=abs(tx-x1);
![]()
for(i=0;i<n;i+=3)
![]()
![]() {
![]()
xm1=x1+(float)(tx-x1)/n*i;
![]()
ym1=y1+(float)(ty-y1)/(tx-x1)*(xm1-x1);
![]()
xm2=xm1+100;
![]()
ym2=ym1+h0;
![]()
getimage(xm1,ym1,xm2,ym2,buffer1);
![]()
![]() putimage(xm1,ym1,buffer,COPY_PUT);/**//* delay(10); */
![]()
putimage(xm1,ym1,buffer1,COPY_PUT);
![]()
}
![]()
![]() putimage(tx,ty,buffer,COPY_PUT);/**//* delay(50);*/
![]()
![]()
free(buffer1);
![]()
free(buffer);
![]()
![]()
}
![]()
![]()
void hanoi(int n,char one,char two,char three)
![]()
![]() {
![]()
if(n==1) move(one,three);
![]()
else
![]()
![]() {
![]()
hanoi(n-1,one,three,two);
![]()
move(one,three);
![]()
hanoi(n-1,two,one,three);
![]()
}
![]()
}
![]()
main()
![]()
![]() {
![]()
int gdriver,gmode,x0=40,y0=400,x1,x2,x3,y1,y2,y3,x,y,w0=100;
![]()
![]()
int i,num,w,w1;
![]()
printf("Please input the number of plate(<=64):");
![]()
scanf("%d",&num);
![]()
if(num>65)
![]()
![]() {printf ("number great than 64 ",exit(0));}
![]()
h0=(y0-80)/num;
![]()
w1=(100-10)/num;
![]()
num1=num;
![]()
num2=0;
![]()
num3=0;
![]()
gdriver=DETECT;
![]()
initgraph(&gdriver,&gmode,"");
![]()
setfillstyle(SOLID_FILL,3);
![]()
bar(0,0,640,480);
![]()
![]() setcolor(15); /**//* white */
![]()
line(1,1,637,1);
![]()
line(1,1,1,477);
![]()
line(0,0,638,0);
![]()
line(0,0,0,478);
![]()
![]() setcolor(8); /**//*darkgray */
![]()
line(638,2,638,478);
![]()
line(639,1,639,479);
![]()
line(632,380,632,472);
![]()
![]() setcolor(14); /**//* yellow */
![]()
line(x0,401,640-x0,401);
![]()
line(x0+80,40,x0+80,400);
![]()
line(x0+280,40,x0+280,400);
![]()
line(x0+480,40,x0+480,400);
![]()
x1=x0+80;
![]()
x2=x0+280;
![]()
x3=x0+480;
![]()
for(x=x1,y=y0,w=w0,i=1;i<=num;i++,y=y-h0-1,w=w-w1)
![]()
![]() {
![]()
plot1(x,y,w,h0);
![]()
cy[i]=y;
![]()
}
![]()
setcolor(14);
![]()
line(x0+80,40,x0+80,400);
![]()
getch();
![]()
hanoi(num,'A','B','C');
![]()
getch();
![]()
![]()
}
![]()
void plot1(int x,int y,int w,int h)
![]()
![]() {int x1,x2,y1,y2,xc,yc,a,b;
![]()
x1=x-w/2;
![]()
x2=x+w/2;
![]()
y1=y-h;
![]()
y2=y;
![]()
xc=(x1+x2)/2;
![]()
yc=(y1+y2)/2;
![]()
a=w/2;
![]()
b=h/2;
![]()
setfillstyle(SOLID_FILL,14);
![]()
![]() /**//* bar(x1,y1,x2,y2); */
![]()
![]() setcolor(14); /**//* yellow */
![]()
setlinestyle(0,0,1);
![]()
ellipse(xc,yc,0,360,a,b);
![]()
floodfill(xc-2,yc,YELLOW);
![]()
floodfill(xc+2,yc,YELLOW);
![]()
setcolor(1);
![]()
ellipse(xc,yc,0,360,a,b);
![]()
ellipse(xc,yc,0,360,a-3,b-3);
![]()
setfillstyle(SOLID_FILL,12);
![]()
floodfill(xc-2,yc+b-2,BLUE);
![]()
floodfill(xc+2,yc+b-3,BLUE);
![]()
![]() /**//* line(x1,y1,x1,y2);
![]()
line(x1,y2,x2,y2);
![]()
line(x2,y2,x2,y1);
![]()
line(x2,y1,x1,y1);
![]()
*/
![]()
}
![]()
![]()
|