//清除 void Clear() { for (int i = 1; i < 10; i++) { for (int j = 1; j < 10; j++) { if (SUDOK[i][j].isok) { ClearRow(i, SUDOK[i][j].result); ClearCol(j, SUDOK[i][j].result); ClearAra(i, j, SUDOK[i][j].result); } } } }
void EditColor() { extern const char *configfile; int i, done = 0, okay = 0; long code, qual, class; register struct Gadget *gd, *dgad; register struct Window *nw; register struct IntuiMessage *imsg; register struct PropInfo *pip; register struct Screen *scrn; long aidx; int msx, msy; int curcol = 0, drag = 0; int bxorx, bxory, bxxlen, bxylen; static UWORD colors[AMII_MAXCOLORS]; static UWORD svcolors[AMII_MAXCOLORS]; static int once = 0; scrn = HackScreen; if (!once) { if (WINVERS_AMIV) { Col_NewWindowStructure1.Width += 300; Col_NewWindowStructure1.Height += 20; Col_NewWindowStructure1.LeftEdge -= 150; Col_BluePen.Width += 300; Col_RedPen.Width += 300; Col_GreenPen.Width += 300; Col_Cancel.LeftEdge += 300; Col_Okay.LeftEdge += 150; Col_Cancel.TopEdge += 20; Col_Save.TopEdge += 20; Col_Okay.TopEdge += 20; } SetBorder(&Col_Okay); SetBorder(&Col_Cancel); SetBorder(&Col_Save); once = 1; } bxylen = Col_NewWindowStructure1.Height - (Col_BluePen.TopEdge + Col_BluePen.Height + 6); bxxlen = Col_BluePen.Width; bxorx = Col_BluePen.LeftEdge; bxory = Col_BluePen.TopEdge + Col_BluePen.Height + 2; /* Save the current colors */ for (i = 0; i < amii_numcolors; ++i) svcolors[i] = colors[i] = GetRGB4(scrn->ViewPort.ColorMap, i); Col_NewWindowStructure1.Screen = scrn; #ifdef INTUI_NEW_LOOK if (IntuitionBase->LibNode.lib_Version >= 37) { ((struct PropInfo *) Col_BluePen.SpecialInfo)->Flags |= PROPNEWLOOK; ((struct PropInfo *) Col_RedPen.SpecialInfo)->Flags |= PROPNEWLOOK; ((struct PropInfo *) Col_GreenPen.SpecialInfo)->Flags |= PROPNEWLOOK; } #endif if (WINVERS_AMIV || WINVERS_AMII) { #ifdef INTUI_NEW_LOOK Col_NewWindowStructure1.Extension = wintags; Col_NewWindowStructure1.Flags |= WFLG_NW_EXTENDED; #ifdef __GNUC__ fillhook.h_Entry = (void *) &LayerFillHook; #else fillhook.h_Entry = (ULONG (*) ()) LayerFillHook; #endif fillhook.h_Data = (void *) -2; fillhook.h_SubEntry = 0; #endif } nw = OpenWindow((void *) &Col_NewWindowStructure1); if (nw == NULL) { DisplayBeep(NULL); return; } PrintIText(nw->RPort, &Col_IntuiTextList1, 0, 0); ClearCol(nw); DrawCol(nw, curcol, colors); while (!done) { WaitPort(nw->UserPort); while (imsg = (struct IntuiMessage *) GetMsg(nw->UserPort)) { gd = (struct Gadget *) imsg->IAddress; code = imsg->Code; class = imsg->Class; qual = imsg->Qualifier; msx = imsg->MouseX; msy = imsg->MouseY; ReplyMsg((struct Message *) imsg); switch (class) { case VANILLAKEY: if (code == 'v' && qual == AMIGALEFT) okay = done = 1; else if (code == 'b' && qual == AMIGALEFT) okay = 0, done = 1; else if (code == 'o' || code == 'O') okay = done = 1; else if (code == 'c' || code == 'C') okay = 0, done = 1; break; case CLOSEWINDOW: done = 1; break; case GADGETUP: drag = 0; if (gd->GadgetID == GADREDPEN || gd->GadgetID == GADBLUEPEN || gd->GadgetID == GADGREENPEN) { pip = (struct PropInfo *) gd->SpecialInfo; aidx = pip->HorizPot / (MAXPOT / 15); if (gd->GadgetID == GADREDPEN) { colors[curcol] = (colors[curcol] & ~0xf00) | (aidx << 8); LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); } else if (gd->GadgetID == GADBLUEPEN) { colors[curcol] = (colors[curcol] & ~0xf) | aidx; LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); } else if (gd->GadgetID == GADGREENPEN) { colors[curcol] = (colors[curcol] & ~0x0f0) | (aidx << 4); LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); } DispCol(nw, curcol, colors); } else if (gd->GadgetID == GADCOLOKAY) { done = 1; okay = 1; } else if (gd->GadgetID == GADCOLSAVE) { FILE *fp, *nfp; char buf[300], nname[300], oname[300]; int once = 0; fp = fopen(configfile, "r"); if (!fp) { pline("can't find NetHack.cnf"); break; } strcpy(oname, dirname((char *) configfile)); if (oname[strlen(oname) - 1] != ':') { sprintf(nname, "%s/New_NetHack.cnf", oname); strcat(oname, "/"); strcat(oname, "Old_NetHack.cnf"); } else { sprintf(nname, "%sNew_NetHack.cnf", oname); strcat(oname, "Old_NetHack.cnf"); } nfp = fopen(nname, "w"); if (!nfp) { pline("can't write to New_NetHack.cnf"); fclose(fp); break; } while (fgets(buf, sizeof(buf), fp)) { if (strncmp(buf, "PENS=", 5) == 0) { once = 1; fputs("PENS=", nfp); for (i = 0; i < amii_numcolors; ++i) { fprintf(nfp, "%03x", colors[i]); if ((i + 1) < amii_numcolors) putc('/', nfp); } putc('\n', nfp); } else { fputs(buf, nfp); } } /* If none in the file yet, now write it */ if (!once) { fputs("PENS=", nfp); for (i = 0; i < amii_numcolors; ++i) { fprintf(nfp, "%03x", colors[i]); if ((i + 1) < amii_numcolors) putc(',', nfp); } putc('\n', nfp); } fclose(fp); fclose(nfp); unlink(oname); if (filecopy((char *) configfile, oname) == 0) if (filecopy(nname, (char *) configfile) == 0) unlink(nname); done = 1; okay = 1; } else if (gd->GadgetID == GADCOLCANCEL) { done = 1; okay = 0; } break; case GADGETDOWN: drag = 1; dgad = gd; break; case MOUSEMOVE: if (!drag) break; pip = (struct PropInfo *) dgad->SpecialInfo; aidx = pip->HorizPot / (MAXPOT / 15); if (dgad->GadgetID == GADREDPEN) { colors[curcol] = (colors[curcol] & ~0xf00) | (aidx << 8); LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); } else if (dgad->GadgetID == GADBLUEPEN) { colors[curcol] = (colors[curcol] & ~0xf) | aidx; LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); } else if (dgad->GadgetID == GADGREENPEN) { colors[curcol] = (colors[curcol] & ~0x0f0) | (aidx << 4); LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); } DispCol(nw, curcol, colors); break; case MOUSEBUTTONS: if (code == SELECTDOWN) { if (msy > bxory && msy < bxory + bxylen - 1 && msx > bxorx && msx < bxorx + bxxlen - 1) { curcol = (msx - bxorx) / (bxxlen / amii_numcolors); if (curcol >= 0 && curcol < amii_numcolors) DrawCol(nw, curcol, colors); } } break; } } } if (okay) { for (i = 0; i < (amii_numcolors); ++i) sysflags.amii_curmap[i] = colors[i]; LoadRGB4(&scrn->ViewPort, sysflags.amii_curmap, amii_numcolors); } else LoadRGB4(&scrn->ViewPort, svcolors, amii_numcolors); CloseWindow(nw); }
//检查 void Check() { for (int i = 1; i < 10; i++) { for (int k = 1; k < 10; k++) { int flag = 0; int last[2]; for (int j = 1; j < 10; j++) { if (SUDOK[i][j].isok && SUDOK[i][j].result == k) { flag = 0; break; } if (!SUDOK[i][j].isok && SUDOK[i][j].number[k] == k) { flag++; last[0] = i; last[1] = j; } } if (flag == 1) comp(last[0], last[1], k); } } for (int j = 1; j < 10; j++) { for (int k = 1; k < 10; k++) { int flag = 0; int last[2]; for (int i = 1; i < 10; i++) { if (SUDOK[i][j].isok && SUDOK[i][j].result == k) { flag = 0; break; } if (!SUDOK[i][j].isok && SUDOK[i][j].number[k] == k) { flag++; last[0] = i; last[1] = j; } } if (flag == 1) comp(last[0], last[1], k); } } //九个宫格循环i,j for (int i = 1; i < 10; i += 3) { for (int j = 1; j < 10; j += 3) { //尝试每个数字k for (int k = 1; k < 10; k++) { int flag = 0; int last[2]; int first[2]; bool b_first = false; //宫内循环m,n for (int m = i - (i - 1) % 3; m < i - (i - 1) % 3 + 3; m++) { for (int n = j - (j - 1) % 3; n < j - (j - 1) % 3 + 3; n++) { if (SUDOK[m][n].isok && SUDOK[m][n].result == k) goto end; if (!SUDOK[m][n].isok && SUDOK[m][n].number[k] == k) { flag++; if (b_first) { first[0] = m; first[1] = n; b_first = false; } last[0] = m; last[1] = n; } } } if (flag == 1) comp(last[0], last[1], k); //检查两个数字 if (flag == 2) { if (last[0] == first[0]) { SUDOK[first[0]][first[1]].isok = true; SUDOK[first[0]][last[1]].isok = true; ClearRow(first[0], k); SUDOK[first[0]][first[1]].isok = false; SUDOK[first[0]][last[1]].isok = false; } if (last[1] == first[1]) { SUDOK[first[0]][first[1]].isok = true; SUDOK[last[0]][first[1]].isok = true; ClearCol(first[1], k); SUDOK[first[0]][first[1]].isok = false; SUDOK[last[0]][first[1]].isok = false; } } } end:; } } }