论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > C语言程序设计教程
Tag:新手,函数,指针,数据类型,对象,Turbo,入门,运算符,数组,结构,二级,,tc,游戏,试题,问答,编译,视频教程

2人五子棋游戏(2)

文章类别:C语言程序设计 | 发表日期:2008-9-24 14:46:49

*/
int inputbox(int x,int y,int lenth,int high,int color,char *title,char *text,char *info,int pass)
{
  void *buffer;
  int mx,my,mkey,size,cch,chcount=0;
  char ch[2]={NULL};
  int chin=0;
  closemouse();
  size=imagesize(x,y,x+lenth,y+high);
  buffer=malloc(size);
  getimage(x,y,x+lenth,y+high,buffer);
  cwin(x,y,lenth,high,color,1);
  strout(x+4,y+2,WHITE,title);
  popbutt(x+lenth/2-60-20,y+high-40,60,25,LIGHTGRAY,1);
  setcolor(DARKGRAY);
  strout(x+lenth/2-60-20,y+high-40+4,DARKGRAY," 确  定 ");
  popbutt(x+lenth/2+20,y+high-40,60,25,LIGHTGRAY,1);
  setcolor(DARKGRAY);
  strout(x+lenth/2+20,y+high-40+4,DARKGRAY," 取  消 ");
  if(text!=NULL){
  strout(x+4,y+25,DARKGRAY,text);}
  stbar(x+10,y+50,lenth-20,20,WHITE,1);
  cch=0;
  openmouse();
  setcolor(DARKGRAY);
  line(x+10+2,y+50+18,x+10+2+8,y+50+18);
  while((*ch=bioskey(0))!=0x0d){
        line(x+10+2,y+50+18,x+10+2+8+cch+8,y+50+18);
        if(chcount==255) break;
        if(x+10+3+cch>=x+lenth-20-8){
       stbar(x+10,y+50,lenth-20,20,WHITE,1);
       cch=0;
       continue;

       }
        if(*ch==8&&cch>0) {
       cch=cch-9;
       bar(x+10+3+cch,y+50+7,x+10+3+cch+9,y+50+7+9);
       *info--=NULL;
       *info=NULL;
       setcolor(WHITE);
       line(x+10+2,y+50+18,x+10+2+cch+28,y+50+18);
       setcolor(DARKGRAY);
       line(x+10+2+cch,y+50+18,x+10+2+8+cch,y+50+18);
       continue;
      }


        *info++=*ch;
/*   汉字处理,有问题...

    if(*ch<='a'&&*ch>='z'||*ch<='A'&&*ch>='Z'||*ch<='0'&&*ch>='9')
    {
         ++chin;
         if(chin==2){
         strout(x+10+cch,y+50,DARKGRAY,info-3);
         cch=cch+18;
         chcount++;
         chcount++;
         chin=0;
         continue;
         }
        continue;
   }

*/
        if(pass!=1)
    outtextxy(x+10+3+cch,y+50+7,ch);
        else  outtextxy(x+10+3+cch,y+50+7,"*");
        cch=cch+9;
        chcount++;
     setcolor(WHITE);
     line(x+10+2,y+50+18,x+10+2+cch,y+50+18);
     setcolor(DARKGRAY);
  }
 for(;;){
  readmouse(&mx,&my,&mkey);
      if(mx>=x+lenth/2-60-20&&mx<=x+lenth/2-60-20+60&&my>=y+high-40&&my<=y+high-40+25){
   closemouse();
   pushbutt(x+lenth/2-60-20,y+high-40,60,25,LIGHTGRAY,1);
   setcolor(DARKGRAY);
          strout(x+lenth/2-60-20,y+high-40+4,DARKGRAY," 确  定 ");
          putimage(x,y,buffer,COPY_PUT);
   free(buffer);
   openmouse();
   return 1;
 }
       if(mx>=x+lenth/2+20&&mx<=x+lenth/2+20+60&&my>=y+high-40&&my<=y+high-40+25){
    closemouse();
    pushbutt(x+lenth/2+20,y+high-40,60,25,LIGHTGRAY,1);
    setcolor(DARKGRAY);
    strout(x+lenth/2+20,y+high-40+4,DARKGRAY," 取  消 ");
           putimage(x,y,buffer,COPY_PUT);
    free(buffer);
    openmouse();
    return 2;
 }
    if(mx>=x+lenth-18&&mx<=x+lenth-18+10&&my>=y+3&&my<=y+15)
 {  closemouse();
    putimage(x,y,buffer,COPY_PUT);
    free(buffer);
    openmouse();
    return 2;
  }
     }
}
/*  字符串输出,可输出汉字
    入口参数:  x,y   =输出字符位置
        col   =字符颜色
        *hz   =字符串指针
    出口参数:无

*/

void strout(int x,int y,int col,char *hz)
{
  long offset1;
  int i,j,k,p,x1,y1;
  char *s=hz;
  unsigned char dot[16][2];
  char ch[2]={NULL};
  x1=x;
  y1=y;
  while(*s)
    { if(*s==0x20) {x1=x1+8;++s;continue;}
      if(*s>='a'&&*s<='z'||*s>='A'&&*s<='Z'||*s>='0'&&*s<'||*s=='['||*s==']'">='9'||*s=='!'||*s=='@'||*s=='+'||*s=='-'||*s=='*'||*s=='/'||*s==','||*s=='.'||*s=='?'||*s=='<'||*s=='>'||*s=='['||*s==']') goto keychar;
      if(*s=='\('||*s=='\)'||*s=='\\'||*s=='&'||*s=='^'||*s=='%'||*s=='$'||*s=='#'||*s=='@'||*s=='`'||*s=='~'||*s=='|'||*s=='='||*s=='_'||*s=='{'||*s=='}'||*s=='\''||*s=='"'||*s==';'||*s==':') goto keychar;
       goto chinese;
  keychar: ch[0]=*s;
   setcolor(col);
   outtextxy(x1,y1+5,ch);
   x1=x1+10;
   ++s;
   continue;

chinese:      offset1=(long)((*s+95)*94+(*(s+1)+95))*32;
      fseek(fp,offset1,SEEK_SET);
      for(i=0;i<16;i++)
       {
  y=y1+i;
   for(j=0;j<2;j++)
     {
       x=x1+8*j;
       dot[i][j]=fgetc(fp);
       p=0x80;
   for(k=0;k<8;k++)
      {
        if(dot[i][j]&p)
        putpixel(x+k,y,col);
        p=p>>1;
      }
   }
    }
     x1=x+8;
     s=s+2;
    }
 }

/* 写白棋子 */

void fillwhite(int x1,int y1)
{
  setfillstyle(1,WHITE);  /*write white chessman*/
  setcolor(WHITE);
  circle(x1,y1,7);
  floodfill(x1,y1,WHITE);
}
/*  写黑棋子 */

void fillblack(int x1,int y1)
{
 setfillstyle(1,14); /*write black chessman*/
 setcolor(14);
 circle(x1,y1,7);
 floodfill(x1,y1,14);
}
/* 产生棋盘 */
void clearboard()
{
 int x,y;
 popbutt(112,32,416,416,BLUE,3);
 setcolor(BROWN);
 setfillstyle(1,BROWN);
 bar(120,40,520,440);
 rectangle(116,36,524,444);
 setcolor(GREEN);
 for(y=56;y<440;y+=16)
   line(120,y,520,y);
  for(x=136;x<520;x+=16)
     line(x,40,x,440);
}


/* 人机大战函数
   算法要重新生成........
*/

void computer()
{  int newx,newy,mbutt,row,lnewx,lnewy,writeflag,firstflag;
 newgame:
   finish=0;
  messbox(200,150,250,150,GREEN,"第一颗棋子的位置","你可以选择当前状态下的按钮,以\n决定谁先下第一颗棋子!",1);
  for(;;){
  openmouse();
  readmouse(&newx,&newy,&mbutt);
  if (mbutt==1){
  if(newx>=560&&newx<=610&&newy>=230&&newy<=248)
  {  firstflag=1;
     closemouse();
     pushbutt(560,230,50,18,7,1);
     strout(566,231,8,"玩 家");
     popbutt(560,260,50,18,7,1);
     strout(566,261,8,"电 脑");
     break;
  }
  if(newx>=560&&newx<=610&&newy>=260&&newy<=278)
   {  firstflag=2;
      closemouse();
      popbutt(560,230,50,18,7,1);
      strout(566,231,8,"玩 家");
      pushbutt(560,260,50,18,7,1);
      strout(566,261,8,"电 脑");
     break;
   }
   }
}
   if(firstflag==2) goto comfirst;
   while(1){
     writeflag=0;
     if(finish==1) {
      openmouse();
      readmouse(&newx,&newy,&mbutt);
      checkbut(newx,newy,mbutt);
      continue;
      }
     openmouse();  /* display cursor */
     readmouse(&newx,&newy,&mbutt);
   if(mbutt==2)
   { int i;
     closemouse();
     setfillstyle(1,BROWN);
     bar(lnewx-8,lnewy-8,lnewx+8,lnewy+8);
     setcolor( GREEN);
     line(lnewx-8,lnewy,lnewx+8,lnewy);
     line(lnewx,lnewy-8,lnewx,lnewy+8);
     setfillstyle(1,BROWN);
     bar(mmx-8,mmy-8,mmx+8,mmy+8);
     setcolor(GREEN);
     line(mmx-8,mmy,mmx+8,mmy);
     line(mmx,mmy-8,mmx,mmy+8);
      for(i=200;i<2000;i+=500);
 {sound(i);
  delay(500);
 }
      nosound();
     continue;
   }
     checkbut(newx,newy,mbutt);

     if(gameflag==1) {clearboard;return;}
     if(newx<135||newx>505||newy<55||newy>425||getpixel(newx,newy)==WHITE||getpixel(newx,newy)==BLACK){
          continue;
         }
     for(row=0;row<24;++row){
     if(newx>carrayx[row]) continue;
 else if((carrayx[row]-newx)<6){
        newx=carrayx[row];
        goto newyy;
        }
 else if((newx-carrayx[row-1])<6) {
        newx=carrayx[row-1];
        goto newyy;
       }
     if(newx<carrayx[row]) break;
     }
     goto nonxy;
     newyy:
     for(row=0;row<24;++row){
 if(newy>carrayy[row]) continue;
 else if((carrayy[row]-newy)<6){
                newy=carrayy[row];
   goto dispxy;
   }
 else if((newy-carrayy[row-1])<6){
      newy=carrayy[row-1];
      goto dispxy;
      }
     if(newy<carrayy[row]) break;
     }
 goto nonxy;
 dispxy:
 if(getpixel(newx,newy)==15||getpixel(newx,newy)==14) goto nonxy;
 lnewx=newx;
 lnewy=newy;
 if(mbutt==1){
   closemouse(); /* close cursor */
   if(pbut==0){
  fillwhite(newx,newy);
  delay(1500);
  }
   else{
  fillblack(newx,newy);
  delay(1500);
 }
    popbutt(560,230,50,18,7,1);
    strout(566,231,8,"玩 家");
    pushbutt(560,260,50,18,7,1);
    strout(566,261,8,"电 脑");

   goto machine;
 }
goto nonxy;

/* 电脑运算 */

machine:
{  int ustatus[4]={0,0,0,0};
   int mstatus[4]={0,0,0,0};
   int x,y,i,uline,mline,curx,cury,ok=0;
   if(finish==1) continue;
   for(y=0;y<24;++y)
      for(x=0;x<24;++x)
  for(i=0;i<4;++i){
  userb[y][x][i]=0;
  machb[y][x][i]=0;
  }
   for(y=0;y<24;++y)
 for(x=0;x<24;++x){
   curx=136+x*16;
   cury=56+y*16;
   if(getpixel(curx,cury)==ucol) {
        userb[y][x][0]=scanchess(curx,cury,1,ucol)+scanchess(curx,cury,5,ucol)+1;
        userb[y][x][1]=scanchess(curx,cury,2,ucol)+scanchess(curx,cury,6,ucol)+1;
        userb[y][x][2]=scanchess(curx,cury,3,ucol)+scanchess(curx,cury,7,ucol)+1;
        userb[y][x][3]=scanchess(curx,cury,4,ucol)+scanchess(curx,cury,8,ucol)+1;
        }
   if(getpixel(curx,cury)==mcol){
  machb[y][x][0]=scanchess(curx,cury,1,mcol)+scanchess(curx,cury,5,mcol)+1;
  machb[y][x][1]=scanchess(curx,cury,2,mcol)+scanchess(curx,cury,6,mcol)+1;
  machb[y][x][2]=scanchess(curx,cury,3,mcol)+scanchess(curx,cury,7,mcol)+1;
  machb[y][x][3]=scanchess(curx,cury,4,mcol)+scanchess(curx,cury,8,mcol)+1;
   }
  }

  mline=machb[0][0][0];
  for(y=0;y<24;++y)
      for(x=0;x<24;++x)
  for(i=0;i<4;++i){
  if(mline<machb[y][x][i]) {
     mmx=136+x*16;
     mmy=56+y*16;
   /* if(i==0&&boundans(mmx,mmy,1,mcol)==1&&boundans(mmx,mmy,5,mcol)==1)  ok=1;
    if(i==1&&boundans(mmx,mmy,2,mcol)==1&&boundans(mmx,mmy,6,mcol)==1)  ok=1;
    if(i==2&&boundans(mmx,mmy,3,mcol)==1&&boundans(mmx,mmy,7,mcol)==1)  ok=1;
    if(i==3&&boundans(mmx,mmy,4,mcol)==1&&boundans(mmx,mmy,8,mcol)==1)  ok=1;
     if(ok==1){ */
     mstatus[0]=machb[y][x][0];
     mstatus[1]=machb[y][x][1];
     mstatus[2]=machb[y][x][2];
     mstatus[3]=machb[y][x][3];
     mline=machb[y][x][i];

     }
  }

/*  if(ok==0){
    mline=machb[0][0][0];
  for(y=0;y<24;++y)
      for(x=0;x<24;++x)
  for(i=0;i<4;++i){
  if(mline<machb[y][x][i]) {
     mmx=136+x*16;
     mmy=56+y*16;
    if(i==0&&boundans(mmx,mmy,1,mcol)==1||boundans(mmx,mmy,5,mcol)==1)  ok=1;
    if(i==1&&boundans(mmx,mmy,2,mcol)==1||boundans(mmx,mmy,6,mcol)==1)  ok=1;
    if(i==2&&boundans(mmx,mmy,3,mcol)==1||boundans(mmx,mmy,7,mcol)==1)  ok=1;
    if(i==3&&boundans(mmx,mmy,4,mcol)==1||boundans(mmx,mmy,8,mcol)==1)  ok=1;
     if(ok==1){
     mstatus[0]=machb[y][x][0];
     mstatus[1]=machb[y][x][1];
     mstatus[2]=machb[y][x][2];
     mstatus[3]=machb[y][x][3];
     mline=machb[y][x][i]; }

     }
  }
 }

*/
  uline=userb[0][0][0];
  for(y=0;y<24;++y)
      for(x=0;x<24;++x)
  for(i=0;i<4;++i){
  if(uline<userb[y][x][i]) {
     newx=136+x*16;
     newy=56+y*16;
     ustatus[0]=userb[y][x][0];
     ustatus[1]=userb[y][x][1];
     ustatus[2]=userb[y][x][2];
     ustatus[3]=userb[y][x][3];
     uline=userb[y][x][i];
     }
  }
   pushbutt(560,230,50,18,7,1);
   strout(566,231,8,"玩 家");
   popbutt(560,260,50,18,7,1);
   strout(566,261,8,"电 脑");
  uline=ustatus[0];
  for(i=1;i<4;++i)
   if(uline<ustatus[i]) uline=ustatus[i];
   if (uline==5) {messbox(150,150,200,150,GREEN,"战争结局","        玩家胜利! \n \n        电脑失败!",1);
   closemouse();
   delay(200);
   finish=1;
   continue;
   }
  mline=mstatus[0];
  for(i=1;i<4;++i)
   if(mline<mstatus[i]) mline=mstatus[i];
   if (mline==5) {messbox(150,150,200,150,RED,"战争结局","       电脑胜利! \n \n       玩家失败!",1);
   closemouse();
   delay(200);
   finish=1;
   continue;
   }
if(writeflag==1) continue;
writeflag=1;
if(uline==ustatus[0])
 {
   if(uline>mline) goto wwmm;
   goto machwrite;
wwmm:if(uline<=4){
    if(boundcheck(newx,newy,1,ucol)==1) goto machine;
     if(boundcheck(newx,newy,5,ucol)==1) goto machine;
    }
 }
if(uline==ustatus[1])
 {
   if(uline>mline) goto wwmm1;
   goto machwrite;
wwmm1:if(uline<=4){
    if(boundcheck(newx,newy,2,ucol)==1) goto machine;
     if(boundcheck(newx,newy,6,ucol)==1) goto machine;
    }
 }
if(uline==ustatus[2])
 {
   if(uline>mline) goto wwmm2;
   goto machwrite;
wwmm2:if(uline<=4){
    if(boundcheck(newx,newy,3,ucol)==1) goto machine;
     if(boundcheck(newx,newy,7,ucol)==1) goto machine;
    }
 }
if(uline==ustatus[3])
 {
   if(uline>mline) goto wwmm3;
   goto machwrite;
wwmm3:if(uline<=4){
    if(boundcheck(newx,newy,4,ucol)==1) goto machine;
     if(boundcheck(newx,newy,8,ucol)==1) goto machine;
    }
 }

machwrite:    if(mline<=0) {
newxy:       mmx=newx+random(10)* 16;
       mmy=newy+random(10)*16;
       if(getpixel(mmx,mmy)==14||getpixel(mmx,mmy)==15) goto newxy;
       if(combut==0)  fillwhite(mmx,mmy);
       else   fillblack(mmx,mmy);

       goto machine;
    }

      if(mline==mstatus[0]){
        if(boundcheck(mmx,mmy,1,mcol)==1) goto machine;
        if(boundcheck(mmx,mmy,5,mcol)==1) goto machine;
        }
      if(mline==mstatus[1]) {
        if(boundcheck(mmx,mmy,2,mcol)==1) goto machine;
        if(boundcheck(mmx,mmy,6,mcol)==1) goto machine;
         }
     if(mline==mstatus[2]) {
        if(boundcheck(mmx,mmy,3,mcol)==1) goto machine;
        if(boundcheck(mmx,mmy,7,mcol)==1) goto machine;
         }
     if(mline==mstatus[3]){
        if(boundcheck(mmx,mmy,4,mcol)==1) goto machine;
        if(boundcheck(mmx,mmy,8,mcol)==1) goto machine;
         }

 mline=mline-1;
 goto machwrite;

}
comfirst: mmx=296+random(10)*16;
       mmy=216+random(10)*16;
       if(combut==0)  fillwhite(mmx,mmy);
      else   fillblack(mmx,mmy);
      pushbutt(560,230,50,18,7,1);
      strout(566,231,8,"玩 家");
      popbutt(560,260,50,18,7,1);
      strout(566,261,8,"电 脑");

 nonxy:
   continue;
 }
}
/* 获取用户按键 */
int getkey()
{
/*  regs.h.ah=1;
  int86(0x16,®s,®s);
  return (regs.h.al); */
  return (inportb(0x60));
}

/* 帮助窗口  */

void helpwin()
{
  messbox(150,100,300,200,GREEN,"关于本游戏","    这只是一个简单的五子棋游戏.\n  \n     版本:1.00    作者:罗旭 \n \n  2001年6月27日于黄石陈家湾  \n    我的邮箱:cn_blue@163.com ",1);
  messbox(150,50,300,200,GREEN,"游戏运行环境","   首先您必须运行鼠标驱动程序,当前\n执行程序目录下有HZK16这个文件,这是\n一个16点阵的汉字库(如UCDOS带的HZZK16等)。\n\n    操作过程中按鼠标右键毁棋! \n    请不要在汉字系统环境下运行!",1);

}
/* 显示菜单 */

void writebut()
{
  popbutt(20,90,70,18,7,1);
  strout(24,91,8,"两人对战");
  popbutt(20,120,70,18,7,1);
  strout(24,121,8,"人机对战");
  popbutt(20,150,70,18,LIGHTGRAY,1);
  strout(24,151,8,"重新开局");
  popbutt(20,180,70,18,LIGHTGRAY,1);
  strout(24,181,8,"系统帮助");
  popbutt(20,210,70,18,LIGHTGRAY,1);
  strout(24,211,8,"退出系统");

 if(gameflag==1){
  popbutt(546,86,79,18,7,3);
  strout(548,88,8," 玩 家 一");
  pushbutt(550,110,30,18,7,1);
  fillblack(565,119);
  popbutt(590,110,30,18,7,1);
  fillwhite(605,119);
  popbutt(546,135,79,18,7,3);
  strout(548,137,8," 玩 家 二");
  popbutt(550,159,30,18,7,1);
  fillblack(565,168);
  pushbutt(590,159,30,18,7,1);
  fillwhite(605,168);
  pushbutt(560,230,50,18,7,1);
  strout(561,231,8,"玩家一");
  popbutt(560,260,50,18,7,1);
  strout(561,261,8,"玩家二");}

  popbutt( 546,200,79,18,7,3);
  strout(548,202,RED," 当前状态");
  if(gameflag==0){
  popbutt(560,230,50,18,7,1);
  strout(566,231,8,"玩 家");
  popbutt(560,260,50,18,7,1);
  strout(566,261,8,"电 脑");
  popbutt(546,86,79,18,7,3);
  strout(548,88,8,"  玩  家");
  popbutt(546,135,79,18,7,3);
  strout(548,137,8,"  电  脑");}

}
/*检测用户动作*/
void checkbut(int newx,int newy,int mbutt)
{

  if(newx<135||newx>505||newy<55||newy>425)
       {  if(mbutt==1){
   closemouse();
   if(gameflag==1){
   if(newx>=550&&newx<=580&&newy>=110&&newy<=128&&p1but!=1){
      pushbutt(550,110,30,18,7,1);
      fillblack(565,119);
      popbutt(590,110,30,18,7,1);
      fillwhite(605,119);
      p1but=1;
       }
   if(newx>=590&&newx<=620&&newy>=110&&newy<=128&&p1but!=0){
       popbutt(550,110,30,18,7,1);
       fillblack(565,119);
       pushbutt(590,110,30,18,7,1);
       fillwhite(605,119);
       p1but=0;
       }
   if(newx>=550&&newx<=580&&newy>=159&&newy<=177&&p2but!=1){
        pushbutt(550,159,30,18,7,1);
        fillblack(565,168);
        popbutt(590,159,30,18,7,1);
        fillwhite(605,168);
       p2but=1;
       }
  if(newx>=590&&newx<=620&&newy>=159&&newy<=177&&p2but!=0){
        popbutt(550,159,30,18,7,1);
        fillblack(565,168);
        pushbutt(590,159,30,18,7,1);
        fillwhite(605,168);
       p2but=0;
       }
   }

   if(gameflag==0){
   if(newx>=550&&newx<=580&&newy>=110&&newy<=128&&pbut!=1){
       pushbutt(550,110,30,18,7,1);
       fillblack(565,119);
       popbutt(590,110,30,18,7,1);
       fillwhite(605,119);
       ucol=14;
       pbut=1;
       }
   if(newx>=590&&newx<=620&&newy>=110&&newy<=128&&pbut!=0){
       popbutt(550,110,30,18,7,1);
       fillblack(565,119);
       pushbutt(590,110,30,18,7,1);
       fillwhite(605,119);
       ucol=15;
       pbut=0;
       }
   if(newx>=550&&newx<=580&&newy>=159&&newy<=177&&combut!=1){
        pushbutt(550,159,30,18,7,1);
        fillblack(565,168);
        popbutt(590,159,30,18,7,1);
        fillwhite(605,168);
       mcol=14;
       combut=1;
       }
  if(newx>=590&&newx<=620&&newy>=159&&newy<=177&&combut!=0){
        popbutt(550,159,30,18,7,1);
        fillblack(565,168);
        pushbutt(590,159,30,18,7,1);
        fillwhite(605,168);
        mcol=15;
        combut=0;
       }
   }
   if(newx>=24&&newx<=24+70&&newy>=90&&newy<=90+18){
       gameflag=1;
       finish=0;
       writebut();
       pushbutt(20,90,70,18,7,1);
       strout(24,91,8,"两人对战");
       clearboard();

       }
    if(newx>=24&&newx<=24+70&&newy>=120&&newy<=120+18){
       gameflag=0;
       writebut();
       pushbutt(20,120,70,18,7,1);
       strout(24,121,8,"人机对战");
       clearboard();
        computer();

       }

    if(newx>=24&&newx<=24+70&&newy>=150&&newy<=150+18){
       writebut();
       if(gameflag==1){
                                          pushbutt(20,90,70,18,7,1);
       strout(24,91,8,"两人对战");
       pushbutt(560,230,50,18,7,1);
       strout(561,231,8,"玩家一");
       popbutt(560,260,50,18,7,1);
       strout(561,261,8,"玩家二");}
       if(gameflag==0){
                                           pushbutt(20,120,70,18,7,1);
       strout(24,121,8,"人机对战");
        pushbutt(560,230,50,18,7,1);
        strout(566,231,8,"玩 家");
        popbutt(560,260,50,18,7,1);
        strout(566,261,8,"电 脑");
      }
       pushbutt(20,150,70,18,7,1);
       strout(24,151,8,"重新开局");
       clearboard();
       popbutt(20,150,70,18,7,1);
       strout(24,151,8,"重新开局");
       finish=0;
       }
     if(newx>=24&&newx<=24+70&&newy>=180&&newy<= 180+18){
       writebut();
       pushbutt(20,180,70,18,7,1);
       strout(24,181,8,"系统帮助");
       delay(200);
       popbutt(20,180,70,18,7,1);
       strout(24,181,8,"系统帮助");
       helpwin();
      }
     if(newx>=24&&newx<=24+70&&newy>=210&&newy<=210+18){
       writebut();
       pushbutt(20,210,70,18,7,1);
       strout(24,211,8,"退出系统");
       close(fp);
       closegraph();
       exit(0);
       }
   }
     }
}
int scanchess(int x,int y,int direction,int chesscolor)
{
  int chessnum=0;
  switch(direction) {
    case 1: {
        if(getpixel(x-16,y-16)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x-32,y-32)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x-48,y-48)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x-64,y-64)!=chesscolor) return chessnum;
    ++chessnum;
        return chessnum;
      }
     case 2: {
        if(getpixel(x,y-16)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x,y-32)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x,y-48)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x,y-64)!=chesscolor) return chessnum;
    ++chessnum;
        return chessnum;
      }
     case 3: {
        if(getpixel(x+16,y-16)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x+32,y-32)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x+48,y-48)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x+64,y-64)!=chesscolor) return chessnum;
    ++chessnum;
        return chessnum;
      }
     case 4: {
        if(getpixel(x+16,y)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x+32,y)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x+48,y)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x+64,y)!=chesscolor) return chessnum;
    ++chessnum;
        return chessnum;
      }
     case 5: {
        if(getpixel(x+16,y+16)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x+32,y+32)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x+48,y+48)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x+64,y+64)!=chesscolor) return chessnum;
    ++chessnum;
        return chessnum;
      }
     case 6: {
        if(getpixel(x,y+16)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x,y+32)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x,y+48)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x,y+64)!=chesscolor) return chessnum;
    ++chessnum;
        return chessnum;
      }
      case 7: {
        if(getpixel(x-16,y+16)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x-32,y+32)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x-48,y+48)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x-64,y+64)!=chesscolor) return chessnum;
    ++chessnum;
        return chessnum;
      }
     case 8: {
        if(getpixel(x-16,y)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x-32,y)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x-48,y)!=chesscolor) return chessnum;
    ++chessnum;
        if(getpixel(x-64,y)!=chesscolor) return chessnum;
    ++chessnum;
        return chessnum;
      }
  }
}
int boundcheck(int x,int y,int direction,int color)
{
  int chnum,tx,ty;
  chnum=scanchess(x,y,direction,color)+1;
  switch(direction) {
    case 1: {   tx=x-chnum*16;
  ty=y-chnum*16;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;
         if(combut==0) fillwhite(mmx,mmy);
         else   fillblack(mmx,mmy);
         return 1;
      }
  return -1;
      }
     case 2: {  tx=x;
  ty=y-chnum*16;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;
                       if(combut==0) fillwhite(mmx,mmy);
         else   fillblack(mmx,mmy);

         return 1;
      }
  return -1;
      }
      case 3: { tx=x+chnum*16;
  ty=y-chnum*16;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;
                       if(combut==0) fillwhite(mmx,mmy);
         else   fillblack(mmx,mmy);

         return 1;
      }
  return -1;
      }
      case 4: { tx=x+chnum*16;
  ty=y;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;
                       if(combut==0) fillwhite(mmx,mmy);
         else   fillblack(mmx,mmy);

         return 1;
      }
  return -1;
      }
      case 5: { tx=x+chnum*16;
  ty=y+chnum*16;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;
                       if(combut==0) fillwhite(mmx,mmy);
         else   fillblack(mmx,mmy);

         return 1;
      }
  return -1;
      }
      case 6: { tx=x;
  ty=y+chnum*16;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;
                       if(combut==0) fillwhite(mmx,mmy);
         else   fillblack(mmx,mmy);

         return 1;
      }
  return -1;
      }
      case 7: { tx=x-chnum*16;
  ty=y+chnum*16;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;
                       if(combut==0) fillwhite(mmx,mmy);
         else   fillblack(mmx,mmy);

         return 1;
      }
  return -1;
      }
       case 8: { tx=x-chnum*16;
  ty=y;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;
                       if(combut==0) fillwhite(mmx,mmy);
         else   fillblack(mmx,mmy);

         return 1;
      }
  return -1;
      }
      }
}
int boundans(int x,int y,int direction,int color)
{
  int chnum,tx,ty;
  chnum=scanchess(x,y,direction,color)+1;
  switch(direction) {
    case 1: {   tx=x-chnum*16;
  ty=y-chnum*16;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;
         return 1;
      }
  return -1;
      }
     case 2: {  tx=x;
  ty=y-chnum*16;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;

         return 1;
      }
  return -1;
      }
      case 3: { tx=x+chnu m*16;
  ty=y-chnum*16;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;
                       if(combut==0) fillwhite(mmx,mmy);
         else   fillblack(mmx,mmy);

         return 1;
      }
  return -1;
      }
      case 4: { tx=x+chnum*16;
  ty=y;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;


         return 1;
      }
  return -1;
      }
      case 5: { tx=x+chnum*16;
  ty=y+chnum*16;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;

         return 1;
      }
  return -1;
      }
      case 6: { tx=x;
  ty=y+chnum*16;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;

         return 1;
      }
  return -1;
      }
      case 7: { tx=x-chnum*16;
  ty=y+chnum*16;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;

         return 1;
      }
  return -1;
      }
       case 8: { tx=x-chnum*16;
  ty=y;
  if(getpixel(tx,ty)!=14&&getpixel(tx,ty)!=15&&tx>=135&&tx<=505&&ty>=55&&ty<=425)
      {  mmx=tx;
         mmy=ty;

         return 1;
      }
  return -1;
      }
      }
}

上一篇:{应用}2人五子棋游戏(1) 人气:6767
下一篇:{应用}乒乓球游戏 人气:6432
视频教程列表
文章教程搜索
 
C语言程序设计推荐教程
C语言程序设计热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058