| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1932 人关注过本帖
标题:我刚编的黑白棋游戏
取消只看楼主 加入收藏
deepblue
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2004-12-15
收藏
 问题点数:0 回复次数:3 
我刚编的黑白棋游戏

用的是边角权值算法不很完善,请大家多提意见。

搜索更多相关主题的帖子: 黑白棋 游戏 边角 算法 意见 
2004-12-17 17:32
deepblue
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2004-12-15
收藏
得分:0 

/**********************************************/ /* 黑白棋源代码 */ /* TC2.0下运行通过 */ /* 走子策略采用边角权值算法 */ /**********************************************/

# include <stdio.h> # include <dos.h> # include <conio.h> # include <graphics.h> # include <stdlib.h> # include <time.h>

# define BGCOLOR 1 /* 背景颜色*/ # define COLOR_WHITECHESS 0 /*白棋棋子的颜色*/ # define COLOR_BLACKCHESS 15 /*黑棋棋子的颜色*/ # define COLOR_LINE 15 /*棋盘线的颜色*/

# define MINBOXSIZE 30 /*棋盘每一格边长*/ # define MAXSIZE 300 /*棋盘的大小 (1+8+1)*25 */ # define SCCOL 50 /*棋盘左上角的坐标*/ # define SCROW 60

/* 按键码*/ # define VK_LEFT 0x4b00 # define VK_RIGHT 0x4d00 # define VK_DOWN 0x5000 # define VK_UP 0x4800 # define VK_SPACE 0x3920 # define VK_ESC 0x011b

/*初始棋盘布局*/ int gril[10][10]= {{0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,1,2,0,0,0,0}, {0,0,0,0,2,1,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0} };

int gril_value[10][10]= {{0,0,0,0,0,0,0,0,0,0}, {0,36,1,19,9,9,19,1,36,0}, {0,1,1,4,4,4,4,1,1,0}, {0,19,4,6,4,4,6,4,19,0}, {0,9,4,4,4,4,4,4,9,0}, {0,9,4,4,4,4,4,4,9,0}, {0,19,4,6,4,4,6,4,19,0}, {0,1,1,4,4,4,4,1,1,0}, {0,36,1,19,9,9,19,1,36,0}, {0,0,0,0,0,0,0,0,0,0}, };

int num_user=2; /*得分统计*/ int num_computer=2;

int gbwzc=5,gbwzr=5; /*光标的初始位置*/ int present_p_v[10][10]; /*当前格的位置及其权值*/

char again='0'; /*用来判断游戏是否需要重新开始*/

/****************用到的汉字*********************/ char ci16H[]={ /* 以下是 '此' 的 16点阵华文行楷 字模,32 byte */ 0x00,0x00,0x00,0x00,0x00,0x80,0x0C,0x50, 0x04,0x58,0x07,0xF0,0x27,0xA0,0x14,0xE0, 0x15,0xC0,0x16,0x82,0x1C,0x86,0x38,0x7E, 0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00, };

char you16H[]={ /* 以下是 '游' 的 16点阵华文行楷 字模,32 byte */ 0x00,0x00,0x00,0x30,0x0D,0xD0,0x0D,0xBC, 0x21,0xF8,0x17,0x98,0x1F,0xB8,0x1D,0xD0, 0x17,0x5C,0x16,0xBC,0x1A,0xF8,0x19,0x48, 0x08,0x78,0x00,0x10,0x00,0x00,0x00,0x00, };

char xi16H[]={ /* 以下是 '戏' 的 16点阵华文行楷 字模,32 byte */ 0x00,0x00,0x01,0x80,0x00,0x98,0x00,0xD0, 0x06,0x70,0x0E,0x60,0x0F,0xD0,0x36,0xB0, 0x4C,0x30,0x4F,0x70,0x39,0x90,0x00,0x0A, 0x00,0x0C,0x00,0x06,0x00,0x00,0x00,0x00, };

