Bootstrap

C++ [项目] 恶魔轮盘赌

现在才发现C++游戏的支持率这么高,那就发几篇吧

零、前情提要

此篇是我与

同学的共创,他负责写人,我负责写机,简称人机, 不过有一点小插曲……

一、基本介绍

        支持Dev-C++5.11版本(务必调为英文输入法),基本操作看游戏里的介绍,怎么做的……懒得说,能看懂就看注释,没有的自己猜,如果你很固执……私我吧

二、代码部分

#include <bits/stdc++.h>
#include <windows.h>
#include<cstdlib>
#include<ctime>
#include <stdlib.h>
#include <stdio.h>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
#define int long long
const int N = 1e5+10;
string s[] = {"啤酒","香烟","放大镜","刀","手铐","肾上腺素","8848手机","过期药片","逆转器"};
//s[] ==> 判断道具
int a[15];
//a[] ==> 玩家道具数,a[i]表示道具s[i - 1]的数量
int dv[15];
//dv[] ==> 恶魔道具数,dv[i]表示道具s[i - 1]的数量
int dvh = 6,peh = 6,ped = 0,dvd = 5;
//dvh ==> 恶魔血量,peh ==> 玩家血量
//ped ==> 玩家道具数,dvd ==> 恶魔道具数
int zd,reld =0,nond = 0,dim_num = 1,peskip = 0,dvskip = 0;
//zd ==> 子弹数,reld ==> 实弹数,nond ==> 空包弹数
//dim_num ==> 系数,peskip ==> 玩家跳过(值为1则跳一回合)
//dvskip ==>恶魔跳过(值为1则跳一回合)
char op,oper = '0';
//op ==> 操作,oper ==> 肾上腺素偷取的道具
queue<int>q;
//q ==> 子弹按顺序弹出
void game_start() //游戏开始
{
	int l = 1;
	while(l--)
	{
		zd = random(4,8),reld =0,nond = 0;
		for(int i = 1;i <= zd;i++)
		{
			int uiti = random(0,1);
			if(uiti == 0) nond++,q.push(-1);
			if(uiti == 1) reld++,q.push(1);
		}//装填子弹
		cout << "本局游戏有" << zd << "发子弹,有" << reld << "发实弹," << nond << "发空包弹"<<endl;
		Sleep(3000);
		system("cls");
		cout << "抽取道具中."<<endl;
		Sleep(500);
		system("cls");
		cout << "抽取道具中.."<<endl;
		Sleep(500);
		system("cls");
		cout << "抽取道具中..."<<endl;
		Sleep(500);
		system("cls");
		cout << "抽取道具中."<<endl;
		Sleep(500);
		system("cls");
		cout << "抽取道具中.."<<endl;
		Sleep(500);
		system("cls");
		cout << "抽取道具中..."<<endl;
		Sleep(500);
		system("cls");
		cout << "抽取道具中."<<endl;
		Sleep(500);
		system("cls");
		cout << "抽取道具中.."<<endl;
		Sleep(500);
		system("cls");
		cout << "抽取道具中..."<<endl;
		Sleep(500);
		system("cls");
		if(ped > 4)
		{
			int d[10]={0,0,0,0,0,0,0,0,0,0};
			for(int i = 1;i <= 8 - ped;i++)
			{
				int doju = random(1,9);
				a[doju]++;
				d[doju]++;
			}
			cout << "您获得了:" << endl;
			for(int i = 1;i <= 9;i++)
			{
				if(d[i] > 0)
				{
					cout << d[i] << "个" << s[i - 1] << endl;
				}
			}
			ped = 8;
			Sleep(3000);
		}//给道具
		else
		{
			int d[10]={0,0,0,0,0,0,0,0,0,0};
			for(int i = 1;i <= 4;i++)
			{
				int doju = random(1,9);
				a[doju]++;
				d[doju]++;
			}
			cout << "您获得了:" << endl;
			for(int i = 1;i <= 9;i++)
			{
				if(d[i] > 0)
				{
					cout << d[i] << "个" << s[i - 1] << endl;
				}
			}
			ped += 4;
			Sleep(3000);
		}//给道具
		if(dvd > 4)
		{
			int d[10]={0,0,0,0,0,0,0,0,0,0};
			for(int i = 1;i <= 8 - ped;i++)
			{
				int doju = random(1,9);
				dv[doju]++;
				d[doju]++;
			}
			cout << "恶魔获得了:" << endl;
			for(int i = 1;i <= 9;i++)
			{
				if(d[i] > 0)
				{
					cout << d[i] << "个" << s[i - 1] << endl;
				}
			}
			dvd = 8;
			Sleep(3000);
		}//给恶魔道具
		else
		{
			int d[10]={0,0,0,0,0,0,0,0,0,0};
			for(int i = 1;i <= 4;i++)
			{
				int doju = random(1,9);
				dv[doju]++;
				d[doju]++;
			}
			cout << "恶魔获得了:" << endl;
			for(int i = 1;i <= 9;i++)
			{
				if(d[i] > 0)
				{
					cout << d[i] << "个" << s[i - 1] << endl;
				}
			}
			dvd += 4;
			Sleep(3000);
		}//给恶魔道具
	}
}
//string s[] = {"啤酒","香烟","放大镜","刀","手铐","肾上腺素","8848手机","过期药片","逆转器"};
void dv_use_things() //恶魔环节
{
	cout << "恶魔的回合"<<endl;
	Sleep(1000);
	if(dvh>=0)
	{
		if(reld<nond-1){
			if(q.front() * dim_num == 1)
			{
				cout << "恶魔射出了一发实弹"<<endl;
				if(q.front() == -1) reld--;
				if(q.front() == 1) nond--;
				Sleep(1);
				cout << "恶魔的血量-1"<<endl;
				Sleep(1);
				dvh--;
				cout << "您的血量 ==> " << peh << " " << dvh << " <== 恶魔血量"<<endl;
				if(dvh < 0)
				{
					cout << "恶魔噶了,恭喜胜利!" << endl;
					exit(0);
				}
				Sleep(2000);
			}
			if(q.front() * dim_num == -1)
			{
				cout << "恶魔射出了一发空弹"<<endl;
				if(q.front() == -1) reld--;
				if(q.front() == 1) nond--;	 
				Sleep(1000);
				cout << "您的血量 ==> " << peh << " " << dvh << " <== 恶魔血量"<<endl;
				peskip++;
				Sleep(2000);
			}
		}
		else
		{
			for(int i=0;i<15;i++)
			{
				if(dvh==5){ 
					if(s[i]=="香烟")
					{
						dvh++;
						dv[2]--;
					}
					break;
				}
				if(dvh<=4){ 
					if(s[i]=="过期药片")
					{						
						int yesno = random(1,2);
						if(yesno == 1)dvh+=2,cout << "恶魔回了2点血量"<<endl;
						else dvh-=1,cout << "恶魔扣了1点血量"<<endl;
						if(peh <= 0) 
						{
							cout << "恶魔噶了,恭喜胜利"<<endl;
							exit(0);
						}
					}
					dv[8]--; 
					break;
				}
				if(s[i]=="放大镜")
				{
					if(q.front() == 1) 
					{
						cout << "恶魔射出了一发实弹"<<endl;
						if(q.front() == 1) nond--;
						if(q.front() == -1) reld--;
						Sleep(1000);
						cout << "您的血量-1"<<endl;
						Sleep(1000);
						peh--;
						cout << "您的血量 ==> " << peh << " " << dvh << " <== 恶魔血量"<<endl;
						if(dvh < 0)
						{
							cout << "您噶了" << endl;
							exit(0);
						}
						Sleep(2000);
						break;
					}
					else 
					{
						cout << "恶魔射出了一发空弹"<<endl;
						if(q.front() == -1) reld--;
						if(q.front() == 1) nond--;	 
						Sleep(1000);
						cout << "您的血量 ==> " << peh << " " << dvh << " <== 恶魔血量"<<endl;
						peskip++;
						Sleep(2000);
						break;
					}
					dv[3]--;
				}
				else if(s[i]=="手铐")
				{
					
					cout << "恶魔铐住了您"<<endl;
					peskip++;
					dv[5]--;
					Sleep(2000);
					break;
				}
				else if(s[i]=="刀")
				{
					cout << "恶魔锯掉了枪管(伤害翻倍)"<<endl;
					dim_num *= 2;
					dv[4]--;
					Sleep(2000);
					break;
				}
				//else if(s[i]=="")
				
			}
			if(q.front() == 1) 
			{
				cout << "恶魔射出了一发实弹"<<endl;
				if(q.front() == 1) nond--;
				if(q.front() == -1) reld--;
				Sleep(1000);
				cout << "您的血量-1"<<endl;
				Sleep(1000);
				peh--;
				cout << "您的血量 ==> " << peh << " " << dvh << " <== 恶魔血量"<<endl;
				if(dvh < 0)
				{
					cout << "您噶了" << endl;
					exit(0);
				}
				Sleep(2000);
			}
			else 
			{
				cout << "恶魔射出了一发空弹"<<endl;
				if(q.front() == -1) reld--;
				if(q.front() == 1) nond--;	 
				Sleep(1000);
				cout << "您的血量 ==> " << peh << " " << dvh << " <== 恶魔血量"<<endl;
				peskip++;
				Sleep(2000);
			}
		} 
	}
	else{
		
	} 
	/**/;
}
void helper() //查看道具作用
{
	while(1)
	{
		system("cls");
		for(int j = 1;j <= 9;j++)
		{
			cout << "若要查看"<< s[j - 1] << "的作用,请输入" << j << endl;
		}
		cout << "若要退出帮助,请输入Q"<<endl;
		char qoo;
		cin >> qoo;
		system("cls");
		if((qoo < '1' || qoo > '9') && (qoo != 'Q' && qoo != 'q'))
		{
			cout << "无效输入"<<endl;
			Sleep(2000);
			system("cls");
			continue;
		}
		if(qoo == '1') cout << "啤酒:弹出下一发子弹"<<endl;
		else if(qoo == '2') cout << "香烟:在血量<6时使用,可以恢复1点血量"<<endl;
		else if(qoo == '3') cout << "放大镜:可以查看下一发子弹是实弹还是空包弹"<<endl;
		else if(qoo == '4') cout << "刀:可以锯掉枪管,使下一枪的实弹伤害变成2(仅限下一枪)"<<endl;
		else if(qoo == '5') cout << "手铐:可以让对面跳过一回合"<<endl;
		else if(qoo == '6') cout << "肾上腺素:可以偷取对方的一件道具并必须立刻使用(不能偷取肾上腺素)"<<endl;
		else if(qoo == '7') cout << "8848手机:可以查看最后一发子弹是实弹还是空包弹"<<endl;
		else if(qoo == '8') cout << "过期药片:在血量<5时使用,有50%概率恢复2点血量,50%概率扣除1点血量"<<endl;
		else if(qoo == '9') cout << "逆转器:可以让下一发子弹逆转(即空包弹变为实弹,实弹变为空包弹)"<<endl;
		else if(qoo == 'Q' || qoo == 'q') break;
		Sleep(3000);
	}
	return;
}
void use_things() //操作
{
	while(1)
	{
		if(oper == '0')
		{
			cout << "剩余" << zd << "发子弹,有" << reld << "发实弹," << nond << "发空包弹"<<endl;
			Sleep(1000);
			cout << "你的回合"<<endl;
			Sleep(1000);
			for(int j = 1;j <= 9;j++)
			{
				cout << "若要使用"<< s[j - 1] << "请输入" << j << "(剩余" << a[j] << 	"个)"<<endl;
			}
			cout << "若要查看每个道具的作用,请输入H"<<endl;
			cout << "若您要对自己开枪,请输入Y"<<endl;
			cout << "若您要对恶魔开枪,请输入D"<<endl;
			cout << "恶魔有:"<<endl;
			for(int i = 1;i <= 9;i++)
			{
				if(dv[i]) cout << dv[i] << "个" << s[i - 1]	<<endl;
			}
			cin >> op;
		}
		else op = oper,oper = '0';
		if((op < '1' || op > '9') && op != 'Y' && op != 'D' && op != 'H' && op != 'y' 	&& op != 'd' && op != 'h')
		{
			cout << "无效输入"<<endl;
			Sleep(2000);
			system("cls");
			continue;
		}
		if(op == '1')
		{
			if(a[1] > 0)
			{
				if(q.front() == 1) zd--,reld--,cout << "您退掉了一发实弹"<<endl;
				else zd--,nond--,cout << "您退掉了一发空包弹"<<endl;
				q.pop();
				a[1]--;
				Sleep(2000);
			}
			else 
			{
				cout << "您没有此道具"<<endl;
				Sleep(2000);
				system("cls");
			}
		}
		else if(op == '2')
		{
			if(a[2] > 0)
			{
				if(peh >= 6) 
				{
					cout << "您的血量已经满了,无需回血"<<endl;
					Sleep(2000);
					system("cls");
				}
				else 
				{
					peh++,cout << "您回了1点血量"<<endl;
				}
				a[2]--;
			}
			else 
			{
				cout << "您没有此道具"<<endl;
				Sleep(2000);
				system("cls");
			}
		}
		else if(op == '3')
		{
			if(a[3] > 0)
			{
				if(q.front() == 1) cout << "下一发子弹是实弹"<<endl;
				else cout << "下一发子弹是空包弹"<<endl;
				a[3]--;
				Sleep(2000);
			}
			else 
			{
				cout << "您没有此道具"<<endl;
				Sleep(2000);
				system("cls");
			}
		}
		else if(op == '4')
		{
			if(a[4] > 0)
			{
				if(dim_num == 2 || dim_num == -2)
				{
					cout << "枪管已经被锯掉,无需锯掉枪管"<<endl;
					Sleep(2000);
				}
				else
				{
					cout << "您锯掉了枪管(伤害翻倍)"<<endl;
					dim_num *= 2;
					a[4]--;
					Sleep(2000);
				}
			}
			else 
			{
				cout << "您没有此道具"<<endl;
				Sleep(2000);
				system("cls");
			}
		}
		else if(op == '5')
		{
			if(a[5] > 0)
			{
				if(dvskip > 0)
				{
					cout << "恶魔已经被铐住,无需使用手铐"<<endl;
					Sleep(2000);
				}
				else
				{
					cout << "您铐住了恶魔"<<endl;
					dvskip++;
					a[5]--;
					Sleep(2000);
				}
			}
			else 
			{
				cout << "您没有此道具"<<endl;
				Sleep(2000);
				system("cls");
			}
		}
		else if(op == '6')
		{
			if(a[6] > 0)
			{
				if(dvd == 0)
				{
					cout << "对方没有道具"<<endl;
				}
				else
				{
					while(oper == '0')
					{
						system("cls");
						cout << "恶魔有:"<<endl;
						for(int i = 1;i <= 9;i++)
						{
							if(dv[i] && i != 6) cout << dv[i] << "个" << s[i - 1]	<<endl;
							//i != 6是为了判断道具是否为“肾上腺素”
						}
						for(int j = 1;j <= 9;j++)
						{
							if(j != 6)cout << "若要偷取"<< s[j - 1] << "请输入" << j 	<< "		(你有" << a[j] << "个)"<<endl;
						}
						int per; // 读取道具
						cin >>per;
						if(per < '1' || per > '9')
						{
							cout << "无效输入"<<endl;
							Sleep(2000);
							system("cls");
							continue;
						}
						if(dv[per] > 0)
						{
							if(per != 6)
							{
								a[per]++;
								dv[per]--;
								oper = char('0' + per);
								cout << "偷取成功" << endl;
								Sleep(2000);
							}
							else
							{
								cout << "不能偷取肾上腺素"<<endl;
								Sleep(2000);
							}
						}
						else
						{
							cout << "对方没有此道具"<<endl;
							Sleep(2000);
						}
					}
				}
			}
			else 
			{
				cout << "您没有此道具"<<endl;
				Sleep(2000);
				system("cls");
			}
		}
		else if(op == '7')
		{
			if(a[7] > 0)
			{
				if(q.back() == 1) cout << "最后一发子弹(" << zd <<"发)是实弹"<<endl;
				else cout << "最后一发子弹(" << zd <<"发)是空包弹"<<endl;
				a[7]--;
				Sleep(2000);
			}
			else 
			{
				cout << "您没有此道具"<<endl;
				Sleep(2000);
				system("cls");
			}
		}
		else if(op == '8')
		{
			if(a[8] > 0)
			{
				if(peh >= 5) 
				{
					cout << "您的血量已经几乎满了,无需回血"<<endl;
					Sleep(2000);
					system("cls");
				}
				else 
				{
					int yesno = random(1,2);
					if(yesno == 1)peh+=2,cout << "您回了2点血量"<<endl;
					else peh-=1,cout << "您扣了1点血量"<<endl;
					if(peh <= 0) 
					{
						cout << "您噶了"<<endl;
						exit(0);
					}
				}
				a[8]--;
			}
			else 
			{
				cout << "您没有此道具"<<endl;
				Sleep(2000);
				system("cls");
			}
		}
		else if(op == '9')
		{
			if(a[9] > 0)
			{
				dim_num *= -1;
				a[9]--;
			}
			else 
			{
				cout << "您没有此道具"<<endl;
				Sleep(2000);
				system("cls");
			}
		}
		else if(op == 'h' || op == 'H')
		{
			helper();
		}
		else if(op == 'y' || op == 'Y')
		{
			if(q.front() * dim_num == 1)
			{
				cout << "您射出了一发实弹"<<endl;
				if(q.front() == 1) reld--;
				if(q.front() == -1) nond--;
				Sleep(1000);
				cout << "您的血量-1"<<endl;
				Sleep(1000);
				peh--;
				cout << "您的血量 ==> " << peh << " " << dvh << " <== 恶魔血量"<<endl;
				if(peh < 0)
				{
					cout << "您噶了" << endl;
					exit(0);
				}
				Sleep(2000);
			}
			if(q.front() * dim_num == 2)
			{
				cout << "您射出了一发实弹"<<endl;
				if(q.front() == 1) reld--;
				if(q.front() == -1) nond--;
				Sleep(1000);
				cout << "您的血量-2"<<endl;
				Sleep(1000);
				peh-=2;
				cout << "您的血量 ==> " << peh << " " << dvh << " <== 恶魔血量"<<endl;
				if(peh < 0)
				{
					cout << "您噶了" << endl;
					exit(0);
				}
				cout << "枪管已经复原" << endl;
				Sleep(2000);
			}
			if(q.front() * dim_num == -1)
			{
				cout << "您射出了一发空弹"<<endl;
				if(q.front() == 1) reld--;
				if(q.front() == -1) nond--;
				Sleep(1000);
				cout << "您的血量 ==> " << peh << " " << dvh << " <== 恶魔血量"<<endl;
				dvskip++;
				Sleep(2000);
			}
			if(q.front() * dim_num == -2)
			{
				cout << "您射出了一发空弹"<<endl;
				if(q.front() == 1) reld--;
				if(q.front() == -1) nond--;
				Sleep(1000);
				cout << "您的血量 ==> " << peh << " " << dvh << " <== 恶魔血量"<<endl;
				cout << "枪管已经复原" << endl;
				dvskip++;
				Sleep(2000);
			}
			dim_num = 1;
			zd--;
			q.pop();
			break;
		}
		else if(op == 'd' || op == 'D')
		{
			if(q.front() * dim_num == 1)
			{
				cout << "您射出了一发实弹"<<endl;
				if(q.front() == 1) reld--;
				if(q.front() == -1) nond--;
				Sleep(1000);
				cout << "恶魔的血量-1"<<endl;
				Sleep(1000);
				dvh--;
				cout << "您的血量 ==> " << peh << " " << dvh << " <== 恶魔血量"<<endl;
				if(dvh < 0)
				{
					cout << "恶魔噶了,恭喜胜利" << endl;
					exit(0);
				}
				Sleep(2000);
			}
			if(q.front() * dim_num == 2)
			{
				cout << "您射出了一发实弹"<<endl;
				if(q.front() == 1) reld--;
				if(q.front() == -1) nond--;
				Sleep(1000);
				cout << "恶魔的血量-2"<<endl;
				Sleep(1000);
				dvh-=2;
				cout << "您的血量 ==> " << peh << " " << dvh << " <== 恶魔血量"<<endl;
				if(dvh < 0)
				{
					cout << "恶魔噶了,恭喜胜利" << endl;
					exit(0);
				}
				cout << "枪管已经复原" << endl;
				Sleep(2000);
			}
			if(q.front() * dim_num == -1)
			{
				cout << "您射出了一发空弹"<<endl;
				if(q.front() == 1) reld--;
				if(q.front() == -1) nond--;
				Sleep(1000);
				cout << "您的血量 ==> " << peh << " " << dvh << " <== 恶魔血量"<<endl;
				Sleep(2000);
			}
			if(q.front() * dim_num == -2)
			{
				cout << "您射出了一发空弹"<<endl;
				if(q.front() == 1) reld--;
				if(q.front() == -1) nond--;
				Sleep(1000);
				cout << "您的血量 ==> " << peh << " " << dvh << " <== 恶魔血量"<<endl;
				cout << "枪管已经复原" << endl;
				Sleep(2000);
			}
			dim_num = 1;
			zd--;
			q.pop();
			break;
		}
		system("cls");
	}
	return;
}
signed main() 
{
	srand((unsigned)time(NULL));
	while(1)
	{
		game_start();
		Sleep(2000);
		while(q.size())
		{
			if(q.empty()) break;
			system("cls");
			Sleep(3000);
			for(int j = 1;j <= 1;j++)
			{
				if(peskip > 0) continue;
				use_things();
				peskip--;
			}
			Sleep(1000);
			system("cls");
			if(q.empty()) break;
			for(int j = 1;j <= 1;j++)
			{
				if(dvskip > 0) continue;
				dv_use_things(); 
				dvskip--;
			}
		}
	}
    return 0;
}

如果觉得不错就点个赞吧

;