求大家帮忙找找bug
  • 板块灌水区
  • 楼主damuzhi
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/12/22 07:22
  • 上次更新2024/12/22 11:38:34
查看原帖
求大家帮忙找找bug
1127424
damuzhi楼主2024/12/22 07:22

简单恶魔轮盘

#include <bits/stdc++.h>
#include <windows.h>

using namespace std;

int healthy[4] = {-1,2,3,4};
int aheal,bheal;

struct body{
	int heal;
	char buf[10];
};

body a,b;

int term,wter;
bool butt[20];

int getrand(int min,int max) {
	return (rand() % (max - min + 1)) + min;
}

void say(string a){
	for(int i = 0; i < a.size(); i++){
		cout << a[i];
		Sleep(75);
	}
}

void wait(){
	cout << "Press Enter to continue..." << endl; getchar();
	system("cls");
}

bool cho(bool wter,int k){
	if(wter) {
		say("a的回合");
		cout << endl;
		wait();
	}
	else{
		say("b的回合");
		cout << endl;
		wait();
	}
		say("你选择打a还是b"); 
		char hit = getchar();
		wait();
		say("你选择了");
		cout << hit;
		say("这很有意思");
		cout << endl;
		say("这一发子弹是......");
		if(butt[k]){
			cout << "实弹" << endl;; 
			if(hit == 'a') a.heal--;
			else b.heal--;
			Sleep(2000); 
		} 
		else{
			cout << "空弹" <<endl; 
			Sleep(2000); 
		}
	wait();
	cout << "a的血量:" << a.heal << endl;
	cout << "b的血量:" << b.heal << endl;
	wait();
	if(wter && ((hit=='a' && butt[k] == 0) || (hit == 'b' && butt[k] == 1))) wter = 1;
	else if(!wter && (hit == 'b' && butt[k] == 0) || (hit == 'a' && butt[k] == 1)) wter = 0;
	else if(!wter && (hit == 'b' && butt[k] == 1) || (hit == 'a' && butt[k] == 0)) wter = 1;
	else if(wter && ((hit=='a' && butt[k] == 1) || (hit == 'b' && butt[k] == 0))) wter = 0;
	return wter;
}

int check(){
	if(a.heal == 0) return 1;
	if(b.heal == 0) return -1;
	else return 0; 
}

int main(){
	srand(time(0));
	
	cout << "只有双人对战,敬请谅解!有很多bug,欢迎在评论区反馈,暂无道具" << endl;
	wait(); 
	int awin = 0,bwin = 0;
	
	for(int h = 1; h <= 3; h++){
		int all = getrand(3,10);

		int live = getrand(1,all);
		int tmp1 = live;
		int vir = all-live;
		for(int i = 1; i<=all; i++){
			if(live && vir){
				int nowbut = getrand(0,1);
				if(nowbut){
					butt[i] = 1;
					live--;
				}
				else{
					butt[i] = 0;
					vir--;
				}
			}
			else if(!live){
				butt[i] = 0;
				vir--;
			}
			else{
				butt[i] = 1;
				live--;
			}
		}
		live = tmp1;
		vir = all - live;
		cout << live << "实弹  " << vir << "空弹" << endl; 
		if(h == 1) say("第I回合");
		if(h == 2) say("第II回合");
		if(h == 3) say("第III回合");
		cout << '\n';
		wait();
		if(aheal &&bheal) {
			a.heal = aheal;
			b.heal = bheal;
			aheal = 0;
			bheal = 0;
		}
		else{
			int heal = healthy[h];
			a.heal = heal;
			b.heal = heal;
		}
		++term;
		int noww = 0;
		wter = getrand(0,1);
		if(wter){
			noww = 1;
			wait(); 
		}
		else{
			noww = 0;
			wait();
		}
		int mter = 1;
		
		while(all){
			noww = cho(noww,mter);
			mter++;
			all--;
			int isend = check(); 
			if(isend == 1){
				cout << "b赢得了此次回合" <<endl;
				wait();
				bwin++;
				break; 
			}
			else if(isend == -1){
				cout << "a赢得了此次回合" << endl;;
				wait();
				awin++;
				break;
			} 
		} 
		if(!all && a.heal && b.heal){
			say("没有人在这一回合胜出,增加一回合");
			cout << endl;
			wait();
			h--;
			aheal = a.heal;
			bheal = b.heal;
		}
	}
	say("比赛已经结束,看看谁赢了......很好,我很有眼光");
	say("胜利者是:");
	if(awin > bwin) cout << 'a';
	else  cout << 'b';
	wait();
	say("恭喜!游戏将在确认后5s结束");
	wait();
	Sleep(5000);
	return 0;
} 
2024/12/22 07:22
加载中...