| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 771 人关注过本帖
标题:五子棋的编程,谁能给改一下啊
取消只看楼主 加入收藏
老人与颂扬
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-7-19
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
五子棋的编程,谁能给改一下啊
#include<graphics.h>

#define N 20
const int LINE_NUM=19;


/*define keyboard*/
#define up 0x4800
#define down 0x5000
#define left 0x4b00
#define right 0x4d00
#define esc 0x011b
#define enter 0x1c0d
#define A 0x1e61
#define S 0x1f73
#define D 0x2064
#define W 0x1177
#define space 0x3920
#define Y 0x1579
#define n 0x316e


int gamespeed=5000;
int i,j,key;


struct Solution
{
     int x;
     int y;/*x,y define the place of the curSolution*/
     int yes[N][N];/* 0:no chess,1: white chess,2: Red chess*/
     int will;/* 1: white chess is setting,2: Red chess is setting*/
     int ok;/*1:white chess is winning,2: white chess is winning*/
}Solution;

void init(void)       /*graph drive*/
{
     int driver=DETECT,mode=0;
    /* registerbgidriver(EGAVGA_driver);    */
     initgraph(&driver,&mode,"");
}







void drawqp(void)/*draw qi pan*/
{
     setcolor(5);
     for(i=50;i<=(N-1)*20+30;i+=20)
     {
         
          line(50,i,50+(19-1)*20,i);
          line(i,50,i,50+(19-1)*20);
     }
     setcolor(11);
     for(i=1;i<3;i++)
     {
         
          circle(50+(10-1)*20,50+(10-1)*20,i);
          circle(50+(5-1)*20,50+(5-1)*20,i);
          circle(50+(5-1)*20,50+(15-1)*20,i);
          circle(50+(15-1)*20,50+(5-1)*20,i);
          circle(50+(15-1)*20,50+(15-1)*20,i);
         
     }
}

void  titleMessage (void)  /*input message*/
{
     setcolor(15);
     settextstyle(0,0,1);
     outtextxy(50,20,"White Chess: Up Down Left Right Enter    Black Chess: W S A D Space");
}

void place(void)/*画出当前光标的位置*/
{
     line(Solution.x-10,Solution.y-10,Solution.x-7,Solution.y-10);
     line(Solution.x-10,Solution.y-10,Solution.x-10,Solution.y-7);

     line(Solution.x-10,Solution.y+10,Solution.x-10,Solution.y+7);
     line(Solution.x-10,Solution.y+10,Solution.x-7,Solution.y+10);

     line(Solution.x+10,Solution.y-10,Solution.x+10,Solution.y-7);
     line(Solution.x+10,Solution.y-10,Solution.x+7,Solution.y-10);

     line(Solution.x+10,Solution.y+10,Solution.x+7,Solution.y+10);
     line(Solution.x+10,Solution.y+10,Solution.x+10,Solution.y+7);

 }

void judge(void)/*judge the result*/
{
     for(i=1;i<N;i++)
     {
          for(j=1;j<N;j++)
          {
               if(
                   ((j+4)<N&&Solution.yes[i][j]!=0&&
                    Solution.yes[i][j]==Solution.yes[i][j+1]&&
                    Solution.yes[i][j+1]==Solution.yes[i][j+2]&&
                    Solution.yes[i][j+2]==Solution.yes[i][j+3]&&
                    Solution.yes[i][j+3]==Solution.yes[i][j+4])||

                    ((i+4)<N&&Solution.yes[i][j]!=0&&
                    Solution.yes[i][j]==Solution.yes[i+1][j]&&
                    Solution.yes[i+1][j]==Solution.yes[i+2][j]&&
                    Solution.yes[i+2][j]==Solution.yes[i+3][j]&&
                    Solution.yes[i+3][j]==Solution.yes[i+4][j])||

                    ((i+4)<N&&(j+4)<N&&Solution.yes[i][j]!=0&&
                    Solution.yes[i][j]==Solution.yes[i+1][j+1]&&
                    Solution.yes[i+1][j+1]==Solution.yes[i+2][j+2]&&
                    Solution.yes[i+2][j+2]==Solution.yes[i+3][j+3]&&
                    Solution.yes[i+3][j+3]==Solution.yes[i+4][j+4])||

                    ((i+4)<N&&j>4&&Solution.yes[i][j]!=0&&
                    Solution.yes[i][j]==Solution.yes[i+1][j-1]&&
                    Solution.yes[i+1][j-1]==Solution.yes[i+2][j-2]&&
                    Solution.yes[i+2][j-2]==Solution.yes[i+3][j-3]&&
                    Solution.yes[i+3][j-3]==Solution.yes[i+4][j-4]))
               {
                    if(Solution.yes[i][j]==1)
                         Solution.ok=1;
                    else
                         Solution.ok=2;
                         break;
               }
          }
          if(Solution.ok!=0)
               break;
     }
}

