EasyX下载地址

EasyX下载地址

// 五子棋.cpp : 定义控制台应用程序的入口点。
//#include "stdafx.h"
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include<windows.h>
#include <time.h>
#include <string>
#pragma warning(disable:4996)
enum ChessPieceColor {white = 1,blue = 2,/* any your want color here */
};
int x = 25, y = 25;  //初始坐标
int board[21][21] = { 0 };     //棋盘占位数组
void InitGame()  //棋盘初始化
{initgraph(600, 500);setlinecolor(RED);for (int i = 0; i < 20; i++){line(0, i * 25, 500, i * 25);line(i * 25, 0, i * 25, 500);}setlinestyle(PS_SOLID, 2);  //画实线 宽度2line(500, 0, 500, 500);outtextxy(512, 60, _T("玩家1:白棋"));outtextxy(512, 180, _T("W,A,S,D移动"));outtextxy(512, 210, _T("G键下棋子"));outtextxy(512, 120, _T("玩家2:蓝棋"));setfillcolor(WHITE);  //棋盘白字初始位置board[1][1] = 1;solidcircle(x, y, 12);}int flag = 1;   //标记下棋状态
char key;       //检测键盘按键void InitMove()     //棋子移动初步判断部分
{switch (key) {case 'w': //上 y -= 25;break;case 's': //下 y += 25;break;case 'a'://左 x += 25;break;case 'd': //右 x -= 25;break;default:break;}if (x < 0)x = 500;if (y > 500)y = 0;if (x > 500)x = 0;if (y < 0)y = 500;}//判断获胜条件
int judge(int a, int b)
{int i, j;int t = 2 - flag % 2;for ((i = a - 4) && (j = b); i <= a; i++)  //横向{if (i >= 1 && i < 16 && t == board[i][j] && t == board[i + 1][j] && t == board[i + 2][j] && t == board[i + 3][j] && t == board[i + 4][j])return 1;}for ((i = a) && (j = b - 4); j <= a; j++)   //竖向{if (j >= 1 && j < 16 && t == board[i][j] && t == board[i][j + 1] && t == board[i][j + 2] && t == board[i][j + 3] && t == board[i][j + 4])return 1;}for ((i = a - 4) && (j = b - 4); ((i <= a) && (j >= b)); i++, j++)   //斜下{if (i >= 1 && i < 16 && j >= 1 && j < 16 && t == board[i][j] && t == board[i + 1][j + 1] && t == board[i + 2][j + 2] && t == board[i + 3][j + 3] && t == board[i + 4][j + 4])return 1;}for ((i = a - 4) && (j = b + 4); ((i <= a) && (j >= b)); i++, j--)   //斜上{if (i >= 1 && i < 16 && j >= 1 && j < 16 && t == board[i][j] && t == board[i + 1][j - 1] && t == board[i + 2][j - 2] && t == board[i + 3][j - 3] && t == board[i + 4][j - 4])return 1;}
}
// 棋子的英文怎么拼 baby
void DrawChessPieces(short x, short y, ChessPieceColor color) {switch (color) {case ChessPieceColor::blue: {setfillcolor(BLUE);break;}case ChessPieceColor::white: {setfillcolor(WHITE);break;}}solidcircle(x, y, 12);
}//void Move()   //棋子移动,以及该位置是否有棋子检测,并按G下棋
//{
//  setfillcolor(BLACK);        //消除上一步光标
//  solidcircle(x, y, 12);
//  key = getchar();
//  InitMove();
//  while (board[x / 25][y / 25] = 1)InitMove();//如果已经有棋子则跳转到下一个位置
//  if (flag % 2 == 1) { setfillcolor(WHITE); };//根据flag数判断棋子颜色
//  if (flag % 2 == 0) { setfillcolor(BLUE); };
//  solidcircle(x, y, 12);
//  if (getchar() == 'g' || 'G')
//  {
//      board[x / 25][y / 25] = 1;
//      if (judge(x / 25, y / 25))         //每下完一次之后进行胜负判断
//      {
//          if (1 == flag % 2)
//          {
//              outtextxy(512, 400, _T("玩家2胜利"));
//
//              return;
//          }
//          else
//          {
//              outtextxy(512, 60, _T("玩家胜利"));
//              return;
//          }
//      }
//      //如果没有结束,跳转到下一个棋子的位置
//      InitMove();
//      while (board[x / 25][y / 25] = 1)InitMove();
//  }
//
//
//
//
//  flag++;
//  if (flag % 2 == 1) { setfillcolor(WHITE); };//根据flag数判断棋子颜色
//  if (flag % 2 == 0) { setfillcolor(BLUE); };
//  solidcircle(x, y, 12);
//
//}
MOUSEMSG m; int k;
bool judgeEdge(int x, int y) {if (x >= 1 && x < 19 && y >= 1 && y < 19) {return true;}else {return false;}
}bool judgeWin(int x,int y, ChessPieceColor color) {int judgeX = x;int judgeY = y;int ChessPieces = 1;bool flag = false;{{int judgeX = x;int judgeY = y;// 横向 向左judgeX--;while (board[judgeX][judgeY] == color) {ChessPieces++;// 如果满足边界if (judgeEdge(judgeX, judgeY)) {judgeX--;}// 不满足直接退出else {break;}}// 横向 向右judgeX = x + 1;while (board[judgeX][judgeY] == color) {ChessPieces++;// 如果满足边界if (judgeEdge(judgeX, judgeY)) {judgeX++;}// 不满足直接退出else {break;}}if (ChessPieces >= 5) {flag = true;}else {ChessPieces = 1;}}{// 横向 向左judgeY--;while (board[judgeX][judgeY] == color) {ChessPieces++;// 如果满足边界if (judgeEdge(judgeX, judgeY)) {judgeY--;}// 不满足直接退出else {break;}}// 横向 向右judgeY = y + 1;while (board[judgeX][judgeY] == color) {ChessPieces++;// 如果满足边界if (judgeEdge(judgeX, judgeY)) {judgeY++;}// 不满足直接退出else {ChessPieces = 1;}}if (ChessPieces >= 5) {flag = true;}else {ChessPieces = 1;}}{int judgeX = x;int judgeY = y;// 横向 向左judgeY--;judgeX--;while (board[judgeX][judgeY] == color) {ChessPieces++;// 如果满足边界if (judgeEdge(judgeX, judgeY)) {judgeY--;judgeX--;}// 不满足直接退出else {break;}}// 横向 向右judgeY = y + 1;judgeX = x + 1;while (board[judgeX][judgeY] == color) {ChessPieces++;// 如果满足边界if (judgeEdge(judgeX, judgeY)) {judgeY++;judgeX++;}// 不满足直接退出else {ChessPieces = 1;}}if (ChessPieces >= 5) {flag = true;}else {ChessPieces = 1;}}{int judgeX = x;int judgeY = y;// 横向 向左judgeY++;judgeX--;while (board[judgeX][judgeY] == color) {ChessPieces++;// 如果满足边界if (judgeEdge(judgeX, judgeY)) {judgeY++;judgeX--;}// 不满足直接退出else {break;}}// 横向 向右judgeY = y - 1;judgeX = x + 1;while (board[judgeX][judgeY] == color) {ChessPieces++;// 如果满足边界if (judgeEdge(judgeX, judgeY)) {judgeY--;judgeX++;}// 不满足直接退出else {ChessPieces = 1;}}if (ChessPieces >= 5) {flag = true;}else {ChessPieces = 1;}}}return flag;}void Move()   //鼠标点击下棋
{int x, y;m = GetMouseMsg();if (m.mkLButton == 1)    //点击下棋{char msg[200];sprintf(msg, "x=%d,y=%d", m.x, m.y);// MessageBoxA(NULL, msg, "鼠标在哪儿", NULL);/*MessageBoxA(NULL, msg, "鼠标在哪儿", NULL);*//*  被你气死得 for什么for*/// x=0,y=0             x=25,y=25/*int x = m.x % 25 >12;int y = m.y % 25;*/int x = m.x / 25;int y = m.y / 25;int offsetX = m.x % 25 <= 12 ? 0 : 25;int offsetY = m.y % 25 <= 12 ? 0 : 25;x *= 25;y *= 25;x += offsetX;y += offsetY;if (x <= 500 && y <= 500 && x >= 0 && y >= 0) {int boardX = x / 25;int boardY = y / 25;if (!board[boardX][boardY]) {if (flag) {DrawChessPieces(x, y, ChessPieceColor::blue);board[boardX][boardY] = ChessPieceColor::blue;bool winFlag = judgeWin(boardX, boardY, ChessPieceColor::blue);if (winFlag) {MessageBoxA(NULL, "WIN", "", NULL);}flag = false;}else {DrawChessPieces(x, y, ChessPieceColor::white);board[boardX][boardY] = ChessPieceColor::white;bool winFlag = judgeWin(boardX, boardY, ChessPieceColor::white);if (winFlag) {MessageBoxA(NULL, "WIN", "", NULL);}flag = true;}}}/*if (m.x >= x && m.x <= (x + 25) && m.y >= y && y <= (y + 25))*///for (x = 12; x < 600; x += 25)//   for (y = 12; y < 500; y += 25)//  {//     if (m.x >= x && m.x <= (x + 25) && m.y >= y && y <= (y + 25))//       {//         if (board[(x + 13) / 25][(y + 13) / 25] = 0)     //判断该位置是否有棋子//          {//             if (flag % 2 == 1) { setfillcolor(WHITE); };//根据flag数判断棋子颜色//             if (flag % 2 == 0) { setfillcolor(BLUE); };//             solidcircle(x + 13, y + 13, 12);//                board[(x + 13) / 25][(y + 13) / 25] = 1;//               flag++;//         }//     }// }}FlushMouseMsgBuffer();//if (judge(x / 25, y / 25))         //每下完一次之后进行胜负判断//{//   if (1 == flag % 2)//  {//     k = 1;//       outtextxy(512, 400, _T("玩家2胜利"));//       return;//   }// else//  {//     k = 1;//       outtextxy(512, 60, _T("玩家胜利"));//     return;//   }//}}void main()
{InitGame();while (1)Move();}

基于EasyX 的五子棋小游戏。相关推荐

  1. 基于 Blazor 开发五子棋小游戏

    今天是农历五月初五,端午节.在此,祝大家端午安康! 端午节是中华民族古老的传统节日之一.端午也称端五,端阳.此外,端午节还有许多别称,如:午日节.重五节.五月节.浴兰节.女儿节.天中节.地腊.诗人节. ...

  2. c语言五子棋学年论文,基于c语言五子棋小游戏生本科论文.doc

    基于c语言五子棋小游戏生本科论文 五子棋小游戏 需求分析 现在有越来越多的人使用电脑,而且五子棋的受众广泛但实体棋操作较为繁琐且平时较难实现,所以电脑版的五子棋游戏应运而生.大家对于这个小游戏的需求如 ...

  3. 基于控制台的五子棋小游戏(简易)

    基于控制台的五子棋小游戏(简易) 展示 源码: 使用: GoBang类: 展示 话不多说上代码 Don't talk much, say the code! 源码: 使用: new完直接运行 publ ...

  4. 基于flask的五子棋小游戏

    基于flask的五子棋小游戏 前言 ​ 首先说明一下,本人方向是java后端,只因老师布置了一个作业,要用flask来做一个五子棋,没办法被逼上梁山,程序不太美观,但是应付作业还是够了的. ​ 废话不 ...

  5. 【Verilog】基于FPGA的五子棋小游戏(VGA显示、双人对战、胜负判别、附完整代码)

    基于FPGA的五子棋小游戏 有一些说明: 1.本文是基于VGA的显示小游戏,主要为VGA显示的拓展应用: 2.为适应不同显示屏的分辨率,棋盘确定为10X10的黑线白底的方格: 3.下棋主要用棋格颜色变 ...

  6. c语言五子棋对局结果存储,基于C语言五子棋小游戏总结.doc

    五子棋小游戏 需求分析 现在有越来越多的人使用电脑,而且五子棋的受众广泛但实体棋操作较为繁琐且平时较难实现,所以电脑版的五子棋游戏应运而生.大家对于这个小游戏的需求如下:首先,设计这个游戏最基本的就是 ...

  7. c语言五子棋毕业设计,基于c语言五子棋小游戏--本科生毕业设计.doc

    五子棋小游戏 需求分析 现在有越来越多的人使用电脑,而且五子棋的受众广泛但实体棋操作较为繁琐且平时较难实现,所以电脑版的五子棋游戏应运而生.大家对于这个小游戏的需求如下:首先,设计这个游戏最基本的就是 ...

  8. 基于深度学习的一款五子棋小游戏

    今天分享一个基于深度学习而开发的AI小游戏 简单介绍 这一款基于深度学习的五子棋小游戏的界面是使用Unity开发的,而网络结构是使用keras搭建的. 环境 笔者的环境如下 操作系统 windows ...

  9. 基于EasyX的五子棋游戏

    基于EasyX的五子棋游戏 一.预备知识 二.游戏逻辑 1.五子棋元素 2.五子棋规则 三.游戏设计 1.地图设计 2.点击设计 3.结束设计 4.整体设计 一.预备知识 1.使用EasyX必须要知道 ...

最新文章

  1. 在Ubuntu 16.04.4 LTS上调研开源QUIC项目ngtcp2
  2. 风险案例-25期-与有过合作经历客户在新合同约定中过于简单、范围不明确,导致客户对新需求工作量不认可...
  3. 每天一道LeetCode-----重排链表,节点顺序是从头取一个,从尾取一个,从头取一个,从尾取一个.....
  4. 【FPGA】相关介绍
  5. 【深度好文】过了30岁,做技术开发、工程师还有前途吗?
  6. AspNet Core 6.0 Json写默认首字母小写(camelCase)问题
  7. Ajax全接触(1)
  8. 计算机视觉论文-2021-06-22
  9. java基础—统计一个字符串中各个字符出现的次数
  10. 记录一次配置unix网络编程环境的过程和遇到的问题
  11. 阿里架构师必学的2019最新资料!首次公布
  12. 怎么把音频转换成mp3格式?
  13. 大数据实战第十二课之-Scala知识05
  14. CentOS7离线安装Cloudera Manager 5.14.1
  15. 十进制转二进制,短除法与位运算两种方法
  16. 王者荣耀觉悟系列(简介)
  17. 如何给 SAP UI5 SmartField 添加 Value Help 功能试读版
  18. Pycharm如何改变背景教程
  19. 八皇后-n皇后-2n皇后
  20. word打印“错误!未找到引用源”的解决办法

热门文章

  1. 深信服科技 数据防泄漏DLP解决方案
  2. dopdf——pdf生成工具
  3. 基于JAVA智能拼车系统计算机毕业设计源码+系统+mysql数据库+lw文档+部署
  4. ASEMI教你如何选择合适的KBP310整流桥
  5. 计算机科学与技术核心课程
  6. 马甲神功之android版
  7. 设备驱动的兼容性,例如cpu_to_le16函数
  8. 使用PreScan构建交通场景——轨迹同步
  9. python实现动态爱心
  10. 电脑不小心删除的文件怎么恢复?