char song16H[]={ /* 以下是 '送' 的 16点阵华文行楷 字模,32 byte */ 0x00,0x20,0x00,0xB0,0x19,0xA0,0x1D,0x60, 0x21,0xE0,0x38,0xC0,0x19,0xF0,0x17,0x80, 0x12,0xC0,0x0B,0x30,0x3F,0x10,0x00,0xFE, 0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00, };

char gei16H[]={ /* 以下是 '给' 的 16点阵华文行楷 字模,32 byte */ 0x00,0x00,0x00,0xC0,0x0C,0xC0,0x0C,0x80, 0x19,0xE0,0x39,0x30,0x3A,0x78,0x15,0xCE, 0x38,0x62,0x1B,0xF0,0x1A,0x60,0x33,0xE0, 0x11,0x20,0x00,0x00,0x00,0x00,0x00,0x00, };

char wo16H[]={ /* 以下是 '我' 的 16点阵华文行楷 字模,32 byte */ 0x00,0x80,0x00,0xC0,0x01,0xD8,0x03,0xC8, 0x0E,0x60,0x13,0xE0,0x27,0x20,0x2E,0x78, 0x1F,0xB0,0x03,0x30,0x0E,0xD0,0x06,0x0A, 0x02,0x0C,0x00,0x06,0x00,0x02,0x00,0x00, };

char ai16H[]={ /* 以下是 '爱' 的 16点阵华文行楷 字模,32 byte */ 0x00,0x20,0x00,0xF0,0x07,0xA0,0x02,0xA0, 0x06,0xA0,0x02,0xFC,0x17,0x8E,0x19,0xF0, 0x17,0xA0,0x13,0xE0,0x04,0xE0,0x05,0xC0, 0x0F,0xA0,0x00,0x1C,0x00,0x00,0x00,0x00, };

char de16H[]={ /* 以下是 '的' 的 16点阵华文行楷 字模,32 byte */ 0x00,0x00,0x00,0x60,0x0C,0xA0,0x04,0xA0, 0x1D,0x40,0x26,0x78,0x2A,0xC4,0x3E,0x04, 0x3E,0x64,0x3A,0xA4,0x1C,0x48,0x14,0x78, 0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00, };

char yao16H[]={ /* 以下是 '姚' 的 16点阵华文行楷 字模,32 byte */ 0x00,0x00,0x00,0x40,0x04,0x60,0x05,0x70, 0x05,0xA8,0x26,0xB0,0x36,0xA0,0x3B,0xD0, 0x3A,0xD0,0x2D,0x60,0x2B,0x44,0x1A,0x3E, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, };

char min16H[]={ /* 以下是 '敏' 的 16点阵华文行楷 字模,32 byte */ 0x00,0x00,0x04,0x00,0x0F,0x10,0x1E,0x10, 0x14,0x30,0x0F,0x3C,0x0B,0x70,0x1D,0x50, 0xF6,0xD0,0x6F,0x30,0x32,0x38,0x26,0xEE, 0x04,0x0F,0x00,0x00,0x00,0x00,0x00,0x00, }; /*******************************************************/ char zuo16S[]={ /* 以下是 '左' 的 16点阵宋体 字模,32 byte */ 0x02,0x00,0x03,0x00,0x02,0x00,0xFF,0xFE, 0x02,0x00,0x02,0x00,0x04,0x00,0x04,0x00, 0x0F,0xF8,0x08,0x80,0x10,0x80,0x10,0x80, 0x20,0x80,0x40,0x80,0xBF,0xFE,0x00,0x00, };

char you16S[]={ /* 以下是 '右' 的 16点阵宋体 字模,32 byte */ 0x02,0x00,0x02,0x00,0x02,0x00,0xFF,0xFE, 0x04,0x00,0x04,0x00,0x08,0x00,0x18,0x00, 0x2F,0xF8,0x48,0x08,0x88,0x08,0x08,0x08, 0x08,0x08,0x0F,0xF8,0x08,0x08,0x00,0x00, };

