该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include #include #include
/*---------------------------常量定义--------------------------------*/#define XWIDTH 160 /*每个柱子占据的水平宽度*/#define XHEIGHT 300 /*所有柱子的高度*/
/*全局场景的矩形*/#define BLEFT (300-XWIDTH*3/2-20)#define BRIGHT (300+XWIDTH*3/2+20)#define BTOP 50#define BBOTTOM (BTOP+XHEIGHT+40)/*每个柱子的中心所在横坐标*/#define POLE_CXA (300-XWIDTH)#define POLE_CXB 300#define POLE_CXC (300+XWIDTH)
#define POLE_BOTTOM (BTOP+XHEIGHT) /*所有柱子的水平面坐标*/#define POLE_TOP (BTOP+100) /*所有柱子的顶部坐标*/#define POLE_THICK 12 /*柱子厚度*/
/*绘制圆饼的参数*/#define DISK_THICK 10 /*圆盘厚度*/#define DISK_MINWIDTH (POLE_THICK+12) /*最小的圆盘宽度*/#define DISK_MAXWIDTH (XWIDTH-20) /*最大的圆盘宽度*/#define DISK_INCSIZE 10 /*圆盘宽度增长值*/#define DISK_MAXCOUNT 10 /*最大圆盘数*/#define DISK_GAP 1 /*相邻圆盘的垂直距离间隔*/#define DISK_FLYHEIGHT (POLE_TOP - (DISK_THICK)*3) /*圆盘的飞行高度*//*延时的参数*/#define DELAY_COUNT 1600 /*绘制时,delay()的参数*//*颜色定义*/#define COLOR_POLE BLACK /*Pole颜色*/#define COLOR_POLEBORDER LIGHTGRAY /*Pole边框颜色*/#define COLOR_BKGND DARKGRAY /*背景颜色*/#define COLOR_DISK YELLOW /*圆盘的填充色*/
#define BGI_PATH "" /*驱动路径*/
/*圆盘信息结构*/typedef struct tagDISK{ int cx; /*中心坐标cx*/ int y; /*上边缘cy*/ int halfwidth; /*宽度的一半*/ int atPole; /*它位于哪一个Pole上,hanoi2要用到这个信息*/ void *pImage; /*缓存的背景*/} DISK, *PDISK;
/*---------------------------全局变量--------------------------------*/int PoleCx[3]; /*记录每一个Pole的中心坐标*/int DiskCount[3]; /*记录每一个POLE上面当前的圆盘数量*/int DiskNo[DISK_MAXCOUNT][3]; /*记录每一个Pole上面的圆盘的索引*/PDISK Disks[DISK_MAXCOUNT]; /*所有圆盘的指针*/
/*---------------------------函数声明--------------------------------*/DISK* NewDisk(int cx1, int y1, int width1);void DeleteDisk(DISK* disk);void RecorverBkGnd(DISK *disk);void DrawDisk(DISK *disk, int cx1, int y1);int GetNextDiskTop(int count);void textout(int x, int y, char* text, int color, int bordercolor);void textoutwithborder(int x, int y, char* text, int color, int bordercolor);void Init(int n);void Quit(int n);void MoveDisk(int from, int to);void Hanoi(int n, int from, int to, int aux);void Hanoi2(int n, int d);int main(int argc,char *argv[]);