原创:数字炸弹游戏
2023-09-02 13:30:18
发布于:浙江
#include<bits/stdc++.h>
using namespace std;
int what,a,b,startt = 1,endd = 100,a_yellow_flag_num,b_yellow_flag_num;
int main(){
srand((unsigned)time(NULL));
cout<<"欢迎来玩数字炸弹游戏(1~100以内版本):\n";
what = 1 + rand() % 100;
cout<<"我已出好数字了,你们要避开我出的这个数字。若碰到了我出的这个数字,则为输。\n";
cout<<"接下来请输入合法数字(否则将会给予一张黄牌,两张黄牌直接为输),谢谢。\n";
cout<<"现在开始轮流输入,游戏共两人可参加,先一号选手输入,在二号选手。\n";
while(true){
cout<<"一号选手请输入:";
cin>>a;
if(a == what){
cout<<"糟糕,你踩中雷了!\n结果:二号选手胜利,恭喜。";break;
break;
}else if(a > endd || a < startt){
a_yellow_flag_num++;
if(a_yellow_flag_num == 2){
cout<<"又得一张黄牌!两张黄牌,你已得到一张红牌!\n结果:二号选手胜利,恭喜。";break;
break;
}
cout<<"注意,请合法输入!得一张黄牌!\n下一位先输入,";goto place;
}else if(a > what){
startt = startt;
endd = a - 1;
cout<<"恭喜,没踩中,接下来猜"<<startt<<"~"<<endd<<endl;
}else if(a < what){
startt = a + 1;
endd = endd;
cout<<"恭喜,没踩中,接下来猜"<<startt<<"~"<<endd<<endl;
}
place:
cout<<"二号选手请输入:";
cin>>b;
if(b == what){
cout<<"糟糕,你踩中雷了!\n结果:一号选手胜利,恭喜。";break;
}else if(b > endd || b < startt){
b_yellow_flag_num++;
if(b_yellow_flag_num == 2){
cout<<"又得一张黄牌!两张黄牌,你已得到一张红牌!\n结果:一号选手胜利,恭喜。";break;
break;
}
cout<<"注意,请合法输入!得一张黄牌!\n下一位先输入,";continue;
}else if(b > what){
startt = startt;
endd = b - 1;
cout<<"恭喜,没踩中,接下来猜"<<startt<<"~"<<endd<<endl;
}else if(b < what){
startt = b + 1;
endd = endd;
cout<<"恭喜,没踩中,接下来猜"<<startt<<"~"<<endd<<endl;
}
}
return 0;
}
这里空空如也
有帮助,赞一个