根据c的猜拳游戏.doc

上传人:小** 文档编号:4482340 上传时间:2021-09-25 格式:DOC 页数:13 大小:49.50KB
返回 下载 相关 举报
根据c的猜拳游戏.doc_第1页
第1页 / 共13页
根据c的猜拳游戏.doc_第2页
第2页 / 共13页
点击查看更多>>
资源描述

《根据c的猜拳游戏.doc》由会员分享,可在线阅读,更多相关《根据c的猜拳游戏.doc(13页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、,#include#include #include using namespace std;void show(int input)switch(input)case 1:cout(出的是石头!);break;case 2:cout(出的是剪刀!);break;case 3:cout(出的是布!);break;default:;void compare(int inputPlay,int inputComputer)if(inputPlay=1&inputComputer=2|inputPlay=2&inputComputer=3|inputPlay=3&inputComputer=1)co

2、ut(n玩家胜!n);else if(inputPlay=inputComputer)cout(n平局!n);elsecout(n电脑胜!n);int main()cout欢迎您玩 石头-剪子-布 游戏(游戏作者:张龙) 版本 1.0nendl; cout请合理安排时间,切勿沉迷于游戏!nendl;cout游戏说明:数字1代表石头 数字2代表剪子 数字3代表布nendl; char isGoOn;int inputPlay;int inputComputer;cout(猜拳游戏n);cout(游戏说明:nn);cout(数字1代表石头 数字2代表剪子 数字3代表布n);srand(time(N

3、ULL); docoutinputPlay;if(inputPlay=0&inputPlay=3)cout(您);show(inputPlay);inputComputer=rand()%3;cout(电脑);show(inputComputer);compare(inputPlay,inputComputer);elsecout(您输入有错误!n);cout(n数字1代表石头 数字2代表剪子 数字3代表布n);coutisGoOn; while(isGoOn=y|isGoOn=Y); cout欢迎下次再玩!; system(pause); #include #include using na

4、mespace std; int win_or_loss(int);/判断输赢的子函数 void baoshi(time_t&);/给出当前系统时间的子函数 void keep_window_open();/让程序运行完毕后,窗口不立马消失 int main() time_t the_time_1,the_time_2; char q; int win(0),loss(0),ping(0); double gailv(0),sum(0); cout欢迎您玩 石头-剪子-布 游戏(游戏作者:张龙) 版本 1.1nendl; cout请合理安排时间,切勿沉迷于游戏!nendl; baoshi(th

5、e_time_1); cout游戏说明:数字1代表石头 数字2代表剪子 数字3代表布nendl; do coutn请问您一共想要玩几次猜拳游戏,请输入大于0的正整数(建议您至少玩十次):times) cout您的输入不合法,必须为一个数字,请重新输入:endl; cin.clear(); cin.sync(); if(times=0) cout您的输入不合法,必须为正整数!nendl; cin.clear(); cin.sync(); q=y; continue; else if(times!=int(times) cout您的输入不合法,必须为正整数!nendl; cin.clear();

6、cin.sync(); q=y; continue; /游戏正式开始 for(int i=0;itimes;+i) coutn请输入您打算猜的拳(用数字123代替,数字1代表石头 数字2代表剪子 数字3代表布)t; if(cin.bad() cerrSorry,出现了系统故障,请重新运行游戏!nendl; return 1; /用来处理非法输入 if(cin.fail() cerrSorry!,请您必须输入一个合法的数字(1 or 2 or 3)endl; cout请输入您打算猜的拳(用数字123代替)endl; cin.clear(); cin.sync(); continue; else

7、if(t!=1&t!=2&t!=3) cerrSorry!,请您必须输入一个合法的数字(1 or 2 or 3)nendl; cout请输入您打算猜的拳(用数字123代替)nendl; cin.clear(); cin.sync(); continue; else cout第i+1次猜拳游戏 ; if(t=1) cout您猜的拳是:石头endl; else if(t=2) cout您猜的拳是:剪刀endl; else cout您猜的拳是:布0) +win;/统计赢的次数 else +loss;/统计输的次数 break; if(i=times-1) cout您的猜拳次数已经达到您所设定的tim

8、es次nendl; cout请问是否还要继续本游戏(Y/other)q;/在玩够开始自己所设的次数后,如果仍然打算继续,则输入y while(q=Y|q=y); /对整个游戏过程做一个完整统计 sum=win+loss+ping; gailv=win/sum; coutn本次游戏您一共猜拳:sum次endl; cout其中一共胜利:win次endl; cout其中一共输了:loss次endl; cout其中一共打平:ping次endl; cout您的胜率为:gailv*100%endl; cout您的败率为:loss/sum*100%endl; cout您的打平的概率为:(1-loss/sum

9、-gailv)*100%endl; if(sum10) cout由于您猜拳的次数小于10次,不具有统计学意义,所以您与电脑到底谁厉害,无法评判,请大侠重新来过!nendl; else if(gailv0.4) cout您真是个菜鸟,继续努力哦!nendl; else cout大侠好厉害啊,竟然赢了电脑,佩服佩服!nendl; baoshi(the_time_2); cout本次游戏您一共花费了:the_time_2-the_time_1秒ntm_sec; int ans; /switch中主要分了三种情况,第一种是60以内的素数,然后又添加了几个其他的,凑够20;第二种是能被3除开的,然后再添

10、加几个凑成20个;剩下的为第三种 switch(rec_sec) case 2:case 8:case 5:case 7:case 11:case 13:case 17:case 19:case 23:case 29:case 31:case 37:case 41:case 43:case 47:case 53:case 59:case 22:case 38:case 56: cout电脑游戏程序的猜的拳是:石头endl; ans=1; break; case 0:case 3:case 6:case 9:case 12:case 15:case 18:case 21:case 24:case

11、 27:case 30:case 33:case 36:case 39:case 42:case 45:case 48:case 51:case 54:case 57: cout电脑游戏程序的猜的拳是:剪子endl; ans=2; break; default: cout电脑游戏程序的猜的拳是:布endl; ans=3; break; if(t=ans) cout您这次和电脑打了一个平手!endl; return 0; switch(t) case 1: if(ans=2) cout恭喜您!您这次赢了电脑!nendl; return 1; else cout哈哈!输给电脑了!再接再厉!endl

12、; return -1; break; case 2: if(ans=3) cout恭喜您!您这次赢了电脑nendl; return 1; else cout哈哈!输给电脑了!再接再厉!endl; return -1; break; case 3: if(ans=1) cout恭喜您!您这次赢了电脑nendl; return 1; else cout哈哈!输给电脑了!再接再厉!endl; return -1; break; inline void keep_window_open() cin.clear(); cout ch; return;inline void baoshi(time_t &timeval) (void)time(&timeval); cout当前北京时间为:ctime(&timeval)nendl; return;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com