自学内容网 自学内容网

C++恶魔轮盘赌(道具版)

家人们,更新了昂,前文:来自阳了个阳C++的恶魔轮盘赌无道具版

作为阳了个阳C++的好同学,我光荣地揽下了道具版的重担

不多说话,直接上代码

#include<bits/stdc++.h>
#include<Windows.h>
typedef long long ll;
using namespace std;
enum TOOLS {
    SMOKE,
    HAND_C,
    MAGNIFYING_GALSS,
    KNIFE,
    DRINKS
};
struct PLAYER_INFO {
ll life;
ll tls[5];
} player,dealer;
ll emp_bullets,tru_bullets,nw,nw_damage=1;
vector<ll> Bullets;
bool now_gun=1,nxt_gun=0;
void Introduction();
ll R(ll left_boundary,ll right_boundary);
void GiveOutTools();
void printOutTools();
void Init_Bullets();
bool Round();
void Do_Dealer_AI();
int main() {
srand(time(NULL));
Introduction();
Init_Bullets();
GiveOutTools();
while(Round()) {
ll a,b;
a=b=0;
cout<<"  你 剩余血量"<<player.life<<"滴\n";
cout<<"对手 剩余血量"<<dealer.life<<"滴\n";
for(ll i=nw;i<Bullets.size();i++)
if(Bullets[i]) a++;
else b++;
cout<<"剩余"<<a<<"发实弹和"<<b<<"发空弹\n";
if(nw>Bullets.size()) Init_Bullets(),GiveOutTools();
Sleep(2000);
system("cls");
}
return 0;
}
void Introduction() {
system("color 4");
cout<<"欢迎来到恶魔轮盘赌\n";
cout<<"我是你的对手\n";
Sleep(2000);
system("cls");
cout<<"请输入每轮真弹数量,假弹数量,以及电量格数\n";
cin>>tru_bullets>>emp_bullets>>player.life;
dealer.life=player.life;
system("cls");
}
ll R(ll left_boundary,ll right_boundary) {
return rand()%(right_boundary-left_boundary)+left_boundary;
}
void Init_Bullets() {
ll e=emp_bullets,t=tru_bullets;
while(e+t) {
ll x=rand()%2;
if(!x) {
if(e) {
e--;
Bullets.push_back(x);
} else {
t--;
Bullets.push_back(1);
}
} else {
if(t) {
t--;
Bullets.push_back(x);
} else {
e--;
Bullets.push_back(0);
}
}
}
}
void GiveOutTools() {
ll r=R(2,4);
for(ll i=1; i<=2; i++)
for(ll k=1; k<=r; k++) {
ll tr=R(0,4);
if(i==1) player.tls[tr]++;
else dealer.tls[tr]++;
}
}
void printOutTools() {
cout<<"华子"<<player.tls[0]<<"个\n手铐"<<player.tls[1]<<"个\n放大镜"<<player.tls[2]<<"个\n小刀"<<player.tls[3]<<"个\n饮料"<<player.tls[4]<<"个\n";
cout<<"手铐同一轮不可叠加,小刀伤害不可叠加\n";
}
bool Round() {
if(now_gun) {
cout<<"输入1使用道具\n输入2直接开枪\n请选择:";
printOutTools();
ll slt;
cin>>slt;
while(slt!=1&&slt!=2) cin>>slt;
if(slt==1) {
ReUse:
system("cls");
printOutTools();
cout<<"请按顺序输入道具使用序列,道具之间空格隔开\n";
string Use_tls;
vector<string> nd_use_tls;
cin.get();
getline(cin,Use_tls);
Use_tls+=" ";
string getStr,emp;
for(ll i=0; i<Use_tls.size(); i++)
if(Use_tls[i]!=' ') getStr+=Use_tls[i];
else {
nd_use_tls.push_back(getStr);
getStr=emp;
}
for(auto xx:nd_use_tls) {
if(xx=="华子") if(player.tls[0]) player.tls[0]--,player.life++;
if(xx=="手铐") if(player.tls[1]) player.tls[1]--,nxt_gun=1;
if(xx=="放大镜") if(player.tls[2]) {
player.tls[2]--;
cout<<"当前子弹为:"<<(Bullets[nw]?"实弹":"空弹")<<"\n";
}
if(xx=="小刀") if(player.tls[3]) {
nw_damage=min(nw_damage*2,(ll)2);
player.tls[3]--;
}
if(xx=="饮料") if(player.tls[4]) {
nw++;
cout<<"退出了一发"<<(Bullets[nw-1]?"实弹":"空弹")<<"\n";
player.tls[4]--;
}
}
cout<<"qwq道具用好啦,";
}
cout<<"你要向谁开枪(1表示自己,2表示对手,3表示还要用道具):";
cin>>slt;
while(slt!=1&&slt!=2&&slt!=3) cin>>slt;
if(slt==3) goto ReUse;
if(slt==1) {
if(Bullets[nw]==1) {
cout<<"是实弹,你扣血了,扣了"<<nw_damage<<"滴,剩余"<<player.life-nw_damage<<"滴血\n";
player.life-=nw_damage;
if(player.life<=0) {
cout<<"你挂了\n";
exit(0);
}
now_gun=nxt_gun;
nxt_gun=!nxt_gun; 
} else {
cout<<"是空弹,下一轮还是你\n";
nxt_gun=1;
now_gun=nxt_gun;
nxt_gun=0;
}
} else {
if(Bullets[nw]==1) {
cout<<"是实弹,对手扣血"<<nw_damage<<"滴,剩余"<<dealer.life-nw_damage<<"滴血\n";
dealer.life-=nw_damage;
if(dealer.life<=0) {
cout<<"对手挂了\n";
exit(0);
}
now_gun=nxt_gun;
nxt_gun=!nxt_gun; 
} else {
cout<<"是空弹\n";
now_gun=nxt_gun;
nxt_gun=!nxt_gun;
}
}
nw++;
nw_damage=1;
} else {
Do_Dealer_AI();
}
return true;
}
void Do_Dealer_AI() {
while(dealer.tls[0]) {
dealer.life++;
dealer.tls[0]--;
}
if(dealer.tls[1]) if(nxt_gun) {
nxt_gun=0;
dealer.tls[1]--;
}
if(dealer.tls[2]) {
int gt=Bullets[nw];
if(!gt) {
cout<<"对手向自己开枪,是空弹\n";
now_gun=0,nxt_gun=1;
} else {
cout<<"对手";
if(dealer.tls[3]) {
nw_damage=2;
dealer.tls[3]--;
cout<<"用小刀后";
}
cout<<"向你开枪\n";
player.life-=nw_damage;
nw++;
cout<<"你剩"<<player.life<<"滴血\n";
if(player.life<=0) {
cout<<"你挂了\n";
exit(0);
}
}
} else {
int rnd=rand()%3+1;
if(rnd<3) {
cout<<"对手向你开枪,是"<<(Bullets[nw]?"实弹":"空弹")<<"\n";
if(Bullets[nw]) {
nw++;
player.life--;
cout<<"你剩"<<player.life<<"滴血\n";
if(player.life<=0) {
cout<<"你挂了\n";
exit(0);
}
now_gun=nxt_gun;
nxt_gun=!nxt_gun;
} else {
nw++;
now_gun=nxt_gun;
nxt_gun=!nxt_gun;
}
} else {
int b=Bullets[nw];
cout<<"对手向自己开枪,是"<<(b?"实弹\n":"空弹\n");
if(b) {
nw++;
dealer.life--;
cout<<"对手剩"<<dealer.life<<"滴血\n";
if(dealer.life<=0) {
cout<<"对手挂了\n";
exit(0);
}
now_gun=nxt_gun;
nxt_gun=!nxt_gun;
} else {
nw++;
now_gun=0,nxt_gun=1;
}
}
}
}

耗时2周,手撸的代码,誊抄在电脑上的,创作不易,在下跪求点赞+关注啊!


原文地址:https://blog.csdn.net/weixin_72166565/article/details/138007821

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!