龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > C/C++开发 >

五子棋(结束界面改观了一下)

时间:2009-12-22 15:42来源:未知 作者:admin 点击:
分享到:
#include #include #include #include #include #define LEFT 0x4b00 #define RIGHT 0x4d00 #define DOWN 0x5000 #define UP 0x4800 #define ESC 0x011b #define SPACE 0x3920 #define BILI 20 #define JZ 4 #define JS 3 #define N 19 int box[N][N]; int st

#include

  #include

  #include

  #include

  #include

#define LEFT 0x4b00

  #define RIGHT 0x4d00

  #define DOWN 0x5000

  #define UP 0x4800

  #define ESC 0x011b

  #define SPACE 0x3920

#define BILI 20

  #define JZ 4

  #define JS 3

  #define N 19

int box[N][N];

  int step_x,step_y ;

  int key ;

  int flag=1 ;

void draw_box();

  void draw_cicle(int x,int y,int color);

  void change();

  void judgewho(int x,int y);

  void judgekey();

  int judgeresult(int x,int y);

  void attentoin();

void attention()

  {

   char ch ;

   gotoxy(20,4);

   printf("请注重(Attentoin please!)");

   gotoxy(20,6);

   printf("1.按左右上下方向键移动棋子");

   gotoxy(20,8);

   printf("2.按空格确定落棋子");

   gotoxy(20,10);

   printf("3.注重:禁止在棋盘外按空格");

   gotoxy(20,12);

   printf("你是否接受上叙的游戏规则(Y/N)");

   while(1)

   {

   gotoxy(51,12);

   ch=getche();

   if(ch=='Y'ch=='y')

   break ;

   else if(ch=='N'ch=='n')

   exit(0);

   gotoxy(51,12);

   printf(" ");

   }

  }

  void draw_box()

  {

   int x1,x2,y1,y2 ;

   setbkcolor(2);

   setcolor(1);

   for(x1=1,y1=1,y2=18;x1<=18;x1++)

   line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI);

   for(x1=1,y1=1,x2=18;y1<=18;y1++)

   line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI);

   for(x1=1;x1<=18;x1++)

   for(y1=1;y1<=18;y1++)

   box[x1][y1]=0 ;

  }

void draw_circle(int x,int y,int color)

  {

   setcolor(color);

   setlinestyle(SOLID_LINE,0,1);

   x=(x+JZ)*BILI ;

   y=(y+JS)*BILI ;

   circle(x,y,8);

  }

void judgekey()

  {

   int i ;

   int j ;

   switch(key)

   {

   case LEFT :

  

   if(step_x-1<0)

   break ;

   else

   {

   for(i=step_x-1,j=step_y;i>=1;i--)

   if(box[i][j]==0)

   {

   draw_circle(step_x,step_y,2);

   break ;

   }

   if(i<1)break ;

   step_x=i ;

   judgewho(step_x,step_y);

   break ;

   }

   case RIGHT :

  

   if(step_x+1>18)

   break ;

   else

   {

   for(i=step_x+1,j=step_y;i<=18;i++)

   if(box[i][j]==0)

   {

   draw_circle(step_x,step_y,2);

   break ;

   }

   if(i>18)break ;

   step_x=i ;

   judgewho(step_x,step_y);

   break ;

   }

   case DOWN :

  

   if((step_y+1)>18)

   break ;

   else

   {

   for(i=step_x,j=step_y+1;j<=18;j++)

   if(box[i][j]==0)

   {

   draw_circle(step_x,step_y,2);

   break ;

   }

   if(j>18)break ;

   step_y=j ;

   judgewho(step_x,step_y);

   break ;

   }

   case UP :

  

   if((step_y-1)<0)

   break ;

   else

   {

   for(i=step_x,j=step_y-1;j>=1;j--)

   if(box[i][j]==0)

   {

   draw_circle(step_x,step_y,2);

   break ;

   }

   if(j<1)break ;

   step_y=j ;

   judgewho(step_x,step_y);

   break ;

   }

   case ESC :

   break ;

   &nbs

  

  

精彩图集

赞助商链接