📄 lianp.c
字号:
char KeyPress(void)
{
char keyp=0;
union REGS regs0;
regs0.h.ah=1;
int86(0x16,®s0,®s0);
if((regs0.x.flags & 0x0040)==0)
{
regs0.h.ah=0;
int86(0x16,®s0,®s0);
keyp=regs0.h.al;
KeyScan=regs0.h.ah;
}
return(keyp);
}
void OpenBmpFile(void)
{
char FileName[20];
strcpy(FileName,BMP_FILE);
fp = fopen(FileName,"rb"); /* open for read, bit mode */
if ( fp == NULL)
{ printf("\nFile %s open fail...\n",FileName);
getch();
exit(1);
}
}
void GetFileInfo(void)
{
int i;
unsigned char ch1,ch2,ch3,ch4;
fseek(fp,0,SEEK_SET);
ch1 = fgetc(fp);
ch2 = fgetc(fp);
if(ch1!=0x42||ch2!=0x4d) /* must be 0x42,0x4d = 'BM' */
{
printf("\nFile format error, must be BMP file\n");
getch();
exit(2);
}
fseek(fp,0x0a,SEEK_SET);
ch1 = fgetc(fp);
ch2 = fgetc(fp);
ch3 = fgetc(fp);
ch4 = fgetc(fp);
FileHead.bfOffBits = ch1+ch2*0x100L+ch3*0x10000L+ch4*0x1000000L;
fseek(fp,0x12,SEEK_SET);
ch1 = fgetc(fp);
ch2 = fgetc(fp);
ch3 = fgetc(fp);
ch4 = fgetc(fp);
InfoHead.biWidth = ch1+ch2*0x100L+ch3*0x10000L+ch4*0x1000000L;
fseek(fp,0x16,SEEK_SET);
ch1 = fgetc(fp);
ch2 = fgetc(fp);
ch3 = fgetc(fp);
ch4 = fgetc(fp);
InfoHead.biHeight = ch1+ch2*0x100L+ch3*0x10000L+ch4*0x1000000L;
/* FileHead.bfOffBits = 0x76;
InfoHead.biWidth = 0x29f;
InfoHead.biHeight = 0x1df; */
fseek(fp,0x1c,SEEK_SET);
ch1 = fgetc(fp);
ch2 = fgetc(fp);
if(ch1!=0x04||ch2!=0x00) /* must be 4 */
{
printf("\nFile format error, must be 16 colors (4 bits) BMP file\n");
getch();
exit(3);
}
InfoHead.biBitCount = 4;
DataSizePerLine = (InfoHead.biWidth*InfoHead.biBitCount+31)/8;
DataSizePerLine= (DataSizePerLine/4)*4;
OneLine = malloc(DataSizePerLine);
for(i=0;i<DataSizePerLine;i++) OneLine[i]=0;
}
void GetUnit(void)
{
int read_from_x,read_from_y;
int read_to_x,read_to_y;
int ix,iy,ux,uy;
long FileLocation;
unsigned char ch;
read_from_y = START_FROM_Y + (unity-1)*UNIT_HIGH_ALL + HIGH_FROM + UNIT_HIGH - 1;
read_to_y = START_FROM_Y + (unity-1)*UNIT_HIGH_ALL + HIGH_FROM;
read_from_x = START_FROM_X + (unitx-1)*UNIT_WIDE_ALL + WIDE_FROM;
read_to_x = START_FROM_X + (unitx-1)*UNIT_WIDE_ALL + WIDE_FROM + UNIT_WIDE - 1;
for(iy=read_from_y,uy=0;iy>=read_to_y;iy--,uy++)
{
FileLocation = FileHead.bfOffBits + DataSizePerLine*(InfoHead.biHeight-1-iy);
fseek(fp,FileLocation,SEEK_SET);
fread(OneLine,DataSizePerLine,1,fp);
for(ix=read_from_x,ux=0;ix<=read_to_x;ix++,ux++)
{
ch = OneLine[ix/2];
if(ix%2) OneUnit[uy][ux] = ch&0x0f; /* it is odd, exp: 17 */
else OneUnit[uy][ux] = (ch&0xf0)>>4;
}
} /* of iy */
}
int ColorConvert(int ccolor)
/*
表3 有关屏幕颜色的符号常数表
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
符号常数 数值 含义 符号常数 数值 含义
───────────────────────────────────
BLACK 0 黑色 DARKGRAY 8 深灰
BLUE 1 兰色 LIGHTBLUE 9 深兰
GREEN 2 绿色 LIGHTGREEN 10 淡绿
CYAN 3 青色 LIGHTCYAN 11 淡青
RED 4 红色 LIGHTRED 12 淡红
MAGENTA 5 洋红 LIGHTMAGENTA 13 淡洋红
BROWN 6 棕色 YELLOW 14 黄色
LIGHTGRAY 7 淡灰 WHITE 15 白色
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
*/
{
switch(ccolor)
{
case 0: return(0);
case 1: return(4);
case 2: return(2);
case 3: return(6);
case 4: return(1);
case 5: return(5);
case 6: return(3);
case 7: return(8);
case 8: return(7);
case 9: return(12);
case 10: return(10);
case 11: return(14);
case 12: return(9);
case 13: return(13);
case 14: return(11);
case 15: return(15);
}
}
void CopyChar(unsigned char *to_unit, unsigned char *from_unit)
{
int i;
for(i=0;i<OneUnitSize;i++)
to_unit[i] = from_unit[i];
}
int CompareChar(unsigned char *unit1, unsigned char *unit2)
/* compare two unit
return 1: unit is same
return 0: not same */
{
int i;
int SameCounter;
SameCounter=0;
for(i=0;i<OneUnitSize;i++)
if(unit1[i]==unit2[i]) SameCounter++;
if(SameCounter>=OneUnitSize*SAME_PERCENT) return(1);
else return(0);
}
void MatrixConvert(void)
{
int x,y;
unsigned char ch;
for(y=1;y<=MAX_UNIT_Y;y++)
for(x=1;x<=MAX_UNIT_X;x++)
{
ch = matrix[x][y];
if(ch==EMPTY_CHAR) matrix[x][y] = 0; /* it ts empty */
else
{
if(ch>=0&&ch<=9) ch = ch+'0';
else if(ch<=35) ch = ch-10+'a';
else if(ch<=61) ch = ch-36+'A';
else if(ch<=76) ch = ch-62+33;
else ch = FILL_CHAR;
matrix[x][y] = ch;
} /* of not empty */
}
}
void InitialGraph(void)
{
int gdriver=DETECT, gmode, errorcode;
registerbgidriver(EGAVGA_driver); /* 如果没有这句话,编译出来的exe程序只能在有tc2的机器里面运行 */
/*
Turbo C对于用initgraph()函数直接进行的图形初始化程序, 在编译和链接
时并没有将相应的驱动程序(*.BGI)装入到执行程序, 当程序进行到intitgraph()
语句时, 再从该函数中第三个形式参数char *path中所规定的路径中去找相应的
驱动程序。若没有驱动程序, 则在C:\TC中去找, 如C:\TC中仍没有或TC不存在,
将会出现错误:
BGI Error: Graphics not initialized (use 'initgraph')
因此, 为了使用方便, 应该建立一个不需要驱动程序就能独立运行的可执行
图形程序,Turbo C中规定用下述步骤(这里以EGA、VGA显示器为例):
1. 在C:\TC子目录下输入命令:BGIOBJ EGAVGA
此命令将驱动程序EGAVGA.BGI转换成EGAVGA.OBJ的目标文件。
2. 在C:\TC子目录下输入命令:TLIB LIB\GRAPHICS.LIB+EGAVGA
此命令的意思是将EGAVGA.OBJ的目标模块装到GRAPHICS.LIB库文件中。
3. 在程序中initgraph()函数调用之前加上一句:
registerbgidriver(EGAVGA_driver):
该函数告诉连接程序在连接时把EGAVGA的驱动程序装入到用户的执行程序中。
经过上面处理,编译链接后的执行程序可在任何目录或其它兼容机上运行。
*/
initgraph(&gdriver, &gmode, "d:\\tools\\tc2");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
}
void ClearMsgLine(void)
{
setfillstyle(EMPTY_FILL,0); /* fill with black */
bar(DRAW_START_X,DRAW_MSG_Y,600,DRAW_MSG_Y+20);
}
int GetCharNum(void)
/* input: unitx, unity
output: the location of char in Char.List */
{
char ch;
ch = matrix[unitx][unity];
if(ch==0) return(EMPTY_CHAR); /* it ts empty */
if(ch>='0'&&ch<='9') ch = ch-'0';
else if(ch>='a'&&ch<='z') ch = ch+10-'a';
else if(ch>='A'&&ch<='Z') ch = ch+36-'A';
else ch = MAX_CHAR+1; /* impossible, will draw a special block */
return(ch);
}
void MatrixSave(void)
{
char FileName[20];
FILE *fp;
int xxx,yyy;
char ch;
strcpy(FileName,MATRIX_FILE);
fp = fopen(FileName,"wa"); /* creat for write */
if ( fp == NULL)
{ gotoxy(1,SCREEN_Y-1);
printf("File %s creat fail...",FileName);
getch();
exit(1);
}
for(yyy=1;yyy<=MAX_Y;yyy++)
{
for(xxx=1;xxx<=MAX_X;xxx++)
{
ch = matrix[xxx][yyy];
if(!ch) ch=SPACE;
fputc(ch,fp);
}
fputc('\n',fp);
}
fclose(fp);
}
void MatrixLoad(void)
{
char FileName[20];
FILE *fp;
int xxx,yyy;
char ch;
strcpy(FileName,MATRIX_FILE);
fp = fopen(FileName,"ra"); /* open for read */
if ( fp == NULL)
{ gotoxy(1,SCREEN_Y-1);
printf("File %s open fail...",FileName);
getch();
exit(1);
}
for(yyy=1;yyy<=MAX_Y;yyy++)
{
for(xxx=1;xxx<=MAX_X;xxx++)
{
ch = fgetc(fp);
if(ch=='\n') ch = fgetc(fp);
if(ch==SPACE) ch = 0;
if(ch<32||ch>=127) ch = 0;
matrix[xxx][yyy]=ch;
}
}
fclose(fp);
}
int IsMatrixEmpty(void)
{
int xxx,yyy;
for(xxx=1;xxx<=MAX_X;xxx++)
{
for(yyy=1;yyy<=MAX_Y;yyy++)
{
if(matrix[xxx][yyy]) return(0);
}
}
return(1);
}
int IsMatrixDie(void)
{
int save1x,save1y,save2x,save2y;
if(IsMatrixEmpty()) return(0);
save1x = selected1x;
save1y = selected1y;
save2x = selected2x;
save2y = selected2y;
FindLinkPair();
selected1x = save1x;
selected1y = save1y;
selected2x = save2x;
selected2y = save2y;
if(LinkType) return(0);
else return(1);
}
void ClearSelectBank(void)
{
int ibank;
for(ibank=0;ibank<MAX_BANK;ibank++)
{
SelectBank[ibank].x1 = 0;
SelectBank[ibank].y1 = 0;
SelectBank[ibank].x2 = 0;
SelectBank[ibank].y2 = 0;
SelectBank[ibank].type = LINK_NONE;
SelectBank[ibank].xy2 = 0;
}
}
int SameSelected(void)
{
int ibank;
for(ibank=0;ibank<BankCounter;ibank++)
{
if(SelectBank[ibank].x1==selected2x&&SelectBank[ibank].y1==selected2y
&&SelectBank[ibank].x2==selected1x&&SelectBank[ibank].y2==selected1y) return(1);
}
return(0);
}
/* ================================================= */
/* IQ function */
/* ================================================= */
void IsLink0p1(void)
{
int i;
for(i=selected1y+1;i<=selected2y-1;i++)
if(matrix[selected1x][i]!=0) return;
LinkType = LINK_0P1;
}
void IsLink0p2(void)
{
int i;
for(i=selected1x+1;i<=selected2x-1;i++)
if(matrix[i][selected1y]!=0) return;
LinkType = LINK_0P2;
}
/* ------------------- */
void IsLink1p31(void)
{
int i;
for(i=selected1x+1;i<=selected2x;i++)
if(matrix[i][selected1y]!=0) return;
for(i=selected1y+1;i<=selected2y-1;i++)
if(matrix[selected2x][i]!=0) return;
LinkType = LINK_1P31;
}
void IsLink1p32(void)
{
int i;
for(i=selected1y+1;i<=selected2y;i++)
if(matrix[selected1x][i]!=0) return;
for(i=selected1x+1;i<=selected2x-1;i++)
if(matrix[i][selected2y]!=0) return;
LinkType = LINK_1P32;
}
void IsLink1p41(void)
{
int i;
for(i=selected1y-1;i>=selected2y;i--)
if(matrix[selected1x][i]!=0) return;
for(i=selected1x+1;i<=selected2x-1;i++)
if(matrix[i][selected2y]!=0) return;
LinkType = LINK_1P41;
}
void IsLink1p42(void)
{
int i;
for(i=selected1x+1;i<=selected2x;i++)
if(matrix[i][selected1y]!=0) return;
for(i=selected1y-1;i>=selected2y+1;i--)
if(matrix[selected2x][i]!=0) return;
LinkType = LINK_1P42;
}
/* ------------------- */
void IsLink21p21(void)
{
int ix,iy,tryy;
int tryok;
if(selected1y<=selected2y) tryy=selected1y-1;
else tryy=selected2y-1; /* this is a important check */
for(;tryy>=0;tryy--)
/* there are many link path with different tryy */
{
tryok = 1;
/* check the path go up */
for(iy=selected1y-1;iy>=tryy;iy--)
if(matrix[selected1x][iy]!=0)
if(iy>0) tryok = 0;
/* else tryy <= 0, outside matrix, always can link */
/* check the go right path */
if(tryok)
{
for(ix=selected1x+1;ix<=selected2x-1;ix++)
if(matrix[ix][tryy]!=0)
if(tryy>0) tryok = 0;
/* else tryy <= 0, outside matrix, always can link */
}
else continue; /* if ---> path is no ok, goto next tryx */
/* check the go down path */
if(tryok)
{
for(iy=tryy;iy<=selected2y-1;iy++)
if(matrix[selected2x][iy]!=0)
if(iy>0) tryok = 0;
/* else tryy <= 0, outside matrix, always can link */
}
else continue; /* if ---> path is no ok, goto next tryx */
if(tryok)
{
type2xy = tryy;
LinkType = LINK_21P21;
break; /* do not need to try next one */
}
} /* of tryy */
}
void IsLink21p22(void)
{
int ix,iy,tryy;
int tryok;
if(selected1y>=selected2y) tryy=selected1y+1;
else tryy=selected2y+1; /* this is a important check */
for(;tryy<=MAX_Y+1;tryy++)
/* there are many link path with different tryy */
{
tryok = 1;
/* check the path go down */
for(iy=selected1y+1;iy<=tryy;iy++)
if(matrix[selected1x][iy]!=0)
if(iy<=MAX_Y) tryok = 0;
/* else tryy > MAX Y, outside matrix, always can link */
/* check the go right path */
if(tryok)
{
for(ix=selected1x+1;ix<=selected2x-1;ix++)
if(matrix[ix][tryy]!=0)
if(tryy<=MAX_Y) tryok = 0;
/* else tryy > MAX Y, outside matrix, always can link */
}
else continue; /* if ---> path is no ok, goto next tryx */
/* check the go up path */
if(tryok)
{
for(iy=tryy;iy>=selected2y+1;iy--)
if(matrix[selected2x][iy]!=0)
if(iy<=MAX_Y) tryok = 0;
/* else tryy > MAX Y, outside matrix, always can link */
}
else continue; /* if ---> path is no ok, goto next tryx */
if(tryok)
{
type2xy = tryy;
LinkType = LINK_21P22;
break; /* do not need to try next one */
}
} /* of tryy */
}
void IsLink21p11(void)
{
int ix,iy,tryx;
int tryok;
for(tryx=selected1x-1;tryx>=0;tryx--)
/* there are many link path with different tryx */
{
tryok = 1;
/* check the path left down */
for(ix=selected1x-1;ix>=tryx;ix--)
if(matrix[ix][selected1y]!=0)
if(ix>0) tryok = 0;
/* else ix<=0, outside matrix, always can link */
/* check the go down path */
if(tryok)
{
for(iy=selected1y+1;iy<=selected2y-1;iy++)
if(matrix[tryx][iy]!=0)
if(tryx>0) tryok = 0;
/* else tryx<=0, outside matrix, always can link */
}
else continue; /* if <--- path is no ok, goto next tryx */
/* check the go right path */
if(tryok)
{
for(ix=tryx;ix<=selected2x-1;ix++)
if(matrix[ix][selected2y]!=0)
if(ix>0) tryok = 0;
/* else ix<=0, outside matrix, always can link */
}
else continue; /* if down path is no ok, goto next tryx */
if(tryok)
{
type2xy = tryx;
LinkType = LINK_21P11;
break; /* do not need to try next one */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -