/*-------------------------------tqmain.c--------------------------------*/
#include <bios.h>;
#include <tqminer.c>;
#include <tqcomt.c>;
#include <xpmouse.c>;
int main()
{ int gameres,key;
initGraph(); /*初始化图形显示*/
MouseMath();/*计算鼠标形状,一开始必须使用,后面就不用了*/
MouseSetY(0,479); /*设置鼠标Y坐标范围0-479*/
MouseSetX(0,639); /*设置鼠标X坐标范围0-639*/
MouseSetXY(100,100); /*设置鼠标当前坐标*/
outtextxy(400,400,"XP mouse test!"); /*显示信息*/
settextstyle(0,0,4); /*设置图形下文本显示风格*/
outtextxy(100,200,"XP Mouse Demo");/*显示文本信息*/
MouseOn(MouseX,MouseY);/*第一次显示鼠标*/
do
{
newgame(); /*初始化新游戏,开局*/
gameres=0;
do
{int key;
skiped=0;
sh=0;
while(1){
key = bioskey(1); /*读入操作信息*/
if(key == 0x011b) break;
switch(MouseStatus()){
case 1: /*单击左键选定某一个棋子或者跳到此处*/
MouseOff();
MouseGetXY();
pj=(MouseX-STARTX)/40;
pi=(MouseY-STARTY)/40;
if (pi>=0 && pi<8 && pj>=0 && pj<8)
work(pi,pj);
MouseOn(MouseX,MouseY);
break;
}
if (skiped) break;
}
if(key==0x011b) break;
if (checkwin()) {
gameres=1;
break;}
comturn(); /*电脑搜索路径,判断处理走棋;*/
if (checkwin()) {
gameres=1;
break;}
} while(!gameres);
}while (!confirm(gameres));
return 0;
}
/*---------------------------------tqcomt-------------------------------*/
int kk;
struct chesser{
int allow;
int nowx;
int nowy;
int oldx;
int oldy;
int x1;
int y1;
}beatlocate;
int caneat(int m,int n)
{
if (table[m][n]%10==2 && table[m+1][n+1]/100==1 && table[m+2][n+2]==0 && m+2<8 && n+2<8 ||
table[m][n]%10==2 && table[m+1][n-1]/100==1 && table[m+2][n-2]==0 && m+2<8 && n-2>=0 ||
table[m][n]%10==2 && table[m-1][n-1]/100==1 && table[m-2][n-2]==0 && m-2>=0 && n-2>=0 ||
table[m][n]%10==2 && table[m-1][n+1]/100==1 && table[m-2][n+2]==0 && m-2>=0 && n+2<8)
return 1;
else
if (table[m][n]%10==1 && table[m-1][n-1]/100==1 && table[m-2][n-2]==0 && m-2>=0 && n-2>=0 ||
table[m][n]%10==1 && table[m-1][n+1]/100==1 && table[m-2][n+2]==0 && m-2>=0 && n+2<8)
return 1;
else return 0;
}
int beeaten(int m,int n)
{
if (table[m-1][n-1]/100==1 && table[m+1][n+1]==0 && m-1>=0 && m+1<8 && n-1>=0 && n+1<8)
return 1;
if (table[m-1][n+1]/100==1 && table[m+1][n-1]==0 && m-1>=0 && m+1<8 && n-1>=0 && n+1<8)
return 1;
if (table[m+1][n-1]/100==1 && table[m-1][n+1]==0 && m-1>=0 && m+1<8 && n-1>=0 && n+1<8 && table[m+1][n-1]%10==2)
return 1;
if (table[m+1][n+1]/100==1 && table[m-1][n-1]==0 && m-1>=0 && m+1<8 && n-1>=0 && n+1<8 && table[m+1][n+1]%10==2)
return 1;
return 0;
}
long value(){
int i,j;
long v=0;
for (i=0;i<8;i++)
for (j=0;j<8;j++){
if (table[i][j]/100==2)
v=v+table[i][j]%10*100+100;
if (table[i][j]/100==1)
v=v-(table[i][j]%10*100+100);
}
return v;
}
double search(int depth,int alpha,int beta,int top){
struct chesser{
int allow;
int nowx;
int nowy;
int oldx;
int oldy;
int x1;
int y1;
}sc[100];
int k,v,eat=0,bb=0;
int b=0,b1=0,b2=0;
int i,j,temp,t;
int x[8],y[8],x1[8],y1[8],isallow[8];
if (depth==0){
return value();
}
for (i=0;i<100;i++){
sc[i].allow=0;
sc[i].nowx=0;
sc[i].nowy=0;
sc[i].oldx=0;
sc[i].oldy=0;
sc[i].x1=0;
sc[i].y1=0;
}
k=0;
for (i=0;i<8;i++)
for (j=0;j<8;j++)
if (table[i][j]/100==2) {
eat=0;
for (t=0;t<8;t++) {
x[t]=-1;
x1[t]=0;
isallow[t]=-1;
}
/*四种基本走法*/
if (j-1>=0 && i-1>=0 && table[i-1][j-1]==0) {
x[0]=i-1;
y[0]=j-1;
isallow[0]=0;}
if (j+1<8 && i-1>=0 && table[i-1][j+1]==0) {
x[1]=i-1;
y[1]=j+1;
isallow[1]=0;}
if (j-1>=0 && i+1<8 && table[i+1][j-1]==0) {
x[2]=i+1;
y[2]=j-1;
isallow[2]=0;}
if (j+1<8 && i+1<8 && table[i+1][j+1]==0) {
x[3]=i+1;
y[3]=j+1;
isallow[3]=0;}
if (table[i][j]%10==1)
{ isallow[2]=-1;
isallow[3]=-1;
}
/*加强棋*/
if (table[i+1][j+1]/100==1 && table[i][j]%10==2 && i+2<8 && j+2<8 && table[i+2][j+2]==0) {
x[4]=(i+1)+1;
y[4]=(j+1)+1;
x1[4]=i+1;
y1[4]=j+1;
eat=1;
isallow[4]=1;}
if (table[i+1][j-1]/100==1 && table[i][j]%10==2 && i+2<8 && j-2>=0 && table[i+2][j-2]==0) {
x[5]=(i+1)+1;
y[5]=(j-1)-1;
x1[5]=i+1;
y1[5]=j-1;
eat=1;
isallow[5]=1;}
if (table[i-1][j-1]/100==1 && i-2>=0 && j-2>=0 && table[i-2][j-2]==0) {
x[6]=(i-1)-1;
y[6]=(j-1)-1;
x1[6]=i-1;
y1[6]=j-1;
eat=1;
isallow[6]=1;}
if (table[i-1][j+1]/100==1 && i-2>=0 && j+2<8 && table[i-2][j+2]==0) {
x[7]=(i-1)-1;
y[7]=(j+1)+1;
x1[7]=i-1;
y1[7]=j+1;
eat=1;
isallow[7]=1;}
/*如果有吃子走法,删除没有吃子的其它走法*/
if (eat){
for (t=0;t<8;t++)
if (isallow[t]<=0) x[t]=-10;
}
/*存入Sc(走法表)中*/
for (t=0;t<8;t++)
{
if (x[t]>=0 && x[t]<8 && y[t]<8 && y[t]>=0 && x1[t]>=0 && x1[t]<8 && table[x[t]][y[t]]==0 && isallow[t]>=0)
{ sc[k].oldx=i;
sc[k].oldy=j;
sc[k].nowx=x[t];
sc[k].nowy=y[t];
sc[k].x1=x1[t];
sc[k].y1=y1[t];
if (isallow[t]==1) sc[k].allow=1; /*如果有吃子,则允许此着走法*/
k++;
}
}
if (eat) {i=100;j=100;}
}
/*搜索是否有允许走法,如果没有则所有走法皆允许*/
temp=0;
for (i=0;i<k;i++)
if (sc[i].allow==1) temp=1;
if (temp==0) {
for (i=0;i<k;i++) sc[i].allow=1;
}
i=0;
while (i<k){
v=0;
if (sc[i].allow)
{ b=0;bb=0;
b1=table[sc[i].oldx][sc[i].oldy];/*记录起点棋子和终点棋子*/
b2=table[sc[i].nowx][sc[i].nowy];
if (sc[i].nowx-sc[i].oldx==2 || sc[i].nowx-sc[i].oldx==-2)
bb=1;
if (bb) b=table[sc[i].x1][sc[i].y1]; /*记录被吃子位置的棋子*/
table[sc[i].oldx][sc[i].oldy]=0; /*清除起点的棋子*/
table[sc[i].nowx][sc[i].nowy]=b1; /*试下棋*/
if (bb) table[sc[i].x1][sc[i].y1]=0; /*清除被吃子位置的棋子*/
if (sc[i].nowx==0) table[sc[i].nowx][sc[i].nowy]=202;
}
if (bb>0 && caneat(sc[i].nowx,sc[i].nowy) && beeaten(sc[i].nowx,sc[i].nowy)==0 && top)
v=value()+1000;
else if (bb>0 && caneat(sc[i].nowx,sc[i].nowy) && beeaten(sc[i].nowx,sc[i].nowy) && top)
v=value()+800;
else if (bb>0 && caneat(sc[i].nowx,sc[i].nowy)==0 && beeaten(sc[i].nowx,sc[i].nowy)==0 && top)
v=value()+600;
else if (bb>0 && caneat(sc[i].nowx,sc[i].nowy)==0 && beeaten(sc[i].nowx,sc[i].nowy) && top)
v=value()+400;
else if (bb==0 && beeaten(sc[i].nowx,sc[i].nowy) && top)
v=value()-400;
else v=search(depth-1,-beta,-alpha,0);
if (sc[i].allow) {
if (bb) table[sc[i].x1][sc[i].y1]=b;
table[sc[i].oldx][sc[i].oldy]=b1;
table[sc[i].nowx][sc[i].nowy]=b2;
}
if (v>beta) return v;
if (v>alpha && top){
alpha=v;
beatlocate.oldx=sc[i].oldx;
beatlocate.oldy=sc[i].oldy;
beatlocate.nowx=sc[i].nowx;
beatlocate.nowy=sc[i].nowy;
if (bb) {
beatlocate.x1=sc[i].x1;
beatlocate.y1=sc[i].y1;
}
}
if (v>alpha && top==0) alpha=v;
i++;
}
return alpha;
}
void bestwork(){
int tt;
tt=table[beatlocate.oldx][beatlocate.oldy];
if (beatlocate.nowx-beatlocate.oldx==2 || beatlocate.nowx-beatlocate.oldx==-2)
kk=1;
table[beatlocate.oldx][beatlocate.oldy]=0;
if (kk) table[beatlocate.x1][beatlocate.y1]=0;
if (beatlocate.nowx==0) tt=202;
table[beatlocate.nowx][beatlocate.nowy]=tt;
drawblock(beatlocate.oldx,beatlocate.oldy);
if (kk) drawblock(beatlocate.x1,beatlocate.y1);
drawblock(beatlocate.nowx,beatlocate.nowy);
}
void perform(int i,int j){
if (table[i+1][j+1]/100==1 && table[i][j]%10==2 && i+2<8 && j+2<8) {
beatlocate.oldx=i;
beatlocate.oldy=j;
beatlocate.nowx=i+2;
beatlocate.nowy=j+2;
beatlocate.x1=i+1;
beatlocate.y1=j+1;
}
if (table[i+1][j-1]/100==1 && table[i][j]%10==2 && i+2<8 && j-2>=0) {
beatlocate.oldx=i;
beatlocate.oldy=j;
beatlocate.nowx=i+2;
beatlocate.nowy=j-2;
beatlocate.x1=i+1;
beatlocate.y1=j-1;
}
if (table[i-1][j-1]/100==1 && i-2>=0 && j-2>=0) {
beatlocate.oldx=i;
beatlocate.oldy=j;
beatlocate.nowx=i-2;
beatlocate.nowy=j-2;
beatlocate.x1=i-1;
beatlocate.y1=j-1;
}
if (table[i-1][j+1]/100==1 && i-2>=0 && j+2<8) {
beatlocate.oldx=i;
beatlocate.oldy=j;
beatlocate.nowx=i-2;
beatlocate.nowy=j+2;
beatlocate.x1=i-1;
beatlocate.y1=j+1;
}
}
void comturn(){
beatlocate.allow=0;
beatlocate.nowx=0;
beatlocate.nowy=0;
beatlocate.oldx=0;
beatlocate.oldy=0;
beatlocate.x1=0;
beatlocate.y1=0;
kk=0;
search(4,-30000,30000,1);
bestwork();
while (caneat(beatlocate.nowx,beatlocate.nowy) && kk)
{
perform(beatlocate.nowx,beatlocate.nowy);
bestwork();
}
}
/*----------------------------------tqminer----------------------------------*/
#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define SIZE 40;
/*红子普通棋用101表示,加强棋用102表示
白子普通棋用201表示,加强棋用202表示*/
int table[8][8]; /*桌面并记录每一格状态*/
int STARTX,STARTY;
int pi,pj,qi,qj;
int sh=0,skiped;
void initGraph(){
/* 要求自动检测 */
int gdriver = DETECT, gmode, errorcode;
/* 初始化图形模式 */
initgraph(&gdriver, &gmode, "");
/* 读取初始化结果 */
errorcode = graphresult();
if (errorcode != grOk) /* 发生错误 */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* 具有错误代码的返回 */
}
}
void xychange()
{ int midx,midy;
midx=getmaxx()/2;
midy=getmaxy()/2;
STARTX=midx-8*20;
STARTY=midy-8*20;
}
void drawblock(int i,int j){
int x,y,xx,yy;
int color;
int mx,my;
x=STARTX+j*SIZE;
y=STARTY+i*SIZE;
xx=x+39;
yy=y+39;
color=((i+j)%2==1)?BLACK:WHITE;
setcolor(WHITE);
rectangle(x,y,xx,yy);
setfillstyle(SOLID_FILL,color);
floodfill(x+1,y+1,WHITE);
setcolor(WHITE); line(x,y,xx,y);line(x,y,x,yy);
setcolor(BLACK); line(xx,y,xx,yy);line(x,yy,xx,yy);
if(pi==i && pj==j){
setcolor(RED);
rectangle(x+1,y+1,xx-1,yy-1);
}
else {setcolor(BLACK); rectangle(x+1,y+1,xx-1,yy-1);}
mx=x+2;
my=y+2;
setcolor ((table[i][j]/100==1)?RED:GREEN);
switch(table[i][j]){
case 201:
outtextxy(mx,my,"w");
break;
case 202:
outtextxy(mx,my,"W");
break;
case 101:
outtextxy(mx,my,"r");
break;
case 102:
outtextxy(mx,my,"R");
break;
}
}
void drawtable(){
int i,j;
for (i=0;i<8;i++)
for (j=0;j<8;j++) drawblock(i,j);
}
void drawpiece(){
int i,j;
for (i=0;i<8;i++)
for (j=0;j<8;j++){
table[i][j]=0;
if (i<3 && (i+j)%2==1 )
table[i][j]=101;
if (i>4 && (i+j)%2==1 )
table[i][j]=201;
}
}
/*初始化游戏*/
void newgame(){
cleardevice();
xychange();
drawpiece();
pi = pj = -1;
drawtable();
}
/*判断白方棋子能不能继续走*/
int canmove(int m,int n){
if ((table[m-1][n-1]==0 && m-1>=0 && n-1>=0) || (table[m-1][n+1]==0 && m-1>=0 && n+1<8))
return 1;
if (((table[m+1][n-1]==0 && m+1<8 && n-1>=0) || (table[m+1][n+1]==0 && m+1<8 && n+1<8)) && table[m][n]%10==2)
return 1;
if (table[m-1][n-1]/100==1 && table[m-2][n-2]==0 && m-2>=0 && n-2>=0)
return 1;
if (table[m-1][n+1]/100==1 && table[m-2][n+2]==0 && m-2>=0 && n+2<8)
return 1;
if (table[m+1][n-1]/100==1 && table[m+2][n-2]==0 && m+2<8 && n-2>=0 && table[m][n]%10==2)
return 1;
if (table[m+1][n+1]/100==1 && table[m+2][n+2]==0 && m+2<8 && n+2<8 && table[m][n]%10==2)
return 1;
return 0;
}
/*判断游戏是否胜利*/
int checkwin(){
int i,j,t=1;
for (i=0;i<8;i++)
for (j=0;j<8;j++)
if (table[i][j]/100==2)
if (canmove(i,j))
{
t=0;
break;
}
return t;
}
/*判断游戏是否重新开始*/
int confirm(int res){
char buffer[100];
int kk;
if(res == 1) {
strcpy(buffer,"You win the game , play again (Y/N)?");
}
else if(res == -1){
strcpy(buffer,"You lose the game ,play again (Y/N)?");
}
else {
strcpy(buffer,"Exit game ,play again (Y/N)?");
}
setcolor(WHITE);
outtextxy(0,0,buffer);
kk = bioskey(0);
kk = (kk&0xff);
if(kk == 'Y' || kk == 'y') return 0;
return 1;
}
int can(int m,int n) /*判断红方m,n位置的棋子能不能吃子*/
{
int t=0;
if (table[m][n]%10==1 && table[m][n]/100==1){
if (table[m+1][n-1]/100==2&&table[m+2][n-2]==0&&m+2<8&& n-2>=0
||table[m+1][n+1]/100==2&&table[m+2][n+2]==0&&m+2<8 && n+2 <8)
t=1;
}
if (table[m][n]%10==2 && table[m][n]/100==1 && m+2<8 && m-2>0 && n+2 <8 && n-2>=0 ){
if (table[m-1][n-1]/100==2&&table[m-2][n-2]==0 && m-2>=0 && n-2>=0
||table[m-1][n+1]/100==2&&table[m-2][n+2]==0 && m-2>=0 && n+2>=0
||table[m+1][n-1]/100==2&&table[m+2][n-2]==0 && m+2<8 && n-2>=0
||table[m+1][n+1]/100==2&&table[m+2][n+2]==0 && m+2<8 && n+2 <8)
t=1;
}
return t;
}
int nofront()/*判断有没有子可吃*/
{ int tt=1;
int i,j;
for (i=0;i<8;i++)
for (j=0;j<8;j++)
if (can(i,j)) {
outtextxy(0,0,"skip first");
tt=0;
break;
}
return tt;
}
void work(int m,int n){
if (table[m][n]/100==1) {
drawblock(m,n);
qi=m;
qj=n;
sh=m+n;
}
if (table[m][n]==0 && sh!=0) {
if (m==qi+1 && (n==qj+1 || n==qj-1) )
{table[m][n]=table[qi][qj];
table[qi][qj]=0;
if (m==7) table[m][n]=102;
drawblock(m,n);
drawblock(qi,qj);
}
if (table[qi][qj]%10==2 && m==qi-1 && (n==qj+1 || n==qj-1) )
{table[m][n]=table[qi][qj];
table[qi][qj]=0;
drawblock(m,n);
drawblock(qi,qj);
}
if (m==qi+2 && n==qj+2 && table[m-1][n-1]/100==2)
{table[m][n]=table[qi][qj];
table[qi][qj]=0;
table[m-1][n-1]=0;
if (m==7) table[m][n]=102;
drawblock(m,n);
drawblock(qi,qj);
drawblock(m-1,n-1);
sh=0;
}
if (m==qi+2 && n==qj-2 && table[m-1][n+1]/100==2)
{table[m][n]=table[qi][qj];
table[qi][qj]=0;
table[m-1][n+1]=0;
if (m==7) table[m][n]=102;
drawblock(m,n);
drawblock(qi,qj);
drawblock(m-1,n+1);
sh=0;
}
if (m==qi-2 && n==qj+2 && table[m+1][n-1]/100==2 && table[qi][qj]%10==2)
{table[m][n]=table[qi][qj];
table[qi][qj]=0;
table[m+1][n-1]=0;
drawblock(m,n);
drawblock(qi,qj);
drawblock(m+1,n-1);
sh=0;
}
if (m==qi-2 && n==qj-2 && table[m+1][n+1]/100==2 && table[qi][qj]%10==2)
{table[m][n]=table[qi][qj];
table[qi][qj]=0;
table[m+1][n+1]=0;
drawblock(m,n);
drawblock(qi,qj);
drawblock(m+1,n+1);
sh=0;
}
skiped=1;
}
if (can(m,n) && sh==0) skiped=0;
}
/*----------------------------xpmouse-------------------------*/
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>
int MouseExist; /*鼠标安装状态*/
int MouseButton; /*鼠标按键状态*/
int MouseX; /*鼠标当前水平方向坐标*/
int MouseY; /*鼠标当前垂直方向坐标*/
/*Winxp下INT 33H中断不支持鼠标的显示和关闭,所以要自己编写这两个函数*/
int up[16][16], down[16][16],mouse_draw[16][16],pixel_save[16][16];
void MouseMath()/*鼠标的形状设置*/
{
int i,j,jj,k;
/* 箭头形状*/
long UpNum[16]={
0x3fff,0x1fff,0x0fff,0x07ff,
0x03ff,0x01ff,0x00ff,0x007f,
0x003f,0x00ff,0x01ff,0x10ff,
0x30ff,0xf87f,0xf87f,0xfc3f
};
long DownNum[16]={
0x0000,0x7c00,0x6000,0x7000,
0x7800,0x7c00,0x7e00,0x7f00,
0x7f80,0x7e00,0x7c00,0x4600,
0x0600,0x0300,0x0300,0x0180
};
/*手形*/
/*
unsigned int UpNum[16]={
-7681,-7681,-7681,-7681,
-7681,-8192,-8192,-8192,
0,0,0,0,
0,0,0,0
};
unsigned int DownNum[16]={
7680,4608,4608,4608,
4608,5119,4681,4681,
4681,-28671,-28671,-28671,
-22767,-32767,-32767,-1
};
*/
for(i=0;i<16;i++){
j=jj=15;
while(UpNum[i]!=0){
up[i][j]=UpNum[i]%2;
j--;
UpNum[i]/=2;
}
while(DownNum[i]!=0){
down[i][jj--]=DownNum[i]%2;
DownNum[i]/=2;
}
for(k=j;k>=0;k--)
up[i][k]=0;
for(k=jj;k>=0;k--)
down[i][k]=0;
for(k=0;k<16;k++){/*四种组合方式*/
if(up[i][k]==0&&down[i][k]==0)
mouse_draw[i][k]=1;
else if(up[i][k]==0&&down[i][k]==1)
mouse_draw[i][k]=2;
else if(up[i][k]==1&&down[i][k]==0)
mouse_draw[i][k]=3;
else
mouse_draw[i][k]=4;
}
}
mouse_draw[1][2]=4;/*特殊点*/
}
/*鼠标光标显示*/
void MouseOn(int x,int y)
{
int i,j;
int color;
for(i=0;i<16;i++){/*画鼠标*/
for(j=0;j<16;j++) {
pixel_save[i][j]=getpixel(x+j,y+i);/*保存原来的颜色*/
if(mouse_draw[i][j]==1)
putpixel(x+j,y+i,0);
else if(mouse_draw[i][j]==2)
putpixel(x+j,y+i,15);
}
}
}
/*隐藏鼠标*/
void MouseOff()
{
int i,j,x,y,color;
x=MouseX;
y=MouseY;
for(i=0;i<16;i++)/*原位置异或消去*/
for(j=0;j<16;j++){
if(mouse_draw[i][j]==3||mouse_draw[i][j]==4)
continue;
color=getpixel(x+j,y+i);
putpixel(x+j,y+i,color^color);
putpixel(x+j,y+i,pixel_save[i][j]);
}
}
/*鼠标是否加载
MouseExist:1=加载
0=未加载
MouseButton:鼠标按键数目
*/
void MouseLoad()
{
_AX=0x00;
geninterrupt(0x33);
MouseExist=_AX;
MouseButton=_BX;
}
/*鼠标状态值初始化*/
void MouseReset()
{
_AX=0x00;
geninterrupt(0x33);
}
/*设置鼠标左右边界
lx:左边界
rx:右边界
*/
void MouseSetX(int lx,int rx)
{
_CX=lx;
_DX=rx;
_AX=0x07;
geninterrupt(0x33);
}
/*设置鼠标上下边界
uy:上边界
dy:下边界
*/
void MouseSetY(int uy,int dy)
{
_CX=uy;
_DX=dy;
_AX=0x08;
geninterrupt(0x33);
}
/*设置鼠标当前位置
x:横向坐标
y:纵向坐标
*/
void MouseSetXY(int x,int y)
{
_CX=x;
_DX=y;
_AX=0x04;
geninterrupt(0x33);
}
/*设置鼠标速度(缺省值:vx=8,vy=1)
值越大速度越慢
*/
void MouseSpeed(int vx,int vy)
{
_CX=vx;
_DX=vy;
_AX=0x0f;
geninterrupt(0x33);
}
/*获取鼠标按下键的信息
是否按下左键
返回值: 1=按下 0=释放
*/
int LeftPress()
{
_AX=0x03;
geninterrupt(0x33);
return(_BX&1);
}
/*是否按下中键
返回值同上
*/
int MiddlePress()
{
_AX=0x03;
geninterrupt(0x33);
return(_BX&4);
}
/*是否按下右键
返回值同上
*/
int RightPress()
{
_AX=0x03;
geninterrupt(0x33);
return(_BX&2);
}
/*获取鼠标当前位置*/
void MouseGetXY()
{
_AX=0x03;
geninterrupt(0x33);
MouseX=_CX;
MouseY=_DX;
}
int MouseStatus()/*鼠标按键情况*/
{
int x,y;
int status;
int press=0;
int i,j,color;
status=0;/*默认鼠标没有移动*/
x=MouseX;
y=MouseY;
while(x==MouseX&&y==MouseY&&status==0&&press==0&&!kbhit()){
if(LeftPress())
press=1;
MouseGetXY();
if(MouseX!=x||MouseY!=y)
status=1;
}
if(status){/*移动情况才重新显示鼠标*/
for(i=0;i<16;i++)/*原位置异或消去*/
for(j=0;j<16;j++){
if(mouse_draw[i][j]==3||mouse_draw[i][j]==4)
continue;
color=getpixel(x+j,y+i);
putpixel(x+j,y+i,color^color);
putpixel(x+j,y+i,pixel_save[i][j]);
}
MouseOn(MouseX,MouseY);/*新位置显示*/
}
if(press!=0)/*有按键的情况*/
return press;
return 0;/*只移动的情况*/
}
此程序为一网络VB程序改编而来,仅供在TC下学习使用,算法研究方面可以参考国际象棋等棋类游戏。
win7请在dosbox下操作,详细google之