- 8
- 0
- 约1.18千字
- 约 5页
- 2016-12-03 发布于贵州
- 举报
人机对战取柴游戏源代码
# include iostream.h
# include time.h
# include stdlib.h
int man(int m);
int cmp(int m);
static int quanju=0;
void main()
{
int sum=21;
xz: cout1:先手\t2:后手\n请正确输入:flush;
int i;
cini;
switch(i)
{
case 1:{
while(sum!=0)
{
sum=man(sum);
if(sum==0)
break;
sum=cmp(sum);
}
break;
}
case 2:
{quanju++;
while(sum!=0)
{
sum=cmp(sum);
if(sum==0)
break;
sum=man(sum);
}
break;
}
default:
{
cout您的输入有误,请正确输入endl;
system(pause);
system(cls);
goto xz ;
}
}
cout游戏结束...endl;
system(pause);
}
int man(int m)
{
int qude=0;
xx: cout剩余m根火柴endl;
cout请输入取得的火柴数范围(1--4):flush;
cinqude;
if(qude4||qude1||qudem)
{
cout输入错误,请重新输入:flush;
goto xx;
}
cout你取得了qude根火柴endl;
if (m==qude)
{
cout你输了...endl;
system(pause);
}
return(m-qude);
}
int cmp(int m)
{
srand(time(0));
cout剩余m根火柴endl;
int qude;
if (quanju==0)
{
qude=(m-1)%5;
}
else
{x:
qude=rand()%4+1;
if(qudem)goto x;
}
cout电脑取了qude根火柴endl;
if(m-qude==0)
{
cout电脑输了...;
system(pause);
} return(m-qude);
}
您可能关注的文档
最近下载
- 2026年高考全国II卷文科综合真题试卷(新课标卷)(+答案).docx VIP
- 安路科技(688107)补国产短板,突高端应用,拓新应用与技术大市场-240717-东北证券-38页.pdf VIP
- [搞笑小品剧本]上当了小品剧本.docx VIP
- 全国初中数学联合竞赛真题及答案(初二组)2015-年.pdf VIP
- 数据中心800V直流供电技术白皮书2.0.pdf
- 上海大学2022-2023学年第1学期《高等数学(上)》期末考试试卷(B卷)附参考答案.pdf
- 上海大学2022-2023学年第1学期《高等数学(上)》期末考试试卷(A卷)附参考答案.pdf
- 中国教育行业人才流动与薪酬水平_2025年12月.docx
- 2024全国初中数学联赛初二卷 .pdf VIP
- AIAG-VDA-SPC手册-Yellow-Volume2026年2月第一版 中文.pdf VIP
原创力文档

文档评论(0)