【低成本自制小游戏】:赌博游戏c++代码(可直接运行)

无聊时随便用一堆随机函数写了个开宝箱的赌博游戏,分享一下:

没一点技术含量,但感觉有点意思哈哈

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<cstring>
#define common_treasure_chest_price 200
#define rare_treasure_chest_price 440
#define suprise_treasure_chest_price 440
#define sky_ground_price 1000
#define rich_price 1500
#define zhizun_price 3800
#define royal_price 5000
#define super_royal_price 7899
#define evil_price 12000
#define god_price 20000
#define black_market 25000
#define pass_code 1470
using namespace std;
void menu();
int menu_choice();
void common_treasure_chest();
int gcd(int a,int b);
void rare_treasure_chest();
void suprise_treasure_chest();
void sky_ground();
void rich();
void zhizun();
void royal();
void super_royal();
void evil();
void god();
void enrol();
void game();
void lack();
char name[100];
long long score=0;
bool flag=true;
bool flag_kejin=false;
int money=pow(2*5/gcd(5,2),gcd(9,3))*2;//加密金币,严禁随意改动 
int main()
{
	srand((unsigned)time(NULL));
	menu();
	int choice=menu_choice();
	if(choice==1)
	enrol();
	else
	return 0;
	while(money>=common_treasure_chest_price)
	{
		game();
	}
	printf("你就剩%d个金币了,啥都买不了了\n",money);
	printf("游戏结束,你的分数为:%lld\n",score);
	printf("远离赌博,从我做起\n");
	int end;
	printf("输入886退出游戏\n");
	while(scanf("%d",&end)!=EOF)
	{
		if(end==886)
		break;
	}
	return 0;
} 
void menu()
{
	printf("*****************************赌博游戏********************************\n");
	printf("*                      亿维数组游戏有限公司                          *\n");
    for(int i=1;i<=3;i++)
	printf("*                                                                   *\n");
	printf("*                      请对应相应功能输入数字                       *\n"); 
    for(int i=1;i<=2;i++)
	printf("*                                                                   *\n");
	printf("*                         1.注册游戏                                *\n");
	printf("*                       不是1的数字.退出游戏                        *\n");
	printf("*        注意:游戏无存档功能,不是不想玩的话,就不要随意退出       *\n");
	printf("*********************************************************************\n"); 
	for(int i=1;i<=3;i++)
	printf("*                                                                   *\n");
	printf("*                金币数量较高时将开启黑市!!!                     *\n");
	printf("*                                                                   *\n");
	printf("*                                                                   *\n");
	printf("*                                                                   *\n");
	printf("*********************************************************************\n");
}
int menu_choice()
{
	int temp;
	printf("请输入您的选择:");
	scanf("%d",&temp);
	if(temp==1)return 1;
	else return 2;
}
void enrol()
{
	printf("请输入您的用户名:");
	scanf("%s",name);
	system("cls");
}

