(这是一个颜色会变化的呦)

#include <iostream>
using namespace std;
int b[][];
int n;
int m;
void qipan()
{
system("cls");
int k = ;
for (int k = ;k < n;++k)
{
for (int j = ;j < m;++j)
{
cout << " ---- ";
}
cout << endl;
for (int i = ;i < n;++i)
{
for (int j = ;j < m;++j)
{
if (b[i][j] < && b[i][j] >= ) cout << "| " << << b[i][j] << " |";
else if (b[i][j] == -) cout << "| " << "█" << " |";
else if (b[i][j] == -) cout << "|" << " ○ " << "|";
else cout << "| " << b[i][j] << " |"; k++;
} cout << endl;
for (int j = ;j < m;++j)
{
cout << " ---- ";
}
cout << endl;
}
}
}
void success()
{
long time;
for (;;)
{
system("color a");
for (time = ; time < ; time++);
system("color b");
for (time = ; time < ; time++);
system("color c");
for (time = ; time < ; time++);
system("color d");
for (time = ; time < ; time++);
system("color e");
for (time = ; time < ; time++);
system("color f");
for (time = ; time < ; time++);
system("color 0");
for (time = ; time < ; time++);
system("color 1");
for (time = ; time < ; time++);
system("color 2");
for (time = ; time < ; time++);
system("color 3");
for (time = ; time < ; time++);
system("color 4");
for (time = ; time < ; time++);
system("color 5");
for (time = ; time < ; time++);
system("color 6");
for (time = ; time < ; time++);
system("color 7");
for (time = ; time < ; time++);
system("color 8");
for (time = ; time < ; time++);
system("color 9");
}
}
int main()
{
cout << "请选择你们想要的棋盘大小(棋盘的面积请不要大于100)" << endl;
cout << "棋盘的长:(推荐长度为10)" << endl;
cin >> m;
cout << "棋盘的宽:(推荐长度为10)" << endl;
cin >> n;
for (int i = ;i < n;++i)
{
for (int j = ;j < m;++j)
{
b[i][j] = i * m + j;
}
}
qipan();
while ()
{
int x;
cout << "请玩家一输入:" << endl;
cin >> x;
if (x == )
{
cout << "玩家一使用系统外挂" << endl;
cout << "游戏结束" << endl;
cout << "玩家一获胜" << endl;
success();
return ;
}
for (int i = ;i < n;++i)
{
for (int j = ;j < m;++j)
{
if (b[i][j] == x) b[i][j] = -;
}
}
for (int i = ;i < n;++i)
{
for (int j = ;j < m - ;++j)
{
if ((b[i][j] == - && b[i][j + ] == - && b[i][j + ] == - && b[i][j + ] == - && b[i][j + ] == -)
|| (b[i][j] == - && b[i + ][j] == - && b[i + ][j] == - && b[i + ][j] == - && b[i + ][j] == -)
|| (b[i][j] == - && b[i + ][j + ] == - && b[i + ][j + ] == - && b[i + ][j + ] == - && b[i + ][j + ] == -))
{
cout << "游戏结束" << endl;
cout << "玩家一获胜" << endl;
success();
return ;
}
else if (i >= && (b[i][j] == - && b[i - ][j + ] == - && b[i - ][j + ] == - && b[i - ][j + ] == - && b[i - ][j + ] == -))
{
cout << "游戏结束" << endl;
cout << "玩家一获胜" << endl;
success();
return ;
}
}
}
qipan();
cout << "请玩家二输入:" << endl;
cin >> x;
if (x == )
{
cout << "玩家二使用系统外挂" << endl;
cout << "游戏结束" << endl;
cout << "玩家二获胜" << endl;
success();
return ;
}
for (int i = ;i < n;++i)
{
for (int j = ;j < m;++j)
{
if (b[i][j] == x) b[i][j] = -;
}
}
qipan();
for (int i = ;i < n;++i)
{
for (int j = ;j < m - ;++j)
{
if ((b[i][j] == - && b[i][j + ] == - && b[i][j + ] == - && b[i][j + ] == - && b[i][j + ] == -)
|| (b[i][j] == - && b[i + ][j] == - && b[i + ][j] == - && b[i + ][j] == - && b[i + ][j] == -)
|| (b[i][j] == - && b[i + ][j + ] == - && b[i + ][j + ] == - && b[i + ][j + ] == - && b[i + ][j + ] == -))
{
cout << "游戏结束" << endl;
cout << "玩家二获胜" << endl;
success();
return ;
}
else if (i >= && (b[i][j] == - && b[i - ][j + ] == - && b[i - ][j + ] == - && b[i - ][j + ] == - && b[i - ][j + ] == -))
{
cout << "游戏结束" << endl;
cout << "玩家二获胜" << endl;
success();
return ;
}
}
} }
}

用C++基础语句写一个五子棋游戏的更多相关文章

  1. Jmeter使用基础笔记-写一个http请求

    前言 本篇文章主要讲述2个部分: 搭建一个简单的测试环境 用Jmeter发送一个简单的http请求 搭建测试环境 编写flask代码(我参考了开源项目HttpRunner的测试服务器),将如下的代码保 ...

  2. Python 写一个俄罗斯方块游戏

    使用 Python 的 PyGame 库写一个俄罗斯方块游戏的逐步指南 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很多已经做案例的人 ...

  3. JavaScript写一个拼图游戏

    拼图游戏的代码400行, 有点多了, 在线DEMO的地址是:打开: 因为使用canvas,所以某些浏览器是不支持的: you know: 为什么要用canvas(⊙o⊙)?  因为图片是一整张jpg或 ...

  4. 利用C# 窗体设计 写一个抽奖游戏

    老师布置了一个任务,要求我们做一个抽奖游戏,以下是我个人制作的一个作品与写项目的过程. 我们用到了8个pictureBox控件和一个button,设置好大小,并且编排成一个九宫个形状 添加窗体的背景图 ...

  5. python案例:使用if语句实现一个猜拳游戏

    任务要求: 在控制台中提示输入石头.剪刀.布,按回车键,然后给出游戏结果. 分析: 我们知道在游戏规则中,石头克剪刀,剪刀克布,布克石头.但是这在计算机中并不是很好直接的表示,因此我们分别用0.1.2 ...

  6. 【编程教室】PONG - 100行代码写一个弹球游戏

    大家好,欢迎来到 Crossin的编程教室 ! 今天跟大家讲一讲:如何做游戏 游戏的主题是弹球游戏<PONG>,它是史上第一款街机游戏.因此选它作为我这个游戏开发系列的第一期主题. 游戏引 ...

  7. 基于Blazor写一个简单的五子棋游戏

    写这个五子棋游戏,其实主要目的是想尝试一下微软新作Blazor.Blazor对于那些搞.NET的程序员,又想做一些前端工作,真的挺友好,不用一句JS就可搞定前端交互,美哉.现在已经有很流行的前端框架, ...

  8. ajax简单手写了一个猜拳游戏

    使用ajax简单写一个猜拳游戏 HTML代码 <!DOCTYPE HTML> <html lang="en-US"> <head> <me ...

  9. 用javascript实现一个2048游戏

    早就想自己写一个2048游戏了,昨晚闲着没事,终于写了一个 如下图,按方向键开始玩吧. 如果觉得操作不方便,请直接打开链接玩吧: http://gujianbo.1kapp.com/2048/2048 ...

随机推荐

  1. java 之死循环

    public class StringTest { public static void main(String[] args) { System.out.println(getStringCount ...

  2. python中的subprocess.Popen()使用详解---以及注意的问题(死锁)

    从python2.4版本开始,可以用subprocess这个模块来产生子进程,并连接到子进程的标准输入/输出/错误中去,还可以得到子进程的返回值. subprocess意在替代其他几个老的模块或者函数 ...

  3. 02 . Beego框架结构组织,路由及项目初始化

    Beego项目组织结构 conf conf:项目配置文件所在的目录,项目中有一些全局的配置都可以放在此目录下.默认的app.conf文件中默认指定了三个配置: // 1)appname = Beego ...

  4. Python 为什么要有 pass 语句?

    本文出自"Python为什么"系列,请查看全部文章 关于 Python 中的pass语句,它似乎很简单(只有 4 个字母),即使是没有任何编程经验的初学者也能很快地掌握它的用法. ...

  5. Day03_WebCrawler(网络爬虫)

    学于黑马和传智播客联合做的教学项目 感谢 黑马官网 传智播客官网 微信搜索"艺术行者",关注并回复关键词"webcrawler"获取视频和教程资料! b站在线视 ...

  6. 实践录丨如何在鲲鹏服务器OpenEuler操作系统中快速部署OpenGauss数据库

    本文适合需要快速了解OpenGauss基本使用和操作的单机用户,可以短时间内完成安装体验.对于企业级生产使用或者需要部署多台服务器的,不适合本文. 因为业务需要,要在鲲鹏架构里安装单机版的OpenGa ...

  7. Struts2中Get请求转码问题

    Tomcat默认编码为ISO859-1 Post提交时,struts2会对其转码为iso8859-1,因此不需要另外转码,而 Get提交表单,则需要单独转码,转码过程如下图:

  8. React Hook~部分实用钩子

    useCompareEffect /** * useCompareEffect * useEffect只是普通的浅比较,这里做了深比较 * useEffect的依赖是否相同,相同不触发 */ impo ...

  9. Python爬取10000条“爆款剧”——《三十而已》热评,并做可视化

    前言 继<隐秘的角落>后,又一部“爆款剧”——<三十而已>获得了口碑收视双丰收,王漫妮.顾佳.钟晓芹三个女主角的故事线频频登上微博热搜.该剧于2020年7月17日在东方卫视首播 ...

  10. Archlinux 最新安装方法 (2020.07.01-x86_64)之虚拟机 BIOS 安装

    话不多说,直接上干货 准备 去Arch 官网,选择一个合适的国内镜像站下载 Arch 安装包 ISO,地址如下: https://www.archlinux.org/download/ 一.创建虚拟机 ...