(现在都没有人分享小游戏了吗)蒟蒻的第一次分享,分享一篇自己写的“求生日记”(c++小游戏),制作不易,做的不好,勿喷
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
#define rt return
int day,food,wood,house,water,bull,chick,sheep,pig,help,tong;
struct node{
string name;
int blood;
int gj;
int fy;
int g_w;
int g_s;
int hungry;
int thirsty;
int tired;
}player;
//struct node{
// string name;
// int time;
// int h;
//}farm[7];
//int plant[7];
//int into(){
// farm[1]={"稻子",50,20};
// farm[2]={"麦子",55,25};
// farm[3]={"黍",45,15};
// farm[4]={"稷",40,10};
// farm[5]={"白菜",50,22};
// farm[6]={"萝卜",47,18};
//}
void see_you(){
printf("暂未开放,请耐心等待更新\n");
}
void sleep(int n){
Sleep(n);
}
void into(){
bull=0;chick=0;sheep=0;
pig=0;water=5;food=3;
day=1,help=0;
player={"111",100,40,30,10,5,10,10,20};
tong=0;house=0;
}
void slowout(string str){
int l=str.size();
for(int i=0;i<l;++i){
cout<<str[i];
Sleep(50);
}
}
void start(){
slowout("你是一个大富翁,有专属于自己的直升飞机,还有一套大别墅......\n有一天,你乘坐着直升飞机,飞到一个荒岛上空时,你身边的随从忽然一脚将你踢下了飞机,幸好你有降落伞,你才得以活命.....\n");
slowout("在这荒岛上,荒无人烟(跟鲁滨逊差不多),你想要去复仇,就得先在这儿存活下来,加油,少年!");
}
void make_wood(){
printf("你要砍几棵树?");
int a;
scanf("%d",&a);
wood=wood+a*5;
int b=a*20;
while(b--){
sleep(20);
printf("%d",b);
system("cls");
}
printf("砍伐成功!你获得了%d棵木头!\n",a*5);
sleep(500);
}
void kd(){
//printf("你要")
see_you();
}
void dg(){
printf("你确定吗?(1/else)\n");
int a;
cin>>a;
if(a!=1) rt;
printf("正在打怪......\n");
sleep(2000);
int hp=rand()%1000+1;
int g=rand()%200+1;
int f=rand()%100+1;
while(player.blood>0&&hp>0){
if((g<=player.fy)&&(f>=player.gj)) rt;
hp=hp-player.gj+f;
player.blood=player.blood-g+player.fy;
}
if(hp==0){
int y=g-f;
if(y<=0) y=1;
printf("恭喜你获得%d个铜矿\n",y);
tong+=y;
}
}
void find_food(){
int x=rand()%10+1;
if(x==4||x==8) printf("你没有找到食物......");
else if(x==2||x==6||x==10||x==7){
printf("你找到了1份食物");
food++;
}
else if(x==1||x==3){
printf("你找到了2份食物");
food+=2;
}
else{
printf("你找到了3份食物");
food+=3;
}
printf("\n");
}
void drink_water(){
int x=rand()%10+1;
if(x==4||x==8) printf("你没有找到水......");
else if(x==2||x==6||x==10||x==7){
printf("你找到了1份水");
water++;
}
else if(x==1||x==3){
printf("你找到了2份水");
water+=2;
}
else{
printf("你找到了3份水");
water+=3;
}
printf("\n");
}
void sleep_bed(){
printf("你要睡几个小时?\n");
int sleep_time;
cin>>sleep_time;
sleep(sleep_time*600);
player.tired+=sleep_time/2+house;
if(player.tired>20) player.thirsty=20;
}
void dl(){
printf("你找到了");
srand(time(NULL));
int y=rand()%4+1;
if(y==1) printf("一头牛");
else if(y==2) printf("一只羊");
else if(y==3) printf("一头猪");
else printf("一只鸡");
printf(",是否圈养?(1/else)\n");
int c;
cin>>c;
if(c==1){
if(y==1) bull++;
if(y==2) sheep++;
if(y==3) pig++;
if(y==4) chick++;
}
}
void make_mf(){
help++;
printf("制造完成!木筏碎片数:%d/25\n",help);
}
void animal(){
printf("牛:%d\n羊:%d\n猪:%d\n鸡:%d\n请问你要宰杀他们吗?(1/else)\n",bull,sheep,pig,chick);
int a;
cin>>a;
if(a!=1) rt;
printf("请问你要宰杀哪个?");
if(bull) printf("1.牛\n");
if(sheep) printf("2.羊\n");
if(pig) printf("3.猪\n");
if(chick) printf("4.鸡\n");
int c;
cin>>c;
if(c<1||c>4) rt;
else{
food+=6;
if(c==1&&bull) bull--;
if(c==2&&sheep) sheep--;
if(c==3&&pig) pig--;
if(c==4&&chick) chick--;
}
}
void make_house(){
if(house) printf("改进中......\n");
else printf("建造中......");
if(house&&wood>=30) house++;
else if(house&&wood<30) printf("改进材料不够!\n");
else if(house==0&wood>=50) house++;
else if(house==0&&wood<50) printf("建筑材料不够!\n");
printf("建造完成\n");
}
void eat(){
printf("你要吃还是喝(1/2)\n");
int a;
cin>>a;
if(a<1||a>2) rt;
if(a==1){
printf("吃几份食物?");
int a;
cin>>a;
if(a<1||a>food) rt;
printf("(咀嚼中......)\n");
sleep(3000);
printf("吃好了!\n");
player.hungry+=4*a;
}else{
printf("喝几份水?");
int a;
cin>>a;
if(a<1||a>water) rt;
printf("咕嘟咕嘟......\n");
sleep(3000);
printf("喝好了!\n");
player.thirsty+=4*a;
}
}
void loading(){
int y;
for(int i=1;i<=50;++i){
printf("加载中:");
for(int j=1;j<=i;++j) printf(">");
printf("\n小提示:");
srand(time(0));
if(i%10==1)y=rand()%4+1;
switch(y){
case 1:printf("只要你不打怪,你就基本不会死.....\n");break;
case 2:printf("其实荒岛上也有人......\n");break;
case 3:printf("荒岛上有一座山,进去了就回不来了.....\n");break;
case 4:printf("家畜可以繁殖.....\n");
}
sleep(100);
system("cls");
}
printf("加载成功!\n");
sleep(1000);
}
void no(){
printf("你思考了一天人生......\n");
}
int main(){
loading();
system("cls");
start();
into();
sleep(1500);
system("cls");
printf("请输入你的名字:");
cin>>player.name;
sleep(500);
system("cls");
while(1){
printf("今天是你荒岛求生的第%d天\n你的状态:生命:%d 攻击:%d 防御:%d 饥饿度:%d 口渴度:%d 疲倦度:%d 生产力:%d 木筏碎片数:%d/25\n1.伐木 2.矿洞 3.打怪 4.找食 5.饮水 6.睡觉 7.打猎 8.造木筏 9.畜牧 10.造(改进)房子 11.吃食\n",day,player.blood,player.gj,player.fy,player.hungry,player.thirsty,player.tired,player.g_s,help);
int c;
scanf("%d",&c);
switch(c){
case 1:make_wood();break;
case 2:kd();break;
case 3:dg();break;
case 4:find_food();break;
case 5:drink_water();break;
case 6:sleep_bed();break;
case 7:dl();break;
case 8:make_mf();break;
case 9:animal();break;
case 10:make_house();break;
case 11:eat();break;
default:no();break;
}
day++;
player.hungry-=2;
player.thirsty-=2;
player.tired-=2;
sleep(1500);
system("cls");
if(player.tired<0){
printf("你很疲倦......\n");
player.blood+=player.tired;
}
if(player.hungry<0){
printf("你很饿......\n");
player.blood+=player.hungry;
}
if(player.thirsty<0){
printf("你很渴......\n");
player.blood+=player.thirsty;
}
if(player.blood<=0){
slowout("你死了......\n");
rt 0;
}else if(help>=25){
slowout("你乘着木筏走了,找到了随从并将他押到了警察局,你重新夺回了属于你的权力,再次过上了幸福的生活......\n");
rt 0;
}
}
rt 0;
}
后续会更合成和矿洞
最后面的rt 0是。。。。
上面有个#define rt retrun
额