void game()
{
	if(flag)
	{
		if(flag_kejin)
		{
			printf("充值成功,感谢支持!\n");
			flag_kejin=false;
		}
		printf("hello,%s,你现在的金币为: %d\n",name,money);
  		printf("这里有一些宝箱可以购买(对于每种宝箱,开出金币越大的概率一般来说会越低):\n");
		printf("宝箱分为连续宝箱和离散宝箱,连续是指可以开到那个区间上任意数量的金币,离散是只有固定数目金币\n"); 
		printf("1.普通宝箱(连续)(可以开出100--400金币):200金币一个\n\n");
		printf("2.稀有宝箱(连续)(可以开出300--750金币):460金币一个\n\n");
		printf("3.惊喜宝箱(离散)(30%:300金币 30%:400金币 20%:600金币 15%:700金币 5% 750金币):460金币一个\n\n");
    	printf("4.天上地下宝箱(离散) (70%:500金币  30%: 2000金币):1000金币一个\n\n");
    	printf("5.富商宝箱(连续)(可以开出800--3000金币):1500金币一个\n\n");
    	printf("6.至尊宝箱(离散)(20%:800金币 30%:2000金币 30%:4000金币 20%:8000金币):3800金币一个\n\n");
    	printf("7.皇家奢华宝箱(连续)(可以开出3000-10000金币):5000金币一个\n\n");
    	printf("8.超级皇家奢华宝箱(离散)(50%:5000金币 25%:8000金币  22%:12000金币 3%:20000金币):7899金币一个\n\n ");
    	if(money>=black_market)
		{
			printf("***********************您的金币足够开启黑市*****************************\n\n");
			printf("9.恶魔宝箱(离散)(30%:0金币 30%:10000金币 30%:18000金币 10%:30000金币):12000金币一个\n\n");
			printf("10.魔神宝箱(连续)(可以开出0--100000金币):20000金币一个\n\n");
		}
		printf("请输入您要购买的宝箱(输入对应数字,输入0结束游戏并结算最终得分)\n\n");	
		printf("金币不足请输入:20\n\n");
	}
	int choice;
	scanf("%d",&choice);
	switch(choice)
	{
		case 1:
			common_treasure_chest();
			break;
		case 2:
			rare_treasure_chest();
			break;
		case 3:
			suprise_treasure_chest();
			break;
		case 4:
		    sky_ground();
			break; 
		case 5:
			rich();
			break; 
		case 6:
			zhizun();
			break;
		case 7:
			royal();
			break;
		case 8:
		    super_royal(); 
		    break;
        case 9:
        	if(money>=black_market)
        	evil();
        	break;
       	case 10:
       		if(money>=black_market)
       		god();
       		break;
		case 20:
			lack();
			break;
		case 0:
			printf("游戏结束,你的分数为:%lld\n",score);
			exit(0);
	}
}
void common_treasure_chest()
{
	money-=common_treasure_chest_price;
	int temp=(int)round(1.0*rand()/RAND_MAX*10000);
	int temp1;
	if(temp>=0&&temp<=7000)
	{
		system("cls");
		temp1=(100+(temp/70));
		printf("\n*****普通宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>7000&&temp<=8800)
	{
		system("cls");
		temp1=(200+((temp-7000)/18));
		printf("\n*****普通宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>8800)
	{
		system("cls");
		temp1=(300+((temp-8800)/12));
		printf("\n*****普通宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
}
void rare_treasure_chest()
{
	if(money>=rare_treasure_chest_price)
	money-=rare_treasure_chest_price;
	else
	{
		printf("钱不够,买个屎啊\n");
		flag=false;
		return;
	}
	int temp=(int)round(1.0*rand()/RAND_MAX*10000);
	int temp1;
	if(temp>=0&&temp<=5000)
	{
		system("cls");
		temp1=(300+(temp/25));
		printf("\n*****稀有宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>5000&&temp<=8000)
	{
		system("cls");
		temp1=(500+((temp-5000)/15));
		printf("\n*****稀有宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>8000)
	{
		system("cls");
		temp1=(500+((temp-8000)/40));
		printf("\n*****稀有宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
}
void suprise_treasure_chest()
{
	if(money>=suprise_treasure_chest_price)
	money-=suprise_treasure_chest_price;
	else
	{
		printf("钱不够,买个屎啊\n");
		flag=false;
		return;
	}
	int temp=(int)round(1.0*rand()/RAND_MAX*10000);
	int temp1;
	if(temp>=0&&temp<=3000)
	{
		system("cls");
		temp1=300; 
		printf("\n*****惊喜宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>3000&&temp<=6000)
	{
		system("cls");
		temp1=400;
		printf("\n*****惊喜宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>6000&&temp<=8000)
	{
		system("cls");
		temp1=600; 
		printf("\n*****惊喜宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>8000&&temp<=9500)
	{
		system("cls");
		printf("\n*****惊喜宝箱开出了700金币*****\n\n");
		money+=700;
		score+=700;
		flag=true;
	}
	else if(temp>9500)
	{
		system("cls");
		printf("\n*****惊喜宝箱开出了750金币*****\n\n");
		money+=750;
		score+=750;
		flag=true;
	}
}
void sky_ground()
{
	if(money>=sky_ground_price)
	money-=sky_ground_price;
	else
	{
		printf("钱不够,买个屎啊\n");
		flag=false;
		return;
	}
	int temp=(int)round(1.0*rand()/RAND_MAX*10000);
	int temp1;
	if(temp>=0&&temp<=7000)
	{
		system("cls");
		temp1=500;
		printf("\n*****天上地下宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else
	{
		system("cls");
		temp1=2000;
		printf("\n*****天上地下宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
}
void rich()
{
	if(money>=rich_price)
	money-=rich_price;
	else
	{
		printf("钱不够,买个屎啊\n");
		flag=false;
		return;
	}
	int temp=(int)round(1.0*rand()/RAND_MAX*100000);
	int temp1;
	if(temp>=0&&temp<=50000)
	{
		system("cls");
		temp1=(800+(temp-0)/125);
		printf("\n*****富商宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>50000&&temp<=80000)
	{
		system("cls");
		temp1=(1200+(temp-50000)/37);
		printf("\n*****富商宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>80000&&temp<=95000)
	{
		system("cls");
		temp1=(2000+(temp-80000)/30);
		printf("\n*****富商宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>95000)
	{
		system("cls");
		temp1=(2500+(temp-95000)/10);
		printf("\n*****富商宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
}
void zhizun()
{
	if(money>=zhizun_price)
	money-=zhizun_price;
	else
	{
		printf("钱不够,买个屎啊\n");
		flag=false;
		return;
	}
	int temp=(int)round(1.0*rand()/RAND_MAX*10000);
	int temp1;
	if(temp>=0&&temp<=2000)
	{
		system("cls");
		temp1=800;
		printf("\n*****至尊宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>2000&&temp<=5000)
	{
		system("cls");
		temp1=2000;
		printf("\n*****至尊宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>5000&&temp<=8000)
	{
		system("cls");
		temp1=4000;
		printf("\n*****至尊宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>8000)
	{
		system("cls");
		temp1=8000;
		printf("\n*****至尊宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
}
void royal()
{
	if(money>=royal_price)
	money-=royal_price;
	else
	{
		printf("钱不够,买个屎啊\n");
		flag=false;
		return;
	}
	int temp=(int)round(1.0*rand()/RAND_MAX*100000);
	int temp1;
	if(temp>=0&&temp<=70000)
	{
		system("cls");
		temp1=(3000+(temp-0)/35);
		printf("\n*****皇家奢华宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>70000&&temp<=80000)
	{
		system("cls");
		temp1=(5000+(temp-70000)/3);
		printf("\n*****皇家奢华宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>80000&&temp<=95000)
	{
		system("cls");
		temp1=(8000+(temp-80000)/15);
		printf("\n*****皇家奢华宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>95000)
	{
		system("cls");
		temp1=(9000+(temp-95000)/5);
		printf("\n*****皇家奢华宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
}
void super_royal()
{
	if(money>=super_royal_price)
	money-=super_royal_price;
	else
	{
		printf("钱不够,买个屎啊\n");
		flag=false;
		return;
	}
	int temp=(int)round(1.0*rand()/RAND_MAX*10000);
	int temp1;
	if(temp>=0&&temp<=5000)
	{
		system("cls");
		temp1=5000;
		printf("\n*****超级皇家奢华宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>=5000&&temp<=7500)
	{
		system("cls");
		temp1=8000;
		printf("\n*****超级皇家奢华宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>=7500&&temp<=9700)
	{
		system("cls");
		temp1=12000;
		printf("\n*****超级皇家奢华宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>=9700)
	{
		system("cls");
		temp1=20000;
		printf("\n*****超级皇家奢华宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
}
void evil()
{
	if(money>=evil_price)
	money-=evil_price;
	else
	{
		printf("钱不够,买个屎啊\n");
		flag=false;
		return;
	}
	int temp=(int)round(1.0*rand()/RAND_MAX*10000);
	int temp1;
	if(temp>=0&&temp<=3000)
	{
		system("cls");
		temp1=0;
		printf("\n*****恶魔宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>3000&&temp<=6000)
	{
		system("cls");
		temp1=10000;
		printf("\n*****恶魔宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>6000&&temp<=9000)
	{
		system("cls");
		temp1=18000;
		printf("\n*****恶魔宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>9000)
	{
		system("cls");
		temp1=30000;
		printf("\n*****恶魔宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
}
void god()
{
	if(money>=god_price)
	money-=god_price;
	else
	{
		printf("钱不够,买个屎啊\n");
		flag=false;
		return;
	}
	int temp=(int)round(1.0*rand()/RAND_MAX*1000000);
	int temp1;
	if(temp>=0&&temp<=850000)
	{
		system("cls");
		temp1=(temp-0)/42;
		printf("\n*****魔神宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>850000&&temp<=900000)//20000--70000
	{
		system("cls");
		temp1=20000+(temp-850000);
		printf("\n*****魔神宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>900000&&temp<=950000)//70000--90000
	{
		system("cls");
		temp1=70000+(temp-900000)/2;
		printf("\n*****恶魔宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
	else if(temp>950000)  //90000--100000
	{
		system("cls");
		temp1=90000+(temp-950000)/5;
		printf("\n*****恶魔宝箱开出了%d金币*****\n\n",temp1);
		money+=temp1;
		score+=temp1;
		flag=true;
	}
}
int gcd(int a,int b)
{
	return !b?a:gcd(b,a%b);
}
void lack()
{
	system("cls");
	printf("**********************金币不足???****************************\n");
	printf("$$$$$$$$$$$$$$$$$$$$$想开启黑市坐拥更多财富吗?$$$$$$$$$$$$$$$$$\n");
	for(int i=1;i<=5;i++)
	printf("$                                                              $\n");
	printf("$           现在充值享受更多优惠!!!                         $\n");
	for(int i=1;i<=3;i++)
	printf("$                                                              $\n");
	printf("$                1000金币:1元 (已售完)                      $\n");
	printf("$                12000金币:10元 (已售完)                    $\n");
	printf("$                无限金币:仅需30元                            $\n");
	for(int i=1;i<=3;i++)
	printf("$                                                              $\n");
	printf("$        充值方式:加qq:********支持qq红包,微信,支付宝    $\n");
	printf("*****************************************************************\n");
	printf("输入:“下次一定” 返回原界面\n");
	printf("若已充值,先输入“充值”再输入兑换码\n");
	int temp;
	char s[100];
	while(scanf("%s",s)!=EOF)
	{
		if(!strcmp(s,"下次一定"))
		{
			system("cls");
			break;
		}
		if(!strcmp(s,"充值"))
		{
			printf("兑换码:");
			scanf("%d",&temp);
			if(temp==pass_code)
			{
				system("cls");
				flag_kejin=true;
				money+=1000000;
				break;
			}
			else{
				printf("兑换码错误,请加qq*********核实\n");
				printf("输入“下次一定”返回原界面\n或者输入“充值”,并重新输入兑换码\n");
			}
		}
	}
}





























  • 5
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值