char shang16S[]={ /* 以下是 '上' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0x01,0x00,0x01,0x00,0x01,0xF8,0x01,0x00, 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0x01,0x00,0x01,0x04,0x7F,0xFE,0x00,0x00, };

char xia16S[]={ /* 以下是 '下' 的 16点阵宋体 字模,32 byte */ 0x00,0x04,0x7F,0xFE,0x01,0x00,0x01,0x00, 0x01,0x00,0x01,0xC0,0x01,0x60,0x01,0x30, 0x01,0x20,0x01,0x00,0x01,0x00,0x01,0x00, 0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00, };

char yi16S[]={ /* 以下是 '移' 的 16点阵宋体 字模,32 byte */ 0x0C,0x40,0x70,0x7C,0x10,0x84,0x15,0x08, 0xFE,0x50,0x30,0x20,0x30,0xD0,0x5B,0x20, 0x54,0x7E,0x90,0x84,0x11,0x88,0x12,0x50, 0x10,0x20,0x10,0x40,0x11,0x80,0x16,0x00, };

char luo16S[]={ /* 以下是 '落' 的 16点阵宋体 字模,32 byte */ 0x04,0x40,0x04,0x40,0xFF,0xFE,0x04,0x40, 0x45,0x00,0x21,0xF8,0xA1,0x10,0x4A,0xA0, 0x48,0x40,0x10,0xA0,0x13,0x18,0xEF,0xF6, 0x22,0x10,0x22,0x10,0x23,0xF0,0x22,0x10, };

char zi16S[]={ /* 以下是 '子' 的 16点阵宋体 字模,32 byte */ 0x00,0x00,0x3F,0xF0,0x00,0x20,0x00,0x40, 0x00,0x80,0x01,0x00,0x01,0x00,0x01,0x04, 0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00, 0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00, };

char tui16S[]={ /* 以下是 '退' 的 16点阵宋体 字模,32 byte */ 0x40,0x00,0x27,0xF0,0x24,0x10,0x07,0xF0, 0x04,0x10,0x04,0x10,0xE7,0xF0,0x24,0x88, 0x24,0x50,0x24,0x20,0x25,0x10,0x26,0x18, 0x24,0x08,0x50,0x00,0x8F,0xFE,0x00,0x00, };

char chu16S[]={ /* 以下是 '出' 的 16点阵宋体 字模,32 byte */ 0x01,0x00,0x01,0x00,0x21,0x04,0x21,0x04, 0x21,0x04,0x21,0x04,0x3F,0xFC,0x21,0x04, 0x01,0x00,0x21,0x04,0x21,0x04,0x21,0x04, 0x21,0x04,0x3F,0xFC,0x20,0x04,0x00,0x00, }; /*******************************************************/

/*********************************************************************/ /*功能:初始化图形模式 */ /*调用TC中initgraph(&gdrive,&gmode,"E:\\Turboc\\")函数 */ /*********************************************************************/ void init(int gdrive,int gmode) { int gd = DETECT, gm = 0; /* 和gd=VGA,gm=VGAHI是同样效果 */ registerbgidriver(EGAVGA_driver);/* 注册BGI驱动后可以不需要.BGI文件的支持运行*/ initgraph(&gd, &gm, ""); }

/*********************************************/ /*在(a,b)处用color色显示大小为font的字符串txt*/ /*********************************************/ void txt(int a,int b,char *txt,int font,int color) { setcolor(color); settextstyle(0,0,font);/*设置图形模式下字符显示底字体、方向和大小*/ outtextxy(a,b,txt); /*图形模式下在x,y坐标位置显示一行字符串*/ }

