正文

五子棋(II)2005-08-07 11:10:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/elva6401/3596.html

分享到:

#include <graphics.h> #include <dos.h> #include <stdio.h> #define computer 2 #define elva6401 1 #define left 75 #define right 77 #define down 80 #define up 72 #define enter 0 #define ALT_X 45 #define top_x 120 #define top_y 100 int chess_map[16][16]; int column,row; int b_column,b_row;/*记下移动前行列,为了un_draw_chess()*/ int E_column,E_row;/*记下按enter的行列或电脑的想的行列*/ int flag=1; /***********************************************/ /* 初始化行列 */ int init_col_row() { int i,j; for (i=0;i<16;i++) for (j=0;j<16;j++)     if (chess_map[i][j]==0)     {     b_column=column=16-i;     b_row=row=16-j;     return 0;     } } /***********************************************/ /* 画整个棋盘 */ int draw_map() { int i; setcolor(GREEN); for (i=0;i<16;i++)     {     line(top_x+i*20,top_y,top_x+i*20,top_y+300);     line(top_x,top_y+i*20,top_x+300,top_y+i*20);     } } /***********************************************/ /* 初始化初始化棋盘 */ void init() { int i,j; for (i=0;i<16;i++) for (j=0;j<16;j++)     chess_map[i][j]=0; init_col_row(); draw_map(); } /***********************************************/ /* 得到当前的按键 ASCII 码 */ int Getkey(void) { int key=0; while (bioskey(1) == 0);/*等待按键*/ key = bioskey(0);/*把接收的按键的键盘码赋给变量key*/ return key; } /***********************************************/ /* 是否能移到column行,row列,能返回0 */ int limit() { if ((column>16 || column<1) || (row>16 || row<1) || chess_map[column-1][row-1]!=0)     return 1; else     return 0; } /***********************************************/ /* 画棋子 */ int draw_chess(int player) { if (player==1)     {     setcolor(WHITE);     setfillstyle(SOLID_FILL,WHITE);     circle(top_x+(column-1)*20,top_y+(row-1)*20,9);     } else     {     setcolor(RED);     setfillstyle(SOLID_FILL,RED);     circle(top_x+(column-1)*20,top_y+(row-1)*20,9);     } } /***********************************************/ /* 涂掉前一步所画的棋子 */ int un_draw_chess() { setcolor(BLUE); setfillstyle(SOLID_FILL,BLUE); circle(top_x+(b_column-1)*20,top_y+(b_row-1)*20,9); setcolor(GREEN); line(top_x+(b_column-1)*20,top_y,top_x+(b_column-1)*20,top_y+300); line(top_x,top_y+(b_row-1)*20,top_x+300,top_y+(b_row-1)*20); } /***********************************************/ /* 对按键的反映,人下棋 */ int move_chess() { int key=Getkey(); b_column=column; b_row=row; switch(key) { case left :     if (column==1) column=17;     column--;     while(limit())         column--;     break; case right :     if (column==16) column=0;     column++;     while(limit())         column++;     break; case up :     if (row==1) row=17;     row--;     while(limit())         row--;     break; case down :     if (row==16) row=0;     row++;     while(limit())         row++;     break; case enter :     chess_map[column-1][row-1]=elva6401;     E_column=column,E_row=row;     flag=0;     return 0; case ALT_X :     exit(0); default : return 0; } draw_chess(elva6401); un_draw_chess(); }

阅读(16318) | 评论(2)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册