五子棋C语言程序代码.docx

上传人:小飞机 文档编号:3076078 上传时间:2023-03-10 格式:DOCX 页数:3 大小:36.98KB
返回 下载 相关 举报
五子棋C语言程序代码.docx_第1页
第1页 / 共3页
五子棋C语言程序代码.docx_第2页
第2页 / 共3页
五子棋C语言程序代码.docx_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《五子棋C语言程序代码.docx》由会员分享,可在线阅读,更多相关《五子棋C语言程序代码.docx(3页珍藏版)》请在三一办公上搜索。

1、五子棋C语言程序代码五子棋C语言程序代码 #include #include #include void drawPanel; int isWin(int,int); int color = 1; /1-红色 2-白色 int chessman1515; /主函数 void main /画棋子 /画棋盘 drawPanel; initgraph(620,620); /产生窗体 /1.定义鼠标事件 MOUSEMSG m; HWND wnd = GetHWnd; /定义当前窗体的句柄 while(true) m = GetMouseMsg; /获取鼠标事件对象 if(m.uMsg = WM_LBU

2、TTONDOWN) /获取点击的坐标 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)

3、; fillcircle(40*i+20,40*j+20,20); chessmanij = 2; /判断输赢 result = 1 int result = isWin(i,j); if(result =1) if(color=1) MessageBoxA(wnd,_T(恭喜,红,MB_OK); else if(color=2) 方获胜!),消息 MessageBoxA(wnd,_T(恭喜,白方获胜!),消息,MB_OK); /切换对方下子 color = color = 1 ? 2 : 1 ; break; getch; int isWin(int x,int y) int count=0

4、;/计数器 int i; /横向 for(i=0;i15;i+) closegraph; /关闭窗体 if(chessmaniy=color) count+; if(count=5) return 1; else count=0; /竖向 for(i=0;i15;i+) if(chessmanxi=color) count+; if(count=5) return 1; else count=0; return 0; void drawPanel /画竖线 for(i=0;i15;i+) line(20+40*i,20,20+40*i,20+14*40); int i; /画横线 for(i=0;i15;i+) line(20,20+40*i,20+14*40,20+40*i);

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号