自制小游戏,分享给大家
//0——步兵(k)
//1——弓箭手(k)
//2——炮兵(k)
//3——土地(平方公里)
//4——能量(t)
//5——钱(元宝)
//6——等级
//7——城池
#include <bits/stdc++.h>
using namespace std;
double xing[100];
int thing(){cout << "---------------------------------------事件--------------------------------------" << endl;cout << " [1]招兵 [2]休息 [3]进攻 [4]提示/目标 [5]退出 [6]国家 [7]国家城池 [其余]显示能量" << endl;return 0;
};
double munny(){random_device rd;mt19937 rang(rd());uniform_int_distribution<int> munny(200,1000);int man = munny(rang);cout << "增加钱数" << man << endl;xing[5] = xing[5] + man;return xing[100];
}
int tu(){random_device rd;mt19937 rang(rd());uniform_int_distribution<int> di(200,1000);int num=di(rang);cout << "增加土地" << num << endl;xing[3] = xing[3] + num;return xing[100];
}
double sun(){random_device rd;mt19937 rang(rd());uniform_int_distribution<int> bing(0,200);uniform_int_distribution<int> mei(0,10);switch (mei(rang)) {case 1:case 2:case 3:case 4:case 5: cout << "步兵损失" << bing(rang) << endl;xing[0] -= bing(rang); if(xing[0] <= 0){xing[0] = 0;}break;case 6:case 7:case 8:cout << "弓箭手损失" << bing(rang) << endl;xing[1] -= bing(rang); if(xing[1] <= 0){xing[1] = 0;}break;default:cout << "炮兵损失" << bing(rang) << endl;xing[2] -= bing(rang); if(xing[2] <= 0){xing[2] = 0;}break;}return xing[100];
}
int mu(){cout << "目标:称霸天下,成为10级国家" << endl;cout << "提示:能量为零时,游戏将会自动结束" << endl;cout << "提示:打仗可以增加钱" << endl;cout << "加油吧,我们神圣的君主" << endl;return 0;
};
double guo(){cout << "步兵:" << xing[0] << endl;cout << "弓箭手:" << xing[1] << endl;cout << "炮兵:" << xing[2] << endl;cout << "土地:" << xing[3] << endl;cout << "能量:" << xing[4] << endl;cout << "钱:" << xing[5] << endl; cout << "等级:" << xing[6] << endl;cout << "已有城池:" << xing[7] << endl;return xing[100];
};
double gongruo(){if(xing[0] != 0 && xing[1] != 0 && xing[2] != 0){random_device rd;mt19937 rang(rd());uniform_int_distribution<int> num(10,200);switch (num(rang)/10) {case 1:case 2:case 3:case 4:case 5:case 6:case 7:cout << "遇上了小土匪" << endl;_sleep(0.5*1000);cout << "全歼敌人" << endl;cout << "无伤亡" << endl; munny();break;case 11:case 12:case 13:case 14:case 15:cout << "遇上了A国敌人" << endl;_sleep(0.5*1000);cout << "歼灭敌人" << endl;sun();munny();tu();break;case 16:case 17:case 18:cout << "遇上了B国敌人" << endl;_sleep(0.5*1000);cout << "歼灭敌人" << endl;sun(); munny();tu();break;default:cout << "遇上了3级国家主力军队" << endl;cout << "交战中" << endl;cout << "······" << endl;_sleep(0.5*1000);if(xing[6]==3){cout << "你险胜" << endl;cout << "步兵还有1000" << endl; cout << "弓箭手还有500" << endl; cout << "炮兵还有100" << endl; xing[0]=1000; xing[1] = 500;xing[2] = 100;cout << "获得10000元宝" << endl;tu();}else if(xing[6]>3){printf("完胜");_sleep(0.5*1000);cout << "歼灭敌人" << endl;printf("无伤亡"); munny();tu();}else{cout << "你惨败" << endl;cout << "所有军队被全歼" << endl;xing[0] = 0;xing[1] = 0;xing[2] = 0; }break;}}else{cout << "兵力不足" << endl;}return xing[100];
};
double gongzhong(){if(xing[0] != 0 && xing[1] != 0 && xing[2] != 0){random_device rd;mt19937 rang(rd());uniform_int_distribution<int> num(10,200);switch (num(rang)/10) {case 1:case 2:case 3:case 4:cout << "遇上了3级国家军队" << endl;_sleep(0.5*1000);cout << "全歼敌人" << endl;cout << "无伤亡" << endl; munny();break;case 5:case 6:case 7:case 8:case 9:case 10:case 11:case 12:case 13:case 14:case 15:cout << "遇上了4级国家部队" << endl;_sleep(0.5*1000);cout << "歼灭敌人" << endl;sun();munny();tu();break;case 16:case 17:case 18:cout << "遇上了5级国家敌人" << endl;_sleep(0.5*1000);cout << "歼灭敌人" << endl;sun(); munny();tu();break;default:cout << "遇上了7级国家主力军队" << endl;cout << "交战中" << endl;cout << "······" << endl;_sleep(0.5*1000);if(xing[6]==7){cout << "你险胜" << endl;cout << "步兵还有100" << endl; cout << "弓箭手还有100" << endl; cout << "炮兵还有100" << endl; xing[0]=100; xing[1] = 100;xing[2] = 100;cout << "获得10000元宝" << endl;tu();}else if(xing[6]>7){printf("完胜");_sleep(0.5*1000);cout << "歼灭敌人" << endl;printf("无伤亡"); munny();tu();}else{cout << "你惨败" << endl;cout << "所有军队被全歼" << endl;xing[0] = 0;xing[1] = 0;xing[2] = 0; }break;}}else{cout << "兵力不足" << endl;}return xing[100];
}
double gongqiang(){if(xing[0] != 0 && xing[1] != 0 && xing[2] != 0){random_device rd;mt19937 rang(rd());uniform_int_distribution<int> num(10,200);switch (num(rang)/10) {case 1:case 2:case 3:case 4:cout << "遇上了8级国家军队" << endl;_sleep(0.5*1000);cout << "全歼敌人" << endl;cout << "无伤亡" << endl; munny();break;case 5:case 6:case 7:case 8:case 9:case 10:case 11:case 12:case 13:case 14:case 15:cout << "遇上了10级国家先锋队" << endl;_sleep(0.5*1000);cout << "歼灭敌人" << endl;sun();munny();tu();break;default:cout << "遇上了10级国家主力军队" << endl;cout << "交战中" << endl;cout << "······" << endl;_sleep(0.5*1000);if(xing[6]==9&&xing[0]>1000&&xing[1]>500){cout << "你险胜" << endl;cout << "步兵还有100" << endl; cout << "弓箭手还有100" << endl; cout << "炮兵还有100" << endl; xing[0]=100; xing[1] = 100;xing[2] = 100;cout << "获得10000元宝" << endl;tu();}else if(xing[6]>9&&xing[2]>1000){printf("完胜");_sleep(0.5*1000);cout << "歼灭敌人" << endl;printf("无伤亡"); munny();tu();}else{cout << "你惨败" << endl;cout << "所有军队被全歼" << endl;xing[0] = 0;xing[1] = 0;xing[2] = 0; }break;}}else{cout << "兵力不足" << endl;}return xing[100];
}
double zhao(){if(xing[5] >= 50){cout << "花钱50" << endl;xing[5] = xing[5] - 50;cout << "开始寻兵" << endl;cout << "寻兵中" << endl;_sleep(1*100); random_device rd;mt19937 rang(rd());uniform_int_distribution<int> num(1,100);switch (num(rang)/10) {case 1:case 2:case 3:case 4:xing[0] += 50;cout << "恭喜" << endl;cout << "步兵增加五十(k)" << endl;cout << "又增加国家兵力啦!" << endl;break;case 5:case 6:case 7:xing[1] += 50;cout << "恭喜" << endl;cout << "弓箭手增加五十(k)" << endl;cout << "又增加国家兵力啦!" << endl;break;case 8:case 9:xing[2] += 50;cout << "恭喜" << endl;cout << "炮手增加五十(k)" << endl;cout << "又增加国家兵力啦!" << endl;break;default:cout << "哎呀" << endl;cout << "啥都没有" << endl;break;} }else{cout << "没钱啦!" << endl;}return xing[100];
};
double xiu(){xing[4] = 100;return xing[100];
};
double dengji(){if(xing[7]>=50){printf("恭喜你,晋升为10级国家\n");xing[6] = 10;}else if(xing[7]>=45){printf("恭喜你,晋升为9级国家\n");xing[6] = 9;}else if(xing[7]>=40){printf("恭喜你,晋升为8级国家\n");xing[6] = 8;}else if(xing[7]>=35){printf("恭喜你,晋升为7级国家\n");xing[6] = 7;}else if(xing[7]>=30){printf("恭喜你,晋升为6级国家\n");xing[6] = 6;}else if(xing[7]>=25){printf("恭喜你,晋升为5级国家\n");xing[6] = 5;}else if(xing[7]>=20){printf("恭喜你,晋升为4级国家\n");xing[6] = 4;}else if(xing[7]>=14){printf("恭喜你,晋升为3级国家\n");xing[6] = 3;}else if(xing[7]>=7){printf("恭喜你,晋升为2级国家\n");xing[6] = 2;}return xing[100];
}
double chengchi(){int num=xing[3];int sum=xing[7];printf("大人,您现在拥有的城池数为:%d\n",sum);printf("您拥有%d平方公里的土地(除去已有城池所占的土地)\n",num); printf("每700平方公里的土地可以建造一座城池\n");if(xing[3]>=700){printf("大人,您要建造几座城池?\n");double n;cin >> n;if(n*700>xing[3]){printf("钱不够,滚开!别妨碍我做生意!\n");}else{xing[3] = xing[3]-n*700;num = xing[3];xing[7]+=n;sum=xing[7];printf("支付完毕\n");printf("剩余%d的土地空闲\n",num);printf("已有城池%d\n",sum);dengji();}}else{printf("这么点钱就要买城池?哼,滚开!别妨碍我做买卖!\n");}return xing[100];
}
int main(){cout << "------------欢迎来到《国争》------------" << endl;cout << "您是蜀国" << endl;cout << "拥有步兵1k,土地1000平方公里,钱1000元宝" << endl;cout << "要在各个王国中成为一代霸主" << endl;cout << "目标:国家等级10级" << endl;cout << "加油!" << endl; xing[0] = 1000;xing[1] = 0;xing[2] = 0;xing[3] = 200;xing[4] = 100; xing[5] = 1000; xing[6] = 1; xing[7] = 1;int yn = 1;while(yn == 1){thing();int num;cin >> num;switch (num) {case 1:zhao();xing[4] -= 5;if(xing[4] <= 0){yn = yn + 1;cout << "能量不足" << endl;}break;case 2:xiu();break;case 3:if(xing[6]<5) {gongruo();}else if(xing[6]<9){gongzhong();}else{gongqiang();}xing[4] -= 5;if(xing[4] <= 0){yn = yn + 1;cout << "能量不足" << endl;}if(xing[6] >= 10){cout << "游戏结束,完成目标" << endl;cout << "称霸天下,晋升10级国家" << endl;return 0;}break;case 4:mu();break;case 5:yn = yn + 1;if(xing[6] < 10){cout << "游戏结束,未完成目标。" << endl;}else{cout << "游戏结束,完成目标" << endl;}break;case 6:guo();break;case 7:chengchi();if(xing[6] == 10){cout << "游戏结束,完成目标" << endl;cout << "称霸天下,晋升10级国家" << endl;return 0;}break;default:cout << xing[4] << endl;break;}}return 0;
}