/*******************************************************/ /* */ /* */ /* */ /*******************************************************/ void drawmat(char *mat,int matsize,int x,int y,int color) /*依次:字模指针、点阵大小、起始坐标(x,y)、颜色*/ { int i, j, k, n; n = (matsize - 1) / 8 + 1; for(j = 0; j < matsize; j++) for(i = 0; i < n; i++) for(k = 0;k < 8; k++) if(mat[j * n + i] & (0x80 >> k)) /*测试为1的位则显示*/ putpixel(x + i * 8 + k, y + j, color); }

void show_ym() { drawmat(ci16H, 16, 110,414, 1); drawmat(you16H,16, 130,414, 1); drawmat(xi16H, 16, 150,414, 1); drawmat(song16H,16,170,414, 1); drawmat(gei16H, 16,190,414, 1); drawmat(wo16H, 16, 210,414, 1); drawmat(ai16H, 16, 230,414, 1); drawmat(de16H, 16, 250,414, 1); drawmat(yao16H, 16,270,414, 1); drawmat(min16H, 16,290,414, 1); txt(315,417 ,"*****",1,1);

}

/**************************/ /*功能:在图形模式下的清屏*/ /*将屏幕用黑色填充 */ /**************************/ void cls() { setfillstyle(SOLID_FILL,0); /*用黑色进行实填充*/ setcolor(0); /*设置前景颜色 */ bar(0,0,640,480); /*0,0为屏幕左上角,屏幕宽为640,长为480*/ }

/*************************************/ /*功能:在图形模式下的高级清屏 */ /*它能填充指定颜色color的指定大小的矩*/ /*形框从(a,b)到(c,d) */ /*************************************/ void clscr(int a,int b,int c,int d,int color) { setfillstyle(SOLID_FILL,color); setcolor(color); bar(a,b,c,d); }

/***********************************************************/ /*功能:最小棋子的绘制 */ /*所在方格的所在格的坐标为(fc,fr) (1,1)为可落子的最左上格 */ /*棋子的半径为radius */ /*棋子的颜色为color */ /*棋子中心坐标为(a,b) */ /***********************************************************/ void minbox(int fc,int fr,int color) { int a=0,b=0; int radius; int color1=color; a=(fc*MINBOXSIZE+SCCOL)+MINBOXSIZE/2; b=(fr*MINBOXSIZE+SCROW)+MINBOXSIZE/2; radius=MINBOXSIZE/2-5;

setcolor(color1); setfillstyle(1,color1); pieslice(a, b,0,360,radius);

}

/**********************************/ /*功能:绘制棋盘的可见的最外框 */ /*非可见外框的最左上坐标为(ac,ar) */ /* 每一格棋的宽度为aw */ /**********************************/ void outerdraw(int ac,int br,int aw,int color) { int a,b; a=ac+aw; b=br+aw;

setcolor(color); rectangle(a,b,a+8*MINBOXSIZE, b+8*MINBOXSIZE); rectangle(a-3,b-3,a+8*MINBOXSIZE+3, b+8*MINBOXSIZE+3); rectangle(a-4,b-4,a+8*MINBOXSIZE+4, b+8*MINBOXSIZE+4); rectangle(a-5,b-5,a+8*MINBOXSIZE+5, b+8*MINBOXSIZE+5); }

/*************************************/ /*功能:绘制棋盘中间的纵横线 */ /*非可见外框的最左上坐标为(cc,cr) */ /*每一格棋的宽度为cw */ /*线的颜色为color */ /*先画七根纵线,后画七根横线 */ /*************************************/ void linedraw(int cc,int cr,int cw,int color) { int m=0; int x1,y1,x2,y2; for(m=1;m<8;m++) { x1=(cc+cw)+m*cw; y1=(cr+cw); x2=x1; y2=y1+8*cw;

setcolor(color); line(x1,y1,x2,y2); } for(m=1;m<8;m++) {

x1=(cc+cw); y1=(cr+cw)+m*cw; x2=x1+8*cw; y2=y1;

setcolor(color); line(x1,y1,x2,y2); } }

