c++猜字符游戏
2022/1/8 11:04:02
本文主要是介绍c++猜字符游戏,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
因为上次那个代码在最后投票,200多人看不懂,所以这次出一个简单一点的;
猜字符(规则自己运行程序看);
主要也没什么特殊的东西,应该大部分人都能看懂;
代码:
#include<conio.h> #include<bits/stdc++.h> using namespace std; void init() { system("color F0"); cout<<"_______________________\n"; cout<<"| 查找字符小游戏 |\n"; cout<<"| 按a查看规则, |\n"; cout<<"| 按b开始 |\n"; cout<<"_______________________\n"; } int main() { init(); while (1) { int ch = _getch(); if (ch==97) { cout<<"规则:\n这是一个双人的游戏,\n首先,然后按b开始游戏,玩家A输入一\n串字符,按回车结束,游戏会自动清屏,由玩家B来猜\n(输入单个字符),\n15次中猜中8个则玩家A赢,否则玩家B赢(按c退出)"; } if (ch==99) { system("cls"); init(); } if (ch==98) { system("cls"); cout<<"游戏现在开始"; cout<<endl<<"玩家A输入一串字符(大于15个)"<<endl; string strA; cin>>strA; if (strA.size()<15) { cout<<"请输入15个及以上的字符"; while(true) { cin>>strA; if (strA.size()>=15) { cout<<"输入正确"<<endl; break; } if (strA.size()<15) { cout<<"请输入15个及以上的字符!"; } } } system("cls"); cout<<"玩家B开始猜"; string strB; int strB_s = 0; for (int i=0;i<16;i++) { cin>>strB; int a = strA.find(strB); if (a==-1) { cout<<"查找不到,错误码:"; cout<<string::npos<<endl; } if (a>=0) { cout<<"猜中了!继续猜"<<endl; strB_s++; } if (strB_s>=8) { cout<<"player A is the winner!!!"; break; } if (i==15&&strB_s<8) { cout<<"player B is the winner!!!"; break; } } } } return 0; }
这篇关于c++猜字符游戏的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-28pyqt 怎么打包整个项目-icode9专业技术文章分享
- 2024-09-28laravel Commands 创建带有参数的 Artisan 命令的步骤和示例-icode9专业技术文章分享
- 2024-09-28antd怎么实现渲染tiff图片-icode9专业技术文章分享
- 2024-09-28英文半角中划线和中文全角的中划线有什么区别-icode9专业技术文章分享
- 2024-09-28nvm npm 和node 他们之间有什么关系-icode9专业技术文章分享
- 2024-09-28Node Version Manager (nvm)使用教程-icode9专业技术文章分享
- 2024-09-28nvm命令太慢,是什么原因-icode9专业技术文章分享
- 2024-09-28Kotlin 如何增加、删除和修改 MutableStateFlow 中的值。-icode9专业技术文章分享
- 2024-09-28Kotlin的stateFlow.update 写法介绍-icode9专业技术文章分享
- 2024-09-28kotlin 怎么获取当前时间格式-icode9专业技术文章分享