首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

C++与easyx实现双人象棋

游戏开发 31.38MB 19 需要积分: 1
立即下载

资源介绍:

C++与easyx实现双人象棋
#include #include #include #include using namespace std; int operate = 0, operatex, operatey, signx, signy; bool judge_red_white=0; //设置逻辑棋盘 int ChessBoard[12][11] = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,1,2,3,4,5,4,3,2,1,-1, -1,0,0,0,0,0,0,0,0,0,-1, -1,0,6,0,0,0,0,0,6,0,-1, -1,7,0,7,0,7,0,7,0,7,-1, -1,0,0,0,0,0,0,0,0,0,-1, -1,0,0,0,0,0,0,0,0,0,-1, -1,8,0,8,0,8,0,8,0,8,-1, -1,0,9,0,0,0,0,0,9,0,-1, -1,0,0,0,0,0,0,0,0,0,-1, -1,10,11,12,13,14,13,12,11,10,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, }; void DrawForesign(int x, int y, bool a, bool b)//绘制准星线条 { if (a == 1) { line(x - 5, y - 5, x - 5, y - 25); line(x - 5, y - 5, x - 25, y - 5); line(x - 5, y + 5, x - 5, y + 25); line(x - 5, y + 5, x - 25, y + 5); } if (b == 1) { line(x + 5, y - 5, x + 5, y - 25); line(x + 5, y - 5, x + 25, y - 5); line(x + 5, y + 5, x + 5, y + 25); line(x + 5, y + 5, x + 25, y + 5); } } static void DrawChessBoard()//绘制棋盘 { setcolor(RGB(255, 102, 102)); for (int i = 45; i <= 855; i += 90) {//横线绘制 line(45, i, 765, i); } for (int i = 45; i <= 765; i += 90) {//竖线绘制 if (i == 45 || i == 765) { line(i, 45, i, 855); } else { line(i, 45, i, 405); line(i, 495, i, 855); } } //大边框绘制 line(42, 42, 42, 858); line(42, 858, 768, 858); line(768, 858, 768, 42); line(768, 42, 42, 42); //绘制九宫 line(315, 45, 495, 225); line(495, 45, 315, 225); line(315, 675, 495, 855); line(495, 675, 315, 855); //绘制兵准星 for (int i = 0; i <= 8; i += 2) { if (i == 0) { DrawForesign(45 + i * 90, 315, 0, 1); DrawForesign(45 + i * 90, 585, 0, 1); } else if (i == 8) { DrawForesign(45 + i * 90, 315, 1, 0); DrawForesign(45 + i * 90, 585, 1, 0); } else { DrawForesign(45 + i * 90, 315, 1, 1); DrawForesign(45 + i * 90, 585, 1, 1); } } //绘制炮准星 DrawForesign(135, 225, 1, 1); DrawForesign(675, 225, 1, 1); DrawForesign(135, 675, 1, 1); DrawForesign(675, 675, 1, 1); } void DrawChessman(int x, int y, char *a,bool object) //绘制单个棋子 { if (object) { setcolor(WHITE); setfillcolor(BLACK); fillcircle(x, y, 34); fillcircle(x, y, 28); setcolor(RGB(255,102,102)); settextstyle(30, 23, "宋体"); outtextxy(x - 23, y - 14, a); } else { setcolor(WHITE); setfillcolor(BLACK); fillcircle(x, y, 34); fillcircle(x, y, 28); settextstyle(30, 23, "宋体"); outtextxy(x - 23, y - 14, a); } } static void DrawALLChessman() //绘制所有棋子 { for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 9; j++) { if (ChessBoard[i][j] == 1) { char ChessArr[] = "车"; DrawChessman(j * 90 - 45, i * 90 - 45, ChessArr, 0); } if (ChessBoard[i][j] == 2) { char ChessArr[] = "马"; DrawChessman(j * 90 - 45, i * 90 - 45, ChessArr, 0); } if (ChessBoard[i][j] == 3) { char ChessArr[] = "象"; DrawChessman(j * 90 - 45, i * 90 - 45, ChessArr, 0); } if (ChessBoard[i][j] == 4) { char ChessArr[] = "士"; DrawChessman(j * 90 - 45, i * 90 - 45, ChessArr, 0); } if (ChessBoard[i][j] == 5) { char ChessArr[] = "将"; DrawChessman(j * 90 - 45, i * 90 - 45, ChessArr, 0); } if (ChessBoard[i][j] == 6) { char ChessArr[] = "炮"; DrawChessman(j * 90 - 45, i * 90 - 45, ChessArr, 0); } if (ChessBoard[i][j] == 7) { char ChessArr[] = "卒"; DrawChessman(j * 90 - 45, i * 90 - 45, ChessArr, 0); } if (ChessBoard[i][j] == 8) { char ChessArr[] = "兵"; DrawChessman(j * 90 - 45, i * 90 - 45, ChessArr, 1); } if (ChessBoard[i][j] == 9) { char ChessArr[] = "炮"; DrawChessman(j * 90 - 45, i * 90 - 45, ChessArr, 1); } if (ChessBoard[i][j] == 10) { char ChessArr[] = "车"; DrawChessman(j * 90 - 45, i * 90 - 45, ChessArr, 1); } if (ChessBoard[i][j] == 11) { char ChessArr[] = "马"; DrawChessman(j * 90 - 45, i * 90 - 45, ChessArr, 1); } if (ChessBoard[i][j] == 12) { char ChessArr[] = "相"; DrawChessman(j * 90 - 45, i * 90 - 45, ChessArr, 1); } if (ChessBoard[i][j] == 13) { char ChessArr[] = "士"; DrawChessman(j * 90 - 45, i * 90 - 45, ChessArr, 1); } if (ChessBoard[i][j] == 14) { char ChessArr[] = "帅"; DrawChessman(j * 90 - 45, i * 90 - 45, ChessArr, 1); } } } } bool JudgeGuideline(int x1, int y1, int x2, int y2) //判断棋子下法是否正确 { //判断不能吃自己的子 if (ChessBoard[x2][y2] > 0) { if (ChessBoard[x2][y2] < 8 && ChessBoard[x1][y1] < 8)return 0; if (ChessBoard[x2][y2] > 7 && ChessBoard[x1][y1] > 7)return 0; } //车的走法 if (ChessBoard[x1][y1] == 1||ChessBoard[x1][y1]==10) { if (x1 == x2 && y1 != y2) { for (int i = min(y1, y2)+1; i < max(y1, y2); i++) { if (ChessBoard[x1][i] > 0)return 0; } return 1; } else if (x1 != x2 && y1 == y2) { for (int i = min(x1, x2)+1; i < max(x1, x2); i++) { if (ChessBoard[i][y1] > 0)return 0; } return 1; }else { return 0; } } //马的走法 if (ChessBoard[x1][y1]==2||ChessBoard[x1][y1]==11) { if (x1 - x2 == 2 && (y1 - y2 == 1 || y1 - y2 == -1)) { if (ChessBoard[x1 - 1][y1] > 0)return 0; else return 1; } else if (x2 - x1 == 2 && (y1 - y2 == 1 || y1 - y2 == -1)) { if (ChessBoard[x1 + 1][y1] > 0)return 0; else return 1; } else if (y2 - y1 == 2 && (x1 - x2 == 1 || x1 - x2 == -1)) { if (ChessBoard[x1][y1 + 1] > 0)return 0; else return 1; } else if (y2 - y1 == -2 && (x1 - x2 == 1 || x1 - x2 == -1)) { if (ChessBoard[x1][y1 - 1] > 0)return 0; else return 1; } else { return 0; } } //炮的走法 if (ChessBoard[x1][y1] == 6 || ChessBoard[x1][y1] == 9) { if (ChessBoard[x2][y2] == 0) { if (x1 == x2 && y1 != y2) { for (int i = min(y1, y2)+1; i < max(y1, y2); i++) { if (ChessBoard[x1][i] > 0)return 0; } return 1; } else if (x1 != x2 && y1 == y2) { for (int i = min(x1, x2)+1; i < max(x1, x2); i++) { if (ChessBoard[i][y1] > 0)return 0; } return 1; } else { return 0; } } else { if (x1 == x2 && y1 != y2) { int temp = 0; for (int i = min(y1, y2) + 1; i < max(y1, y2); i++) { if (ChessBoard[x1][i] > 0)temp++; } if (temp == 1)return 1; else return 0; } else if(x1 != x2 && y1 == y2){ int temp = 0; for (int i = min(x1, x2) + 1; i < max(x1, x2); i++) { if (ChessBoard[i][y1] > 0)temp++; } if (temp == 1)return 1; else return 0; } else { return 0; } } } //卒的走法 if (ChessBoard[x1][y1] == 7) { if (x1 < 6) { if (y1 == y2 && x2 - x1 == 1)return 1; else return 0; } else { if (x1 == x2 && (y1 - y2 == 1 || y2 - y1 == 1))return 1; else if (x2 - x1 == 1 && y1 == y2)return 1; else return 0; } } //兵的走法 if (ChessBoard[x1][y1] == 8) { if (x1 > 5) { if (y1 == y2 && x2 - x1 == -1)return 1; else return 0; } else { if (x1 == x2 && (y1 - y2 == 1 || y2 - y1 == 1))return 1; else if (x2 - x1 == -1 && y1 == y2)return 1; else return 0; } } //象的走法 if (ChessBoard[x1][y1] == 3) { if (x2 < 6) { if ((x1 - x2 == 2 || x2 - x1 == 2) && (y1 - y2 == 2 || y2 - y1 == 2)) { if (ChessBoard[(x1 + x2) / 2][(y1 + y2) / 2] == 0)return 1; else return 0; } else return 0; } else return 0; } //相的走法 if (ChessBoard[x1][y1] == 12) { if (x2 > 5) { if ((x1 - x2 == 2 || x2 - x1 == 2) && (y1 - y2 == 2 || y2 - y1 == 2)) { if (ChessBoard[(x1 + x2) / 2][(y1 + y2) / 2] == 0)return 1; else return 0; } else return 0; } else return 0; } //黑士走法 if (ChessBoard[x1][y1] == 4) { if ((x2 >= 1 && x2 <= 3) && (y2 <= 6 && y2 >= 4)) { if ((x2 - x1 == 1 || x1 - x2 == 1) && (y1 - y2 == 1 || y2 - y1 == 1)) { return 1; }

