c++小游戏《荒岛求生》

这个游戏是我小学5年级的时候写的,快一年了

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
double wanjia,health=1000,ammo,hungry=100,thirsty=100,food,drink,wood,stone,iron,axe=500,pickaxe=500,ice,fire;
bool gun=false;
void start(){
	while(health>=0){
		system("cls");
		cout<<"你现在要干什么?\n";
		int wj;
		double jia;
		cout<<"1砍树 2采矿 3吃东西 4喝水 5钓鱼 6狩猎 7采集??? 8制作 9回血 10修补 11查看背包\n";
		cin>>wj;
		srand(time(0));
		switch(wj){
			case 1:{
				system("cls"); 
				if(axe){
					cout<<"砍树中……\n";
					Sleep(2000);
					cout<<"砍树完成\n";
					jia=rand()%10+1;
					cout<<"获得"<<jia<<"木材\n";
					wood+=jia;
					hungry-=jia/2;
					thirsty-=jia/4;
					axe-=jia/4; 	
				}
				else{
					cout<<"斧子坏了\n";
				}
				system("pause");
				break;
			}
			case 2:{
				system("cls");
				if(pickaxe){
					cout<<"采矿中……\n";
					Sleep(2000);
					cout<<"采矿完成\n";
					jia=rand()%10+1;
					cout<<"获得"<<jia<<"石头\n";
					stone+=jia;
					pickaxe-=jia/4;
					jia=rand()%5+1;
					hungry-=jia/2;
					cout<<"获得"<<jia<<"铁矿\n"; 
					iron+=jia;
					thirsty-=jia/2;
				} 
				else{
					cout<<"镐子坏了\n";
				}
				system("pause");
				break;
			}
			case 3:{
				system("cls");
				if(hungry==100){
					cout<<"现在饥饿值是满的,不用吃\n";
					system("pause");
					break;
				}
				else if(!food){
					cout<<"没有吃的\n";
					system("pause");
					break;
				}
				else{
					--food;
					hungry=100;
					cout<<"嗝~吃的真饱~~~\n";
					system("pause");
				}
				break;
			}	
			case 4:{
				system("cls");
				if(thirsty==100){
					cout<<"现在口渴值是满的,不用喝\n";
					system("pause");
					break;
				}
				else if(!drink){
					cout<<"没有喝的\n";
					system("pause");
					break;
				}
				else{
					--drink;
					thirsty=100;
					cout<<"嗝~喝的真饱~~~\n";
					system("pause");
				}
				break;
			}
			case 5:{
				system("cls"); 
				cout<<"钓鱼中……\n";
				Sleep(2000);
				cout<<"钓鱼完成\n";
				jia=rand()%8+1;
				cout<<"获得"<<jia<<"条鱼\n";
				food+=jia;
				hungry-=jia/2;
				thirsty-=jia/4;
				system("pause");
				break;
			}
			case 6:{
				system("cls"); 
				if(!ammo){
					cout<<"没弹药\n";
					system("pause");
					break;
				}
				else if(!gun){
					cout<<"没枪\n";
					system("pause");
					break;
				}
				cout<<"狩猎中……\n";
				Sleep(2000);
				cout<<"狩猎完成\n";
				jia=rand()%10+1;
				cout<<"获得"<<jia<<"块牛肉\n";
				food+=jia;
				hungry-=jia/2;
				thirsty-=jia/4;
				health-=jia;
				system("pause");
				break;
			}
			case 7:{
				system("cls"); 
				cout<<"采集中……\n";
				Sleep(2000);
				cout<<"采集完成\n";
				jia=rand()%5+1;
				cout<<"获得"<<jia<<"冰霜药草\n";
				ice+=jia;
				jia=rand()%10+1;
				cout<<"获得"<<jia<<"瓶饮品\n";
				hungry-=jia/2;
				thirsty-=jia/4;
				drink+=jia;
				jia=rand()%5+1;
				cout<<"获得"<<jia<<"火焰草\n";
				fire+=jia;
				jia=rand()%5+1;
				cout<<"获得"<<jia<<"块牛肉\n";
				food+=jia;
				system("pause");
				break;
			}
			case 8:{
				int xuanze; 
				system("cls");
				cout<<"木材数量:"<<wood<<endl;
				cout<<"石头数量:"<<stone<<endl;
				cout<<"铁的数量:"<<iron<<endl;
				cout<<"火焰草数量:"<<fire<<endl;
				cout<<"1.枪:25木头,15石头,10铁,5火焰草\n";
				cout<<"2.100子弹:50铁,25火焰草\n";
				cin>>xuanze;
				if(xuanze==1&&wood>=25&&stone>=15&&iron>=10&&fire>=5&&!gun){
					wood-=25;
					stone-=15;
					iron-=10;
					fire-=5;
					gun=true;
					cout<<"制作完成!现在已有了1把枪\n";
				}
				else if(xuanze==2&&iron>=50&&fire>=25){
					iron-=50;
					fire-=25;
					cout<<"获得100子弹\n";
					ammo+=100;
				}
				else cout<<"制作失败\n";
				system("pause");
				break;
			}
			case 9:{
				system("cls");
				if(health==1000){
					cout<<"你很健康,不用回血\n";
					system("pause");
				}
				else if(!ice){
					cout<<"没有药\n";
					system("pause");
				}
				else{
					--ice;
					cout<<"我又恢复了活力!\n";
					health=1000;
					system("pause");
				}
				break;
			}
			case 10:{
				system("cls");
				if(wood>=50&&stone>=100){
					cout<<"修补中……\n";
					Sleep(5000);
					cout<<"修补完成。斧子和镐子都焕然一新!\n";
					wood-=50;
					stone-=100;
				}
				else if(axe==100||pickaxe==100){
					cout<<"都好好的,不用修补\n";
					system("pause");
				}
				else{
					cout<<"没材料\n";
					system("pause");
				}
				break;
			}
			case 11:{
				system("cls");
				cout<<"生命值:"<<health<<endl;
				cout<<"饥饿值:"<<hungry<<endl;
				cout<<"口渴值:"<<thirsty<<endl;
				cout<<"木材数量:"<<wood<<endl;
				cout<<"石头数量:"<<stone<<endl;
				cout<<"铁矿数量:"<<iron<<endl;
				cout<<"饮品数量:"<<drink<<endl;
				cout<<"食物数量:"<<food<<endl;
				cout<<"冰霜药草数量:"<<ice<<endl;
				cout<<"火焰草数量:"<<fire<<endl;
				cout<<"斧子耐久:"<<axe<<endl;
				cout<<"稿子耐久:"<<pickaxe<<endl;
				system("pause");
				break;
			}
		}
		if(thirsty==0||hungry==0){
			health=0;
		}
	}
	cout<<"你死了……\n";
	return;
}
int main(){
	while(1){
		system("cls");
		cout<<"					      荒岛求生\n\n";
		cout<<"						1开始\n";
		cin>>wanjia;
		if(wanjia==1){
			system("cls");
			cout<<3;
			Sleep(1000);
			system("cls");
			cout<<2;
			Sleep(1000);
			system("cls");
			cout<<1;
			Sleep(1000);
			system("cls");
			cout<<"你在乘船旅游的的途中遭遇海难,大家都死了,只剩下你一个人。\n";
			cout<<"醒来时,发现你在一座岛上,你的面前有一座无人木屋。\n";
			cout<<"生存下去吧······\n";
			system("pause");
			start();
		}
	} 
	
} 

