五子棋C语言程序代码.doc
《五子棋C语言程序代码.doc》由会员分享,可在线阅读,更多相关《五子棋C语言程序代码.doc(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、五子棋C语言程序代码#include #include #include void drawPanel();int isWin(int,int);int color = 1; /1-红色 2-白色 int chessman1515;/主函数void main()initgraph(620,620); /产生窗体/画棋盘drawPanel();/画棋子 /1.定义鼠标事件 MOUSEMSG m;HWND wnd = GetHWnd(); /定义当前窗体的句柄while(true)m = GetMouseMsg(); /获取鼠标事件对象if(m.uMsg = WM_LBUTTONDOWN)/获取点
2、击的坐标int x = m.x;int y = m.y;/换算成二维数组中的下标int i = x/40;int j = y/40;/显示点击的坐标/*char msg100;sprintf(msg,%d,%d,i,j);MessageBoxA(wnd,msg,消息,MB_OK);*/if(color=1)setfillstyle(RGB(255,0,0);fillcircle(40*i+20,40*j+20,20);chessmanij = 1;else if(color=2)setfillstyle(RGB(255,255,255);fillcircle(40*i+20,40*j+20,2
3、0);chessmanij = 2;/判断输赢 result = 1int result = isWin(i,j);if(result =1)if(color=1)MessageBoxA(wnd,_T(恭喜,红方获胜!),消息,MB_OK);else if(color=2)MessageBoxA(wnd,_T(恭喜,白方获胜!),消息,MB_OK);break;/切换对方下子color = color = 1 ? 2 : 1 ; getch();closegraph(); /关闭窗体int isWin(int x,int y)int count=0;/计数器int i;/横向for(i=0;i15;i+)if(chessmaniy=color)count+;if(count=5)return 1;elsecount=0;/竖向for(i=0;i15;i+)if(chessmanxi=color)count+;if(count=5)return 1;elsecount=0;return 0; void drawPanel()int i;/画横线for(i=0;i15;i+)line(20,20+40*i,20+14*40,20+40*i);/画竖线for(i=0;i15;i+)line(20+40*i,20,20+40*i,20+14*40);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 五子棋 语言 程序代码
限制150内