资源文件列表:

Chess.zip 大约有42个文件
  1. Chess/.vs/
  2. Chess/.vs/Chess/
  3. Chess/.vs/Chess/FileContentIndex/
  4. Chess/.vs/Chess/FileContentIndex/1456be53-20b3-4e93-9d1f-600bbad10565.vsidx 10.11KB
  5. Chess/.vs/Chess/FileContentIndex/645dc446-f26d-448a-966a-dae8fd6ce198.vsidx 7.63KB
  6. Chess/.vs/Chess/v17/
  7. Chess/.vs/Chess/v17/.suo 26KB
  8. Chess/.vs/Chess/v17/Browse.VC.db 37.6MB
  9. Chess/.vs/Chess/v17/DocumentLayout.json 1.42KB
  10. Chess/.vs/Chess/v17/ipch/
  11. Chess/.vs/Chess/v17/ipch/AutoPCH/
  12. Chess/.vs/Chess/v17/ipch/AutoPCH/a82cb7300c4490e6/
  13. Chess/.vs/Chess/v17/ipch/AutoPCH/a82cb7300c4490e6/FILENAME.ipch 81.06MB
  14. Chess/.vs/Chess/v17/Solution.VC.db 428KB
  15. Chess/Chess.sln 1.4KB
  16. Chess/Chess/
  17. Chess/Chess/Chess.vcxproj 6.47KB
  18. Chess/Chess/Chess.vcxproj.filters 970B
  19. Chess/Chess/Chess.vcxproj.user 168B
  20. Chess/Chess/FileName.cpp 11.83KB
  21. Chess/Chess/x64/
  22. Chess/Chess/x64/Debug/
  23. Chess/Chess/x64/Debug/Chess.exe.recipe 300B
  24. Chess/Chess/x64/Debug/Chess.ilk 3.13MB
  25. Chess/Chess/x64/Debug/Chess.log 81B
  26. Chess/Chess/x64/Debug/Chess.tlog/
  27. Chess/Chess/x64/Debug/Chess.tlog/Chess.lastbuildstate 167B
  28. Chess/Chess/x64/Debug/Chess.tlog/CL.command.1.tlog 722B
  29. Chess/Chess/x64/Debug/Chess.tlog/Cl.items.tlog 125B
  30. Chess/Chess/x64/Debug/Chess.tlog/CL.read.1.tlog 33.39KB
  31. Chess/Chess/x64/Debug/Chess.tlog/CL.write.1.tlog 516B
  32. Chess/Chess/x64/Debug/Chess.tlog/link.command.1.tlog 1.23KB
  33. Chess/Chess/x64/Debug/Chess.tlog/link.read.1.tlog 2.9KB
  34. Chess/Chess/x64/Debug/Chess.tlog/link.secondary.1.tlog 134B
  35. Chess/Chess/x64/Debug/Chess.tlog/link.write.1.tlog 376B
  36. Chess/Chess/x64/Debug/FileName.obj 117.93KB
  37. Chess/Chess/x64/Debug/vc143.idb 355KB
  38. Chess/Chess/x64/Debug/vc143.pdb 468KB
  39. Chess/x64/
  40. Chess/x64/Debug/
  41. Chess/x64/Debug/Chess.exe 153.5KB
  42. Chess/x64/Debug/Chess.pdb 5.85MB
0评论
提交 加载更多评论
其他资源 暨大线上试题复习资料0706.zip
暨大线上试题复习资料0706.zip
暨大线上试题复习资料0706.zip 暨大线上试题复习资料0706.zip 暨大线上试题复习资料0706.zip
答题卡识别系统代码+报告
数字图像处理实训基于OpenCV的答题卡识别系统代码+报告,使用PYQT5创建GUI界面,可实现简单的用户交互
答题卡识别系统代码+报告 答题卡识别系统代码+报告 答题卡识别系统代码+报告
最新版抖音查投诉运营源码
新版抖音查投诉源码
《Python 程序设计开发案例教程》
《Python 程序设计开发案例教程》各章节实例,仅供参考
拼图游戏,C++与easyx实现
拼图游戏,C++与easyx实现
bugreport-2024-07-14-140100.zip
bugreport-2024-07-14-140100.zip
高一化学暑假作业-选择性必修1化学反应原理导学.zip
高一化学暑假作业-选择性必修1化学反应原理导学.zip
Dev-Cpp-5.11-Setup(二次压缩版)
Dev-Cpp-5.11-Setup(二次压缩版)