跳到正文

个人记录

打怪升天小游戏

drzo约 17 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 17 分钟
获赞
1

版本

  1. v1当前
C
#include <iostream>
#include <ctime>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <set>
#include <map>
using namespace std;
struct me
{
	int blood=100,speed=25,attack=0;
}m;
struct slm
{
	int blood=50,attack=5,speed=10;
}m1;
struct zombie
{
	int blood=100,attack=15,speed=20;
}m2;
struct godzilla
{
	int blood=10000,attack=100,speed=50;
}m3;
struct super_godzilla
{
	int blood=1000000,attack=1000,speed=95;
}m4;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	srand(time(NULL));
	cout<<"***********************"<<endl;
	cout<<"|                     |"<<endl;
	cout<<"| 欢迎来到打怪小游戏  |"<<endl;
	cout<<"|     输入1开始!     |"<<endl;
	cout<<"|      否则结束       |"<<endl;
	cout<<"|                     |"<<endl;
	cout<<"***********************"<<endl;
	int a,coin=100;
	cin>>a;
	if(a==1)
	{
			cout<<"你有5个绝招:1.鬼火(能使无限次,攻击为10) 2.冰封(能使5次,让敌方速度减10) 3.霹雳(使10次,攻击为15) 4.万物复苏(使5次,血+100) 5.天崩地裂(1次,攻击25,涨血20)"<<endl<<"你的金币有100"<<endl;
			int c1=0;
			int c2=0;
			bool flag=true;
			while(flag)
			{
				int c2=3,c3=10,c4=5,c5=1;
				cout<<"你要:1.买药水 2.打怪 3.看看自己"<<endl;
				int p;
				cin>>p;
				if(p==3)
				{
					cout<<m.blood<<endl<<m.attack<<endl<<m.speed<<endl;
				 }
				else if(p==2)
				{
				int t=rand()%3;
				if(c1==3)
				{
					t=3;
				}
				if(t==0)
				{
					m1.blood=50;
					cout<<"你遇见了史莱姆!"<<endl;
					cout<<"你逃跑吗? 1.作战 2.逃跑"<<endl;
					int w;
					cin>>w;
					if(w==2)
					{
						coin-=1000;
						cout<<"逃跑成功"<<endl;
						continue;
					 }
					while(m.blood>0&&m1.blood>0)
					{
						cout<<"敌方的血还有"<<m1.blood<<endl;
						cout<<"你的血还有"<<m.blood<<"   请攻击(选择绝招编号)"<<endl;
						int z;

						cin>>z;
						if(z==1)
						{

							if(rand()%101<m1.speed)
							cout<<"敌方躲避了攻击"<<endl;
							else
							{
								m1.blood-=10;
								m1.blood-=m.attack;
								cout<<"敌方受到攻击"<<endl;
							}

					 	}
					 	else if(z==2&&c2>0)
					 	{
					 		m1.speed-=10;
					 		cout<<"敌方被冻住了,减了速度!"<<endl;
					 		c2--;
					 	}
					 	else if(z==3&&c3>0)
					 	{
					 		if(rand()%101<m1.speed)
							cout<<"敌方躲避了攻击"<<endl;
							else
							{
								m1.blood-=15;
								m1.blood-=m.attack;
								cout<<"敌方受到攻击"<<endl;
							}
							c3--;
					 	}
					 	else if(z==4&&c4>0)
					 	{
					 		m.blood+=100;
					 		cout<<"你涨血了!"<<endl;
					 		c4--;
					 	}
					 	else if(z==5&&c5>0)
					 	{

					 		m1.blood-=25;
					 		m1.blood-=m.attack;
					 		cout<<"天崩地裂!!!敌方受到猛烈攻击!!!"<<endl;
					 		m.blood+=20;
					 		c5--;
					 	}
					 else
					 cout<<"攻击无效!!!"<<endl;
					 cout<<"敌方攻击了"<<endl;
					 if(rand()%101<m.speed)
					 {
					 	cout<<"你躲避了攻击!"<<endl;
					 }
					 else
					 m.blood-=(rand()%5+m1.attack);
				}
			}
			if(t==1)
			{
				m2.blood=100;
				cout<<"你遇见了僵尸!"<<endl;
				cout<<"你逃跑吗? 1.作战 2.逃跑"<<endl;
					int w;
					cin>>w;
					if(w==2)
					{
						coin-=100;
						cout<<"逃跑成功"<<endl;
						continue;
					 }
				while(m.blood>0&&m2.blood>0)
				{
					cout<<"敌方的血还有"<<m2.blood<<endl;
					cout<<"你的血还有"<<m.blood<<"   请攻击(选择绝招编号)"<<endl;
					int z;

					cin>>z;
					if(z==1)
					{

						if(rand()%101<m2.speed)
						cout<<"敌方躲避了攻击"<<endl;
						else
						{
							m2.blood-=10;
							m2.blood-=m.attack;
							cout<<"敌方受到攻击"<<endl;
						}

					 }
					 else if(z==2&&c2>0)
					 {
					 	m2.speed-=10;
					 	cout<<"敌方被冻住了,减了速度!"<<endl;
					 	c2--;
					 }
					 else if(z==3&&c3>0)
					 {
					 	if(rand()%101<m2.speed)
						cout<<"敌方躲避了攻击"<<endl;
						else
						{
							m2.blood-=15;
							m2.blood-=m.attack;
							cout<<"敌方受到攻击"<<endl;
						}
						c3--;
					 }
					 else if(z==4&&c4>0)
					 {
					 	m.blood+=100;
					 	cout<<"你涨血了!"<<endl;
					 	c4--;
					 }
					 else if(z==5&&c5>0)
					 {

					 	m2.blood-=25;
					 	m2.blood-=m.attack;
					 	cout<<"天崩地裂!!!敌方受到猛烈攻击!!!"<<endl;
					 	m.blood+=20;
					 	c5--;
					 }
					 else
					 cout<<"攻击无效!!!"<<endl;
					 cout<<"敌方攻击了"<<endl;
					 if(rand()%101<m.speed)
					 {
					 	cout<<"你躲避了攻击!"<<endl;
					 }
					 else
					 m.blood-=(rand()%5+m2.attack);
				}
			}
			if(t==2)
			{
				m3.blood=10000;
				cout<<"你遇见了哥斯拉!"<<endl;
				cout<<"你逃跑吗? 1.作战 2.逃跑"<<endl;
					int w;
					cin>>w;
					if(w==2)
					{
						coin-=10;
						cout<<"逃跑成功"<<endl;
						continue;
					 }
				while(m.blood>0&&m3.blood>0)
				{
					cout<<"敌方的血还有"<<m3.blood<<endl;
					cout<<"你的血还有"<<m.blood<<"   请攻击(选择绝招编号)"<<endl;
					int z;

					cin>>z;
					if(z==1)
					{

						if(rand()%101<m3.speed)
						cout<<"敌方躲避了攻击"<<endl;
						else
						{
							m3.blood-=10;
							m3.blood-=m.attack;
							cout<<"敌方受到攻击"<<endl;
						}

					 }
					 else if(z==2&&c2>0)
					 {
					 	m3.speed-=10;
					 	cout<<"敌方被冻住了,减了速度!"<<endl;
					 	c2--;
					 }
					 else if(z==3&&c3>0)
					 {
					 	if(rand()%101<m3.speed)
						cout<<"敌方躲避了攻击"<<endl;
						else
						{
							m3.blood-=15;
							m3.blood-=m.attack;
							cout<<"敌方受到攻击"<<endl;
						}
						c3--;
					 }
					 else if(z==4&&c4>0)
					 {
					 	m.blood+=100;
					 	cout<<"你涨血了!"<<endl;
					 	c4--;
					 }
					 else if(z==5&&c5>0)
					 {

					 	m3.blood-=25;
					 	m3.blood-=m.attack;
					 	cout<<"天崩地裂!!!敌方受到猛烈攻击!!!"<<endl;
					 	m.blood+=20;
					 	c5--;
					 }
					 else
					 cout<<"攻击无效!!!"<<endl;
					 cout<<"敌方攻击了"<<endl;
					 if(rand()%101<m.speed)
					 {
					 	cout<<"你躲避了攻击!"<<endl;
					 }
					 else
					 m.blood-=(rand()%5+m3.attack);
				}
			}
			if(t==3)
			{
				m4.blood=10000000;
				cout<<"你遇见了超级哥斯拉!"<<endl;
				cout<<"你逃跑吗? 1.作战 2.逃跑"<<endl;
					int w;
					cin>>w;
					if(w==2)
					{
						coin-=1;
						cout<<"逃跑成功"<<endl;
						continue;
					 }
				while(m.blood>0&&m4.blood>0)
				{
					cout<<"敌方的血还有"<<m4.blood<<endl;
					cout<<"你的血还有"<<m.blood<<"   请攻击(选择绝招编号)"<<endl;
					int z;

					cin>>z;
					if(z==1)
					{

						if(rand()%101<m4.speed)
						cout<<"敌方躲避了攻击"<<endl;
						else
						{
							m4.blood-=10;
							m4.blood-=m.attack;
							cout<<"敌方受到攻击"<<endl;
						}

					 }
					 else if(z==2&&c2>0)
					 {
					 	m4.speed-=10;
					 	cout<<"敌方被冻住了,减了速度!"<<endl;
					 	c2--;
					 }
					 else if(z==3&&c3>0)
					 {
					 	if(rand()%101<m4.speed)
						cout<<"敌方躲避了攻击"<<endl;
						else
						{
							m4.blood-=15;
							m4.blood-=m.attack;
							cout<<"敌方受到攻击"<<endl;
						}
						c3--;
					 }
					 else if(z==4&&c4>0)
					 {
					 	m.blood+=100;
					 	cout<<"你涨血了!"<<endl;
					 	c4--;
					 }
					 else if(z==5&&c5>0)
					 {

					 	m4.blood-=25;
					 	m4.blood-=m.attack;
					 	cout<<"天崩地裂!!!敌方受到猛烈攻击!!!"<<endl;
					 	m.blood+=20;
					 	c5--;
					 }
					 else
					 cout<<"攻击无效!!!"<<endl;
					 cout<<"敌方攻击了"<<endl;
					 if(rand()%101<m.speed)
					 {
					 	cout<<"你躲避了攻击!"<<endl;
					 }
					 else
					 m.blood-=(rand()%5+m4.attack);
				}
			}
			if(m.blood<=0)
			{
				cout<<"你死了"<<endl;
				return 0;
			}

			else
			{
				cout<<"敌人死了"<<endl;
				if(t==0)
				coin+=10;
				else if(t==1)
				coin+=100;
				else if(t==2)
				{
					coin+=1000;
					c1++;
				}
				else
				{
					coin+=5000;
				}
			}

			}
			else
			{
				cout<<"你的金币有"<<coin<<endl;
				cout<<"你要买: 1.攻击力药水 25元 2.超级攻击力药水 100元 3.生命力药水 10元 4.超级生命力药水 100元 5.速度药水 10元 6.无敌药水 1000元 7.哥斯拉药水 5000元 8.神圣仙药 10000元"<<endl;
				int r;
				cin>>r;
				if(r==1&&coin>=25)
				{
					m.attack+=10;
					coin-=25;
					cout<<"购买成功"<<endl;
				 }
				else if(r==2&&coin>=100)
				{
					m.attack+=50;
					coin-=100;
					cout<<"购买成功"<<endl;
				 }
				 else if(r==3&&coin>=10)
				{
					m.blood+=50;
					coin-=10;
					cout<<"购买成功"<<endl;
				 }
				 else if(r==4&&coin>=100)
				{
					m.blood+=600;
					coin-=100;
					cout<<"购买成功"<<endl;
				 }
				 else if(r==5&&coin>=10&&m.speed<=75)
				{
					m.speed+=10;
					coin-=10;
					cout<<"购买成功"<<endl;
				 }
				 else if(r==6&&coin>=1000&&m.speed<=75)
				{
					m.speed+=10;
					m.attack+=2500;
					m.blood+=30000;
					coin-=1000;
					cout<<"购买成功"<<endl;
				 }
				 else if(r==8&&coin>=10000)
				{
					cout<<"你成功升天,游戏成功!!!"<<endl;
					return 0;
				 }
				 else if(r==6&&coin>=1000&&m.speed>75)
				{
					m.attack+=2500;
					m.blood+=30000;
					coin-=1000;
					cout<<"购买成功"<<endl;
				 }
				else if(r==7&&coin>=5000)
				{
				 	m.blood+=200000;
				 	m.attack+=15000;
					coin-=5000;
					cout<<"购买成功"<<endl;
				}
				 else
				{
					cout<<"购买失败"<<endl;
				 }

			}
		}
	}
	else
	{
		return 0;
	}
}
原文