/********************/ /*整个屏幕外框的绘制*/ /********************/ void win(int a,int b,int c,int d,int bgcolor,char *text,int font,int textcolor) { clscr(a,b,c,d,7); clscr(a+3,b+24,c-3,d-3,bgcolor); clscr(a+3,b+3,c-3,b+20,9);

setcolor(15); line(a,b,c,b); line(a,b,a,d); line(a+2,b+21,c-2,b+21); line(c-2,b+2,c-2,b+21); line(a+2,d-2,c-2,d-2); line(c-2,b+23,c-2,d-2); txt(a+5,b+8,text,font,textcolor);/*调用文字显示函数*/

setcolor(0); line(a,d,c,d); line(c,b,c,d); line(a+3,b+2,c-3,b+2); line(a+2,b+2,a+2,b+20); line(a+2,b+24,a+2,d-2); line(a+2,b+23,c-3,b+23); } /*************************************************************/ /*功能:绘出所在格的提示光标 */ /*(gc,gr)表示当前光标的所在格,(1,1)为的最左上格 */ /*************************************************************/ void gbdw(int gc,int gr,int color) { int x1,y1; x1=(SCCOL+MINBOXSIZE)+(gc-1)*MINBOXSIZE; y1=(SCROW+MINBOXSIZE)+(gr-1)*MINBOXSIZE;

setcolor(color); line(x1+7,y1+7,x1+MINBOXSIZE-7,y1+MINBOXSIZE-7); line(x1+7,y1+MINBOXSIZE-7,x1+MINBOXSIZE-7,y1+7);

}

2004-12-20 18:56
deepblue
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2004-12-15
收藏
得分:0 

/**************************************************************/ /*功能:判断当前是否格可以落子 */ /*(xc,yr)表示当前欲落子的所在格的坐标,(1,1)为可落子的最左上格.*/ /*测试当前方块是否可以放置棋子,可放的话得到present_p_v的值 */ /*val表示欲落子的值,白为1,黑为2 */ /*返回值为int 0或1,0代表不可继续下落 */ /*判断依据:向八个方向依次推进,判断每一个方向的情况 */ /**************************************************************/ int putdown(xc,yr,val) { int a=1,b=1,c=1,d=1,e=1,f=1,g=1,h=1; int a_val=0,b_val=0,c_val=0,d_val=0,e_val=0,f_val=0,g_val=0,h_val=0; int temp=0; if(gril[xc][yr]==0) { if(gril[xc-1][yr-1]==2/val)/*沿左上角向左上上沿*/ { while(gril[xc-a][yr-a]==2/val) { a_val=a_val+gril_value[xc-a][yr-a]; a++; }

if(gril[xc-a][yr-a]==val) present_p_v[xc][yr]=gril_value[xc][yr]+a_val; else a_val=0; }

if(gril[xc][yr-1]==2/val)/*沿正上方向正上方上沿*/ { while(gril[xc][yr-b]==2/val) { b_val=b_val+gril_value[xc][yr-b]; b++; } if(gril[xc][yr-b]==val) present_p_v[xc][yr]=gril_value[xc][yr]+b_val; else b_val=0; }

if(gril[xc+1][yr-1]==2/val)/*沿右上角向右上上沿*/ { while(gril[xc+c][yr-c]==2/val) { c_val=c_val+gril_value[xc+c][yr-c]; c++; }

if(gril[xc+c][yr-c]==val) present_p_v[xc][yr]=gril_value[xc][yr]+c_val; else c_val=0; }

if(gril[xc-1][yr]==2/val)/*沿正左方向向正左方左沿*/ { while(gril[xc-d][yr]==2/val) { d_val=d_val+gril_value[xc-d][yr]; d++; } if(gril[xc-d][yr]==val) present_p_v[xc][yr]=gril_value[xc][yr]+d_val; else d_val=0; }

if(gril[xc+1][yr]==2/val)/*沿正右方向向正右方右沿*/ { while(gril[xc+e][yr]==2/val) { e_val=e_val+gril_value[xc+e][yr]; e++; } if(gril[xc+e][yr]==val) present_p_v[xc][yr]=gril_value[xc][yr]+e_val; else e_val=0; }

if(gril[xc-1][yr+1]==2/val)/*沿左下角向左下角下沿*/ { while(gril[xc-f][yr+f]==2/val) { f_val=f_val+gril_value[xc-f][yr+f]; f++; }

if(gril[xc-f][yr+f]==val) present_p_v[xc][yr]=gril_value[xc][yr]+f_val; else f_val=0;

}

if(gril[xc][yr+1]==2/val)/*沿正下方向正下方下沿*/ { while(gril[xc][yr+g]==2/val) { g_val=g_val+gril_value[xc][yr+g]; g++; } if(gril[xc][yr+g]==val) present_p_v[xc][yr]=gril_value[xc][yr]+g_val; else g_val=0; }

if(gril[xc+1][yr+1]==2/val)/*沿右下角向右下下沿*/ { while(gril[xc+h][yr+h]==2/val) { h_val=h_val+gril_value[xc+h][yr+h]; h++; }

if(gril[xc+h][yr+h]==val) present_p_v[xc][yr]=gril_value[xc][yr]+h_val; else h_val=0; }

} else return 0;

temp=a_val+b_val+c_val+d_val+e_val+f_val+g_val+h_val; if(temp==0) return 0; return 1; }

