- 注册时间
- 2004-11-26
- 最后登录
- 1970-1-1
|
- #define PAN_X 8
- #define PAN_Y 8
- #define PAN_COLOR 175+16
- #define BLOCK_COLOR 0x10
- #define ACT_COLOR 0x10
- #define DING_COLOR 0x14
- char g_digit[2][10][8*16];
- char pan[11][16];
- char pan_flag[11][16];
- char x_pan[11][16];
- char y_pan[11][16];
- char z_pan[11][16];
- void init_digit()
- {
- int i;
- char s[2];
-
- SetBgColor(PAN_COLOR);
- SetFgColor(ACT_COLOR);
- s[1]=0;
- for (i=0;i<10;i++) {
- if (i==0) s[0]=' ';
- else s[0]=i+'0';
- TextOut(0,0,s,0x81);
- GetBlock(0,2,8,12,0x40,g_digit[0][i]);
- }
- SetFgColor(DING_COLOR);
- for (i=0;i<10;i++) {
- if (i==0) s[0]=' ';
- else s[0]=i+'0';
- TextOut(0,0,s,0x81);
- GetBlock(0,2,8,12,0x40,g_digit[1][i]);
- }
- }
- void draw_pan()
- {
- int i;
- SetBgColor(PAN_COLOR);
- SetFgColor(BLOCK_COLOR);
- Block(PAN_X,PAN_Y,PAN_X+143,PAN_Y+143,0);
- for (i=0;i<10;i++) {
- Line(PAN_X,PAN_Y+(i<<4),PAN_X+144,PAN_Y+(i<<4),1);
- Line(PAN_X+(i<<4),PAN_Y,PAN_X+(i<<4),PAN_Y+144,1);
- }
- for (i=0;i<=144;i=i+48) {
- Line(PAN_X,PAN_Y-1+i,PAN_X+144,PAN_Y-1+i,1);
- Line(PAN_X,PAN_Y+1+i,PAN_X+144,PAN_Y+1+i,1);
- Line(PAN_X-1+i,PAN_Y,PAN_X-1+i,PAN_Y+144,1);
- Line(PAN_X+1+i,PAN_Y,PAN_X+1+i,PAN_Y+144,1);
- }
- }
- void draw_num()
- {
- int i,j;
-
- for (i=1;i<=9;i++) {
- for (j=1;j<=9;j++) {
- WriteBlock(PAN_X-16+5+(j<<4),PAN_Y-16+3+(i<<4),8,12,1,g_digit[pan_flag[i][j]][pan[i][j]]);
- }
- }
- }
- void pan_init()
- {
- memset(pan,0,sizeof(pan));
- memset(pan_flag,0,sizeof(pan_flag));
- }
- void set_xyz()
- {
- int x,y,z,t;
-
- memset(x_pan,0,sizeof(x_pan));
- memset(y_pan,0,sizeof(y_pan));
- memset(z_pan,0,sizeof(z_pan));
- for (y=1;y<=9;y++) {
- for (x=1;x<=9;x++) {
- t=pan[y][x];
- if (t) {
- z=(x-1)/3+(y-1)/3*3+1;
- x_pan[y][t]=1;
- y_pan[x][t]=1;
- z_pan[z][t]=1;
- }
- }
- }
- }
- void sudu_jie()
- {
- int x,y,z,t,t_bak;
- x=1;
- y=1;
- for (;;) {
- if (pan_flag[y][x]) { //数字已固定
- x++;
- if (x>9) {
- x=1;
- y++;
- if (y>9) break;
- }
- continue;
- }
- z=(x-1)/3+(y-1)/3*3+1;
- t_bak=pan[y][x];
- t=t_bak+1;
- xxx2:
- pan[y][x]=t;
- if (t>9) {
- pan[y][x]=0;
- if (t_bak) {
- x_pan[y][t_bak]=0;
- y_pan[x][t_bak]=0;
- z_pan[z][t_bak]=0;
- }
- xxx:
- x--;
- if (x<1) {
- x=9;
- y--;
- if (y<1) break;
- }
- if (pan_flag[y][x]) goto xxx;
- continue;
- }
- if (x_pan[y][t]) {
- t++;
- goto xxx2;
- }
- if (y_pan[x][t]) {
- t++;
- goto xxx2;
- }
- if (z_pan[z][t]) {
- t++;
- goto xxx2;
- }
- if (t_bak) {
- x_pan[y][t_bak]=0;
- y_pan[x][t_bak]=0;
- z_pan[z][t_bak]=0;
- }
- x_pan[y][t]=1;
- y_pan[x][t]=1;
- z_pan[z][t]=1;
- x++;
- if (x>9) {
- x=1;
- y++;
- if (y>9) break;
- }
- }
- }
- void main()
- {
- long t;
- init_digit();
-
- pan_init();
- set_xyz();
- sudu_jie();
- SetBgColor(0xec);
- ClearScreen();
- draw_pan();
- draw_num();
- Refresh();
- getchar();
- }
复制代码 |
|