




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include#includevoid print() printf(*n); printf(* *n); printf(* welcome to the game *n); printf(* *n); printf(* Game rules: *n); printf(* 3man and 3rateiners and goods to pass *n); printf(*the river,the number of rateiners not more *n); printf(*over the number mans in the passing river. *n); printf(* Game operrations: *n); printf(* 1.input the number of men and rateiners *n); printf(* in turn *n); printf(* 2.input error keys,the game will restart*n); printf(*n);void began()/游戏开始 char ch; printf(nn); printf(press and key to start the game (Q key to quit).n); scanf(%c,&ch);if(ch=Q|ch=q) exit(0);/退出键void xianshi(char *a,char *b)/显示过河的动态 int ax=0,ay=0,bx=0,by=0;/ax ay代表原始岸边的人数,bx by代表现在岸那边人数 int i; for(i=0;i6;i+) if(*(a+i)=M)/岸这边商人数 ax+; if(*(a+i)=S)/岸这边仆人数 ay+; if(*(b+i)=M)/岸那边商人数 bx+; if(*(b+i)=S)/岸那边仆人数 by+; printf(this bankn);/岸边状况 for(i=1;iax;i+) printf(mann); printf(n); for(i=1;iay;i+) printf(rateinersn); printf(nn); printf(this bankn); for(i=1;ibx;i+) printf(mann); printf(n); for(i=1;iby;i+) printf(rateinersn); printf(nn);if(ax=0&ay=0&bx=3&by=3)/商人和仆人都运送过河 printf(congrarulation!You have finished the game!n);/游戏完成 exit(0);/退出游戏void pan(int ax,int ay,int bx,int by)/判断过河的商人与仆人是否安全即就是商人人数不少于仆人数 if(axay|bxby) printf(the men are killed!game overn); exit(0);main() int i,x=0,y=0; int ax=3,ay=3,bx=0,by=0; char a6,b6; system(color 1E); print(); began(); print();for(i=0;i3;i+)/M代表商人,s代表仆人 ai=M;for(i=3;i6;i+) ai=S;for(i=0;i6;i+)/游戏开始前的动态 即是3商人和3仆人在等待 bi=0;xianshi(a,b);/开始前动态do printf(please input number of man to that bank:);/输入商人乘船数 scanf(%d,&x); while(x2)/判定过河人数是否正确即不能超过2人或无人 printf(the wrong number ,please enter again:); scanf(%d,&x); print(); xianshi(a,b); printf(please input number of rateiners to that bank:);/输入仆人乘船数 scanf(%d,&y); while(y2|x+y2)/判定过河人数是否正确即不能超过2人或无人 printf(the wrong number ,please enter again:); scanf(%d,&y); ax=ax-x;ay=ay-y;pan(ax,ay,bx,by);bx=bx+x;by=ay+y;/一次过后,两边商人与仆人的人数print();for(i=0;i6;i+)ai=0;bi=0;for(i=0;iax;i+) ai=M;for(i=3;i3+ay;i+) ai=S;for(i=0;ibx;i+) bi=M;for(i=3;i3+by;i+) bi=S;xianshi(a,b); printf(please input number of man to this bank:); scanf(%d,&x); while(x2) printf(the wrong number ,please enter again:); scanf(%d,&x); print(); xianshi(a,b); printf(please input number of rateiners to that bank:);/输入仆人乘船数 scanf(%d,&y); while(y2|x+y2)/判定过河人数是否正确即不能超过2人或无人 printf(the wrong number ,please enter again:); scanf(%d,&y); bx=bx-x;by=by-y;pan(ax,ay,bx,by);ax=ax+x;ay=ay+y;/一次过后,两边商人与仆人的人数print();for(i=0;i6;i+)ai=0;bi=0;for(i=0;iax;i+) ai=M;for(i=3;i3+ay;i+) ai=S;for(i=0;ibx;i+) bi=M;for(i=3;i3+by;i+) bi=S;xianshi(a,b); printf(please input number of
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 新课标体育与健康说课稿
- 1.2地球运动的地理意义教学设计2024-2025学年高二上学期地理人教版(2019)选择性必修1
- 2025威海市租赁合同书格式文
- 2025年个体承租物业合同
- 防暴雨知识考试题及答案
- 数字化转型对工程项目管理模式的重构
- 2025合作协议(商务局改)
- 高端化学试剂和助剂生产项目环境影响报告书
- 城市排水管网改造工程施工方案
- 150MW光伏发电工程风险评估报告
- 宣传物料技术服务方案设计
- 品管圈PDCA改善案例-产科联合多部门降低阴道分娩产后出血发生率
- 暴聋(突发性耳聋)中医临床路径及入院标准2020版
- 部编高教版2023·职业模块 中职语文 2.《宁夏闽宁镇:昔日干沙滩今日金沙滩》 课件
- 矿井火灾防治理论与技术课件
- 【MOOC】生命的教育-浙江大学 中国大学慕课MOOC答案
- 食品检测实验室操作规程
- 高血压个案护理案例
- 四川省三级综合医院评审标准实施细则(2023年版)
- 心肺复苏术课件2024新版
- Unit 1 Lesson1 Hello!教学设计 2024-2025学年冀教版英语七年级上册
评论
0/150
提交评论