/*********************************************************/ /*功能:吃掉所落棋子与同色棋子之间别的棋子 */ /*所落棋子为(xr,yr) */ /*val表示欲落子的值,白为1,黑为2 */ /*向八个方向进行查找,吃子。 */ /*********************************************************/ void change_val(int xc,int yr,int val) { int a=1,b=1,c=1,d=1,e=1,f=1,g=1,h=1; int temp=0,color;

if(val==1) color=15; if(val==2) color=0; if(gril[xc-1][yr-1]==2/val)/*沿左上角向左上上沿*/ {

while(gril[xc-a][yr-a]==2/val) { a++; } if(gril[xc-a][yr-a]==val) { for(temp=1;temp<a;temp++) gril[xc-temp][yr-temp]=val; }

}

if(gril[xc][yr-1]==2/val)/*沿正上方向正上方上沿*/ { while(gril[xc][yr-b]==2/val) { b++; } if(gril[xc][yr-b]==val) { for(temp=1;temp<b;temp++) gril[xc][yr-temp]=val; } }

if(gril[xc+1][yr-1]==2/val)/*沿右上角向右上上沿*/ { while(gril[xc+c][yr-c]==2/val) { c++; } if(gril[xc+c][yr-c]==val) { for(temp=1;temp<c;temp++) gril[xc+temp][yr-temp]=val; } }

if(gril[xc-1][yr]==2/val)/*沿正左方向向正左方左沿*/ { while(gril[xc-d][yr]==2/val) { d++; } if(gril[xc-d][yr]==val) { for(temp=1;temp<d;temp++) gril[xc-temp][yr]=val; }

}

if(gril[xc+1][yr]==2/val)/*沿正右方向向正右方右沿*/ { while(gril[xc+e][yr]==2/val) { e++; } if(gril[xc+e][yr]==val) { for(temp=1;temp<e;temp++) gril[xc+temp][yr]=val; }

}

if(gril[xc-1][yr+1]==2/val)/*沿左下角向左下角下沿*/ { while(gril[xc-f][yr+f]==2/val) { f++; }

if(gril[xc-f][yr+f]==val) { for(temp=1;temp<f;temp++) gril[xc-temp][yr+temp]=val; }

}

if(gril[xc][yr+1]==2/val)/*沿正下方向正下方下沿*/ { while(gril[xc][yr+g]==2/val) { g++; } if(gril[xc][yr+g]==val) { for(temp=1;temp<g;temp++) gril[xc][yr+temp]=val; } }

if(gril[xc+1][yr+1]==2/val)/*沿右下角向右下下沿*/ { while(gril[xc+h][yr+h]==2/val) { h++; } if(gril[xc+h][yr+h]==val) { for(temp=1;temp<h;temp++) gril[xc+temp][yr+temp]=val; } }

}