void gameover(void)
{
     setcolor(0);
     settextstyle(0,0,1);
     outtextxy(50,20,"White Chess: Up Down Left Right Enter    Black Chess: W S A D Space");
     if(Solution.ok==1)
     {
         outtextxy(488,119,"White");
         
     }
     else
     {
         outtextxy(488,119,"Red");
         
     }
     
     outtextxy(488,189," Chess");
     
     outtextxy(488,259," Win");
     outtextxy(488,329," !");

     
}

/*show the x and y coordinate*/
void ShowXY(void)
{
     char str1[10],str2[10];
     setfillstyle(SOLID_FILL,7);
     bar(50,440,205,470);
     setcolor(12);
     settextstyle(0,0,2);
     sprintf(str1,"X:%d",(Solution.x-30)/20);
     sprintf(str2,"Y:%d",(Solution.y-30)/20);
     outtextxy(60,450,str1);
     outtextxy(135,450,str2);
}

void gameplay(void)
{
     for(i=1;i<N;i++)/*initialize chessboard*/
          for(j=1;j<N;j++)
               Solution.yes[i][j]=0;

     Solution.will=1; /* white chess first */

     Solution.ok=0;/* result is not decided*/

     Solution.x=50+(10-1)*20;/*230*/

     Solution.y=50+(10-1)*20;/*initialize cursor ,the position is in the center of the chessboard*/

     setcolor(15);
     place();

     while(1)
     {
          ShowXY();
          key=bioskey(0);
          if(key==esc)
               break;

          /*white chess key is moving*/
      else if(key==up&&Solution.y>50&&Solution.will==1)/*50 the top*/
          {
               setcolor(0);
               place();
               Solution.y-=20;
          }
      else if(key==down&&Solution.y<(N-1)*20+30&&Solution.will==1)/*230 the bottow  */
          {
               setcolor(0);
               place();
               Solution.y+=20;
          }
          else if(key==left&&Solution.x>50&&Solution.will==1)
          {
               setcolor(0);
               place();
               Solution.x-=20;
          }
          else if(key==right&&Solution.x<(N-1)*20+30&&Solution.will==1)
          {
               setcolor(0);
               place();
               Solution.x+=20;
          }

          /*red chess is moving*/
          else if(key==W&&Solution.y>50&&Solution.will==2)
          {
               setcolor(0);
               place();
               Solution.y-=20;
          }
          else if(key==S&&Solution.y<(N-1)*20+30&&Solution.will==2)
          {
               setcolor(0);
               place();
               Solution.y+=20;
          }
          else if(key==A&&Solution.x>50&&Solution.will==2)
          {
               setcolor(0);
               place();
               Solution.x-=20;
          }
          else if(key==D&&Solution.x<(N-1)*20+30&&Solution.will==2)
          {
               setcolor(0);
               place();
               Solution.x+=20;
          }
          else if(key==space&&Solution.yes[(Solution.x-30)/20][(Solution.y-30)/20]==0&&Solution.will==2)
          {
               setcolor(13);
               for(i=1;i<=9;i++)
               {
            circle(Solution.x,Solution.y,i);/* i is the radius*/
            delay(10000);/* delay time 1 s  */
               }
               Solution.yes[(Solution.x-30)/20][(Solution.y-30)/20]=2;
               Solution.will=1;
               judge();/* judge result*/
               if(Solution.ok!=0)
               {
                    gameover();
                    break;
               }
          }
          else if(key==enter&&Solution.yes[(Solution.x-30)/20][(Solution.y-30)/20]==0&&Solution.will==1)
          {
               setcolor(15);
               for(i=1;i<=9;i++)
               {
            circle(Solution.x,Solution.y,i);/* i is the radius, draw the concentric circles */
                    delay(10000);
               }
               Solution.yes[(Solution.x-30)/20][(Solution.y-30)/20]=1;
               Solution.will=2;
               judge();
               if(Solution.ok!=0)
               {
                    gameover();
                    break;
               }
          }
          else
               continue;
          if(Solution.ok!=0)
               break;
          if(Solution.will==1)
               setcolor(15);
          else
               setcolor(13);
          place();
     }/*endwhile(1)*/
}



main()
{

     while(1)
     {
          init();
          cleardevice();
          titleMessage();
          drawqp();
          setfillstyle(SOLID_FILL,7);


          gameplay();
          setcolor(15);
          settextstyle(0,0,2);
          outtextxy(230,450,"Continue? (Y/N)");
          while(1)
          {
               key=bioskey(0);
               if(key==Y||key==n||key==esc)
                    break;
          }
          if(key==n||key==esc)
               break;
     }
     closegraph();
}

搜索更多相关主题的帖子: 五子棋 
2010-07-19 16:20
老人与颂扬
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-7-19
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册

这是错误:

d:\fivechess.c(1) : fatal error C1083: Cannot open include file: 'graphics.h': No such file or directory
哪位高手能给改一下啊,小弟万分感谢!
2010-07-19 16:29
老人与颂扬
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-7-19
收藏
得分:0 
四个include里什么都没包含,怎么可能运行的了啊········
2010-07-20 16:05
老人与颂扬
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-7-19
收藏
得分:0 
vikingguo
你是深山里的黄瓜,欠拍·········哈哈
2010-07-21 15:17
快速回复:五子棋的编程,谁能给改一下啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.063430 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved