C++比大小游戏

devtools/2024/11/13 10:06:20/
x">
xmlns="http://www.w3.org/2000/svg" style="display: none;">

目录

  • 开头
  • 程序
  • 程序的流程图
  • 程序游玩的效果
  • 下一篇博客要说的东西

开头

大家好,我叫这是我58。

程序

#include <iostream>
#include <Windows.h>
using namespace std;
int main() {int ir = 1;char chparr[2] = { 0 };int ip1 = 0;int ip2 = 0;int i = 1;cout << "欢迎你们来玩这个比大小游戏&#xff0c;在这个游戏中&#xff0c;P1只能输入1~8以内的数和未知数X来跟P2的数比大小&#xff0c;P2也只能输入1~8以内的数和未知数X来跟P1的数比大小&#xff0c;这里面的未知数X的规则是&#xff1a;如果对面的数<5&#xff0c;那么未知数X=0&#xff0c;否则未知数X=9&#xff0c;而如果P1的数大于P2的数&#xff0c;那么P1记一分&#xff0c;如果P2的数大于P1的数&#xff0c;那么P2记一分&#xff0c;如果P1的数等于P2的数&#xff0c;那么谁都不记一分&#xff0c;这样的对局一共有三轮&#xff0c;如果P1的分大于P2的分&#xff0c;那么P1胜利&#xff0c;如果P2的分大于P1的分&#xff0c;那么P2胜利&#xff0c;但如果P1的分等于P1的分&#xff0c;那么P1和P2就平局了&#xff0c;你听明白了吗?" << endl << endl;for (; ir < 4; ir++) {system("pause");system("color 07");system("cls");cout << "第" << ir << "局\t" << ip1 << " : " << ip2 << endl;for (i = 1; i < 3; i++) {cout << "1 2 3 4 5 6 7 8 X" << endl << "请P" << i << "输入上面的其中一个数字 -> ";cin >> chparr[i - 1];rewind(stdin);while (!(chparr[i - 1] > '0' && chparr[i - 1] < '9' || 'X' == chparr[i - 1])) {cout << "\033[31;1m输入错误\033[0m&#xff0c;请P" << i << "重新输入上面的其中一个数字 -> ";cin >> chparr[i - 1];rewind(stdin);}chparr[i - 1] -= '0';cout << endl;}cout << endl;for (i = 0; i < 2 && chparr[0] != chparr[1]; i++) {40 == chparr[i] && (chparr[1 - i] < 5 && (chparr[i] = 0), chparr[1 - i] < 5 || (chparr[i] = 9));}if (chparr[0] > chparr[1]) {system("color 02");cout << "P1胜&#xff0c;记一分" << endl;ip1++;}else if (chparr[0] < chparr[1]) {system("color 02");cout << "P2胜&#xff0c;记一分" << endl;ip2++;}else {system("color 08");cout << "平局&#xff0c;无人记分" << endl;}}system("pause");system("color 07");system("cls");cout << ip1 << " : " << ip2 << endl << "最终获胜的人是&#xff1a;";Sleep(1500);if (ip1 > ip2) {system("color 0A");cout << "P1!" << endl;}else if (ip1 < ip2) {system("color 0A");cout << "P2!" << endl;}else {system("color 08");cout << "无人&#xff0c;请再接再厉!" << endl;}return 0;
}

程序的流程图

xmlns="http://www.w3.org/2000/svg" height="3678.51416015625" viewbox="-0.000030517578125 0 4150.38232421875 3678.51416015625" class="mermaid-svg"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x" style="opacity: 1;" id="L-r-x"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x LE-清空缓存区" style="opacity: 1;" id="L-x-清空缓存区"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x" style="opacity: 1;" id="L-aw-ax"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x LE-j" style="opacity: 1;" id="L-ax-j"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"> x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="603.75" height="26">
是(等待用户按下任意一个键&#xff0c;按下后就把背景色设为黑色&#xff0c;前景色设为白色&#xff0c;并清屏)
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="0" height="0">
x" class="edgeLabel L-LS-r' L-LE-x">
x="0" ry="0" width="0" height="0">
x-清空缓存区" class="edgeLabel L-LS-x' L-LE-清空缓存区">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="603.75" height="26">
否(等待用户按下任意一个键&#xff0c;按下后就把背景色设为黑色&#xff0c;前景色设为白色&#xff0c;并清屏)
x="0" ry="0" width="70.65625" height="26">
等待1.5秒
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="0" height="0">
x" class="edgeLabel L-LS-aw' L-LE-ax">
x="0" ry="0" width="0" height="0">
x-j" class="edgeLabel L-LS-ax' L-LE-j">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="16" height="26">
x="0" ry="0" width="0" height="0">
x="0" ry="0" width="16" height="26">
x="23" ry="23" x="-31.75" y="-23" width="63.5" height="46" class="label-container">
开始
x="0" ry="0" x="-40.578125" y="-23" width="81.15625" height="46" class="label-container">
导入io流
x="0" ry="0" x="-64.609375" y="-23" width="129.21875" height="46" class="label-container">
导入Windows.h
定义整型ir为1
把有两个字符的字符数组chparr全都初始化为0
定义整型ip1为0
定义整型ip2为0
定义整型i为1
输出“欢迎你们来玩这个比大小游戏&#xff0c;在这个游戏中&#xff0c;P1只能输入1~8以内的数和未知数X来跟P2的数比大小&#xff0c;P2也只能输入1~8以内的数和未知数X来跟P1的数比大小&#xff0c;这里面的未知数X的规则是&#xff1a;如果对面的数<5&#xff0c;那么未知数X=0&#xff0c;否则未知数X=9&#xff0c;而如果P1的数大于P2的数&#xff0c;那么P1记一分&#xff0c;如果P2的数大于P1的数&#xff0c;那么P2记一分&#xff0c;如果P1的数等于P2的数&#xff0c;那么谁都不记一分&#xff0c;这样的对局一共有三轮&#xff0c;如果P1的分大于P2的分&#xff0c;那么P1胜利&#xff0c;如果P2的分大于P1的分&#xff0c;那么P2胜利&#xff0c;但如果P1的分等于P1的分&#xff0c;那么P1和P2就平局了&#xff0c;你听明白了吗?\​n\​n”
ir < 4?
输出“第”&#xff0c;ir&#xff0c;“局\​t”&#xff0c;ip1&#xff0c;“ : ”ip2&#xff0c;并换行
x="0" ry="0" x="-32.4765625" y="-23" width="64.953125" height="46" class="label-container">
设i为1
i < 3?
输出“1 2 3 4 5 6 7 8 X\​n请P”&#xff0c;i和“输入上面的其中一个数字 -> ”
x-504" transform="translate(654.1054229736328,1652.0203170776367)">
把字符数组chparr的第i减1项设为你输入的内容
x="0" ry="0" x="-50" y="-23" width="100" height="46" class="label-container">
清空缓存区
!(chparr[i - 1] > '0' && chparr[i - 1] < '9' || 'X' == chparr[i - 1])
输出“\​033[31;1m输入错误\​033[0m&#xff0c;请P”&#xff0c;i和“重新输入上面的其中一个数字 -> ”
把字符数组chparr的第i减1项设为你输入的内容
x="0" ry="0" x="-50" y="-23" width="100" height="46" class="label-container">
清空缓存区
x="0" ry="0" x="-206.078125" y="-23" width="412.15625" height="46" class="label-container">
把字符数组chparr的第i减1项自减去字符“0”的ASCII码值
输出“\​n”
x="0" ry="0" x="-32.4765625" y="-23" width="64.953125" height="46" class="label-container">
i自增1
输出“\​n”
x="0" ry="0" x="-32.4765625" y="-23" width="64.953125" height="46" class="label-container">
设i为0
i < 2 && chparr[0] != chparr[1]?
40 == chparr[i]?
chparr[1 - i] < 5?
x="0" ry="0" x="-119.6875" y="-23" width="239.375" height="46" class="label-container">
把字符数组chparr的第i项设为0
chparr[1 - i] < 5?
x="0" ry="0" x="-32.4765625" y="-23" width="64.953125" height="46" class="label-container">
i自增1
chparr[0] > chparr[1]?
x="0" ry="0" x="-138" y="-23" width="276" height="46" class="label-container">
把背景色设为黑色&#xff0c;前景色设为绿色
输出“P1胜&#xff0c;记一分\​n”
x="0" ry="0" x="-41.1328125" y="-23" width="82.265625" height="46" class="label-container">
ip1自增1
x="0" ry="0" x="-35.5859375" y="-23" width="71.171875" height="46" class="label-container">
ir自增1
输出ip1&#xff0c;“ : ”&#xff0c;ip2和“\​n最终获胜的人是&#xff1a;”
ip1 > ip2?
x="0" ry="0" x="-146" y="-23" width="292" height="46" class="label-container">
把背景色设为黑色&#xff0c;前景色设为淡绿色
输出“P1!\​n”
x="23" ry="23" x="-31.75" y="-23" width="63.5" height="46" class="label-container">
结束
ip1 < ip2?
x="0" ry="0" x="-138" y="-23" width="276" height="46" class="label-container">
背景色设为黑色&#xff0c;前景色设为淡绿色
输出“P2!\​n”
x="0" ry="0" x="-138" y="-23" width="276" height="46" class="label-container">
把背景色设为黑色&#xff0c;前景色设为灰色
输出“无人&#xff0c;请再接再厉!\​n”
chparr[0] < chparr[1]?
x="0" ry="0" x="-138" y="-23" width="276" height="46" class="label-container">
把背景色设为黑色&#xff0c;前景色设为绿色
输出“P2胜&#xff0c;记一分\​n”
x="0" ry="0" x="-41.1328125" y="-23" width="82.265625" height="46" class="label-container">
ip2自增1
x="0" ry="0" x="-138" y="-23" width="276" height="46" class="label-container">
把背景色设为黑色&#xff0c;前景色设为灰色
x-552" transform="translate(2099.7447509765625,3077.0156326293945)">
输出“平局&#xff0c;无人记分\​n”
x="0" ry="0" x="-119.6875" y="-23" width="239.375" height="46" class="label-container">
把字符数组chparr的第i项设为9

程序游玩的效果

x" data-report-view="{"spm":"3001.10261","extra":{"id":"uypGIx4Q-1726377887281"}}">

比大小游戏

下一篇博客要说的东西

C++3D迷宫


http://www.ppmy.cn/devtools/113141.html

相关文章

手势识别&手势控制系统-OpenCV&Python(源码和教程)

项目特点 手部手势识别&#xff1a; 项目利用计算机视觉技术来识别手部的各种手势。这种技术可以应用于多种场景&#xff0c;比如人机交互、游戏控制、无障碍技术等。 自定义手势&#xff1a; 用户可以自定义手势&#xff0c;这意味着可以通过训练新的手势模式来扩展系统的功能…

Mybatis-plus-Generator 3.5.5 自定义模板支持 (DTO/VO 等) 配置

随着项目节奏越来越快&#xff0c;为了减少把时间浪费在新建DTO 、VO 等地方&#xff0c;直接直接基于Mybatis-plus 这颗大树稍微扩展一下&#xff0c;在原来生成PO、 DAO、Service、ServiceImpl、Controller 基础新增。为了解决这个问题&#xff0c;网上找了一堆资料&#xff…

【加密社】Solidity 中的事件机制及其应用

加密社 引言 在Solidity合约开发过程中&#xff0c;事件&#xff08;Events&#xff09;是一种非常重要的机制。它们不仅能够让开发者记录智能合约的重要状态变更&#xff0c;还能够让外部系统&#xff08;如前端应用&#xff09;监听这些状态的变化。 本文将详细介绍Solidity中…

数据中台建设(六)—— 数据资产管理

数据资产管理 随着企业数据越来越大&#xff0c;企业意识到数据是一种无形的资产&#xff0c;通过对企业各业务线产生的海量数据进行合理管理和有效应用&#xff0c;能盘活并充分释放数据的巨大价值。如果不能对海量数据进行有效管理和应用&#xff0c;企业堆积如山的数据给企…

day20JS-axios数据通信

1. 什么是axios axios 是一个基于Promise 用于浏览器和 nodejs 的 HTTP 客户端&#xff0c;简单的理解就是ajax的封装&#xff0c;只不过它是Promise的实现版本。 特性&#xff1a; 从浏览器中创建 XMLHttpRequests从 node.js 创建 http 请求支持 Promise API拦截请求和响应转…

初学Linux(学习笔记)

初学Linux&#xff08;学习笔记&#xff09; 前言 本文跳过了Linux前期的环境准备&#xff0c;直接从知识点和指令开始。 知识点&#xff1a; 1.目录文件夹&#xff08;Windows&#xff09; 2.文件内容属性 3.在Windows当中区分文件类型是通过后缀&#xff0c;而Linux是通过…

Java项目: 基于SpringBoot+mybatis+maven校园资料分享平台(含源码+数据库+答辩PPT+毕业论文)

一、项目简介 本项目是一套基于SpringBootmybatismaven校园资料分享平台 包含&#xff1a;项目源码、数据库脚本等&#xff0c;该项目附带全部源码可作为毕设使用。 项目都经过严格调试&#xff0c;eclipse或者idea 确保可以运行&#xff01; 该系统功能完善、界面美观、操作简…

Unity程序基础框架

概述 单例模式基类 没有继承 MonoBehaviour 继承了 MonoBehaviour 的两种单例模式的写法 缓存池模块 &#xff08;确实挺有用&#xff09; using System.Collections; using System.Collections.Generic; using UnityEngine;/// <summary> /// 缓存池模块 /// 知识点 //…