/********************************/ /*功能:游戏中各种提示信息的显示*/ /********************************/ void help_info(char *txt,int color) { clscr(SCCOL,410,500,430,15); setcolor(color); settextstyle(0,0,1);/*设置图形模式下字符显示底字体、方向和大小*/ outtextxy(SCCOL+15,417,txt); /*图形模式下在x,y坐标位置显示一行字符串*/ }

/***************************/ /*功能:延时函数 */ /*t为所延时的长度 */ /***************************/ void wait(int t) { clock_t t2,t1; t2=clock(); t1=clock(); while((t1-t2)<25*t) { t1=clock(); } }

/****************************************************/ /*功能:判断游戏是否结束,并进行得分的统计,判定胜负*/ /****************************************************/ void jud_win() { int x,y; int jud=0;/*表示游戏已经结束*/

num_user=0; num_computer=0; for(x=1;x<=8;x++) { for(y=1;y<=8;y++) { if(gril[x][y]==1) ++num_user; if(gril[x][y]==2) ++num_computer; if(gril[x][y]==0) jud=1; } } if(jud==0)/*游戏已经结束时*/ { if(num_user>num_computer) help_info("You Win! ^_^ Game will Exit! ",4); if(num_user<num_computer) help_info("You Lose! ^_^ Game will Exit! ",0); if(num_user==num_computer)help_info("Dogfall! ^_^ Game will Exit! ",14); wait(4); exit(1);

}

}

/********************************************/ /*****************repaint********************/ /********************************************/ void repaint() { int i=1,j=1; clscr(SCCOL,SCROW,SCCOL+MAXSIZE,SCROW+MAXSIZE,7); outerdraw(SCCOL,SCROW,MINBOXSIZE,8); linedraw(SCCOL,SCROW,MINBOXSIZE,8); for(i=1;i<=8;i++) { for(j=1;j<=8;j++) { if(gril[i][j]==1) minbox(i,j,15); if(gril[i][j]==2) minbox(i,j,0); } } gbdw(gbwzc,gbwzr,12); }

/**********************/ /*游戏打开后第一个屏幕*/ /**********************/ void front_screen() { int il,jl,kl;

clscr(0,0,640,480,15); win(1,1,639,479,BGCOLOR," Welcome to use the programme of deepblue!",1,15);/***windows 绘制***/ txt(192,155,"OTHELO",5,15); txt(190,153,"OTHELO",5,7); txt(205,350,"copyright: deepblue Dec.04",1,7); txt(205,360,"E-mail:fjzhang@yeah.net",1,7); txt(205,370,"Http://56m.net/deepblue",1,7); wait(1); getch();

}

/************************************************/ /*此函数完成程序的程序的主要功能 */ /*在每一个时间片里通过对键盘的监视完成相应的操作*/ /************************************************/ void main_game() { int key,cant=0; /*cant用来判断我是否此时无子可走,cant=0为无子可走*/ int m,n; int big_val[3]={0,0,0}; /*电脑走子时用,用来存目前的最佳位置*/ for(;;) { /*用户走子*/ while(1) /*if(bioskey(1))*/ {

/*******************/ for(m=1;m<=8;m++) { for(n=1;n<=8;n++) { if(putdown(m,n,1)==1) cant=1; } } if(cant==0) { help_info("You have to no chessman to play this time !",BGCOLOR);

wait(2); break; }/*无子可走,给电脑走子*/ cant=0; /*********************/ help_info("It is your turn now !",BGCOLOR); key=bioskey(0); if(key==VK_LEFT) { if(gbwzc>1) { --gbwzc; repaint(); } } if(key==VK_RIGHT) { if(gbwzc<8) { ++gbwzc; repaint(); } } if(key==VK_UP) { if(gbwzr>1) { --gbwzr; repaint(); } } if(key==VK_DOWN) { if(gbwzr<8) { ++gbwzr; repaint(); } }

if(key==VK_SPACE) { if(putdown(gbwzc,gbwzr,1)==1) { gril[gbwzc][gbwzr]=1;/*完成落子*/ repaint(); change_val(gbwzc,gbwzr,1);/*完成落子后的吃子*/ gbwzc=5;/*完成光标的复位*/ gbwzr=5; repaint();

jud_win();/*统计积分,判断胜负及游戏的结束*/

break;/*交换走棋权*/ } } if(key==VK_ESC) { help_info("Do you really want to Exit?(Y/N)",BGCOLOR); again=getch(); if((again=='Y')||(again=='y')) exit(1);

} }

/*电脑走子*/ while(1) {

for(m=1;m<=8;m++) { for(n=1;n<=8;n++) { if(putdown(m,n,2)==1) cant=1; } } if(cant==0) { help_info("The computer have no chessman to play this time !",BGCOLOR); wait(2); break;/*无子可走,给用户走子*/ } cant=0; /*********************/

/************************/ for(m=0;m<=9;m++) { for(n=0;n<=9;n++) { present_p_v[m][n]=0; } } /************************/

for(m=1;m<=8;m++) { for(n=1;n<=8;n++) { putdown(m,n,2); if(big_val[2]<present_p_v[m][n]) {

big_val[0]=m; big_val[1]=n; big_val[2]=present_p_v[m][n]; } } } help_info("It is the turn of computer now !",BGCOLOR); wait(1);

gril[big_val[0]][big_val[1]]=2;/*完成落子*/ repaint(); change_val(big_val[0],big_val[1],2);/*完成落子后的吃子*/ repaint();

jud_win();/*统计积分,判断胜负及游戏的结束*/

big_val[0]=0;big_val[1]=0;big_val[2]=0;/*(复原该值)电脑走子时用,用来存目前的最佳位置*/

break;/*交换走棋权*/

} } }

2004-12-20 18:56
deepblue
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2004-12-15
收藏
得分:0 

void help_fangxiang() { drawmat(zuo16S, 16, 410,110, 15); drawmat(yi16S,16, 425,110, 15); drawmat(you16S, 16, 410,130, 15); drawmat(yi16S,16, 425,130, 15); drawmat(shang16S,16,410,150, 15); drawmat(yi16S, 16, 425,150, 15); drawmat(xia16S, 16, 410,170, 15); drawmat(yi16S, 16, 425,170, 15); drawmat(luo16S, 16, 410,190, 15); drawmat(zi16S, 16, 425,190, 15); drawmat(tui16S, 16, 410,220, 15); drawmat(chu16S, 16, 425,220, 15);

txt(440,115," : Left KEY",1,15); txt(440,135," : Right KEY",1,15); txt(440,155," : Up KEY",1,15); txt(440,175," : Down KEY",1,15); txt(440,195," : Space KEY",1,15); txt(440,225," : Esc KEY",1,15);

}

/*主程序开始*/ void main() { int i,j,color=7;

init(VGA,VGAHI); front_screen(); clscr(0,0,640,480,15); win(1,1,639,479,BGCOLOR," Welcome to use the programmme of deepblue!",1,15);/***windows 绘制***/

repaint();

help_info("*****",BGCOLOR); show_ym(); help_fangxiang(); wait(1); main_game(); getch(); closegraph(); }

2004-12-20 18:57
快速回复:我刚编的黑白棋游戏
数据加载中...
 
   



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

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