文字游戏,不太好玩

希望大家赏脸给个赞,收藏,转发

相关推荐

  1. c++游戏荒岛求生

    2024-03-25 21:08:02       22 阅读
  2. c++游戏

    2024-03-25 21:08:02       24 阅读
  3. c++游戏整理

    2024-03-25 21:08:02       24 阅读
  4. C++游戏合集

    2024-03-25 21:08:02       31 阅读
  5. C++:自创游戏

    2024-03-25 21:08:02       37 阅读
  6. c语言弹球游戏

    2024-03-25 21:08:02       16 阅读
  7. c++ 游戏(2种)

    2024-03-25 21:08:02       12 阅读
  8. 推箱子游戏C++

    2024-03-25 21:08:02       10 阅读
  9. C++游戏 合集

    2024-03-25 21:08:02       9 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-25 21:08:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-25 21:08:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-25 21:08:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-25 21:08:02       18 阅读

热门阅读

  1. typeScript3(数组类型)

    2024-03-25 21:08:02       18 阅读
  2. 【58. 最后一个单词的长度】

    2024-03-25 21:08:02       21 阅读
  3. 面对数据集不平衡的分类任务怎么办?

    2024-03-25 21:08:02       16 阅读
  4. 《c++》继承同名静态成员处理方式

    2024-03-25 21:08:02       19 阅读
  5. 【Leetcode】代码随想录Day15|二叉树2.0

    2024-03-25 21:08:02       18 阅读
  6. 毕业论文的问题猜想及答案整理

    2024-03-25 21:08:02       18 阅读
  7. Python学习笔记01

    2024-03-25 21:08:02       18 阅读
  8. 碎碎念-记一下LSPatch的原理

    2024-03-25 21:08:02       17 阅读
  9. 【笔试】美团2024年春招第二场笔试(技术)

    2024-03-25 21:08:02       21 阅读
  10. Linux的目录结构和文件管理命令

    2024-03-25 21:08:02       17 阅读