社区讨论
a game
灌水区参与者 5已保存回复 14
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 14 条
- 当前快照
- 1 份
- 快照标识符
- @m276oqy0
- 此快照首次捕获于
- 2024/10/13 14:07 去年
- 此快照最后确认于
- 2024/10/13 16:17 去年
CPP
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<deque>
#include<vector>
#include<queue>
#include<string>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<windows.h>
#include<conio.h>
#include<ctime>
using namespace std;
const int maxn = 100000;
const int sleep = 500; //屏幕速度
struct civil { //文明
int level;
vector<int>planets;
string name;
bool alive;
bool xg = false;
bool hq = false;
bool hl = false;
bool hy = false;
bool xy = false;
bool sw = false;
int ki = 1;
} c[maxn];
struct planet { //星球
int dist;
int belong;
string name;
bool xg = false;
bool hq = false;
bool hl = false;
bool hy = false;
bool xy = false;
bool sw = false;
} p[maxn];
struct warship { //舰队
int from;
int frompl;
int to;
int ti;
warship() {}
warship(int _frompl, int _to, int _ti): from(p[_frompl].belong),
frompl(_frompl), to(_to), ti(_ti) {}
};
bool operator<(warship a, warship b) {
return a.ti > b.ti;
}
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
string lv[] = {"蛮荒时代", "石器时代", "青铜时代", "铁器时代", "火器时代", "蒸汽时代", "电气时代", "信息时代", "量子时代", "无限能源时代", "机械时代", "跨恒星广播能力", "1/100光速航行", "1/10光速航行", "1/5光速航行", "亚光速航行", "光速航行", "超光速航行", "虫洞跨越", "超曲率航线", "光粒打击", "二向箔打击"};
string destroy[] = {"严寒", "烈焰", "大撕裂", "双日凌空", "三日凌空", "三日连珠", "伽马风暴", "流浪黑洞", "母星寿尽", "恒星塌缩", "流浪恒星"};
string kind[] = {"硅基生命", "碳基生命", "能量生命"};
// 1 2 3 4 5 6 7 8 9 10 11
priority_queue<warship>q, r;
int sum;
void lose(int id);
string sFromInt(int x);
int main() {
srand(time(0));
system("COLOR 0A");
//freopen("ST.in","r",stdin);
//freopen("ST.out","w",stdout);
int i, j, n, year, cnt;
unsigned int sd = 2333;
cout << "文明的数量:";
cin >> n; //输入:第一行字符串个数,接下来若干行字符串
sum = n;
cout << n << "个文明的名字:" << endl;
for (i = 1; i <= n; i++) {
cout << i << ". ";
cin >> c[i].name;
p[i].name = c[i].name;
unsigned int tmp = 622;
for (j = 0; j < c[i].name.size(); j++) tmp = 703 * tmp + c[i].name[j];
sd = sd * 3071 + tmp;
c[i].level = 0;
int tq = rand() % 20;
if (tq == 0) {
tq = rand() % 20;
if (tq == 0) {
c[i].ki = 2;
c[i].level = 8;
} else {
c[i].ki = 0;
c[i].level = 5;
}
} else {
c[i].ki = 1;
}
if (c[i].name.find("归零") >= 0 &&
c[i].name.find("归零") <= c[i].name.length()) {
c[i].level += rand() % 6 + 5;
}
if (c[i].name.find("高维") >= 0 &&
c[i].name.find("高维") <= c[i].name.length()) {
c[i].level += rand() % 5 + 5;
}
if (c[i].name.find("吞噬") >= 0 &&
c[i].name.find("吞噬") <= c[i].name.length()) {
c[i].level += rand() % 4 + 3;
}
if (c[i].name.find("神") >= 0 && c[i].name.find("神") <= c[i].name.length()) {
c[i].level += rand() % 2 + 1;
}
if (c[i].name.find("命运") >= 0 &&
c[i].name.find("命运") <= c[i].name.length()) {
c[i].level += rand() % 3 + 1;
} else if (c[i].name.find("天命") >= 0 &&
c[i].name.find("天命") <= c[i].name.length()) {
c[i].level += rand() % 2 + 2;
} else if (c[i].name.find("命") >= 0 &&
c[i].name.find("命") <= c[i].name.length()) {
c[i].level += rand() % 2 + 1;
}
if (c[i].name.find("天尊") >= 0 &&
c[i].name.find("天尊") <= c[i].name.length()) {
c[i].level += rand() % 2 + 1;
}
if (c[i].name.find("帝") >= 0 && c[i].name.find("帝") <= c[i].name.length()) {
c[i].level += rand() % 2 + 1;
}
if (c[i].name.find("虫族") >= 0 &&
c[i].name.find("虫族") <= c[i].name.length()) {
c[i].level += rand() % 3 + 1;
c[i].ki = 1;
}
if (c[i].name.find("泰坦") >= 0 &&
c[i].name.find("泰坦") <= c[i].name.length()) {
c[i].level += rand() % 2 + 2;
c[i].ki = 1;
}
if (c[i].name.find("克苏鲁") >= 0 &&
c[i].name.find("克苏鲁") <= c[i].name.length()) {
c[i].level += rand() % 3 + 8;
c[i].ki = 2;
}
if (c[i].name.find("量子") >= 0 &&
c[i].name.find("量子") <= c[i].name.length()) {
c[i].level += rand() % 3 + 8;
c[i].ki = 2;
}
if (c[i].name.find("幽灵") >= 0 &&
c[i].name.find("幽灵") <= c[i].name.length()) {
c[i].level += rand() % 2 + 8;
c[i].ki = 2;
}
if (c[i].name.find("机甲") >= 0 &&
c[i].name.find("机甲") <= c[i].name.length()) {
c[i].level += rand() % 3 + 5;
c[i].ki = 0;
}
if (c[i].name.find("机械") >= 0 &&
c[i].name.find("机械") <= c[i].name.length()) {
c[i].level += rand() % 2 + 5;
c[i].ki = 0;
}
if (c[i].name.find("智能") >= 0 &&
c[i].name.find("智能") <= c[i].name.length()) {
c[i].level += rand() % 5 + 5;
c[i].ki = 0;
}
if (c[i].name.find("赛博") >= 0 &&
c[i].name.find("赛博") <= c[i].name.length()) {
c[i].level += rand() % 4 + 5;
c[i].ki = 0;
}
c[i].level = min(c[i].level, 16);
// cout<<"level:"<<c[i].level<<endl;
c[i].planets.push_back(i);
c[i].alive = true;
p[i].dist = rand() % 100 + 10;
p[i].belong = i;
// c[i].level+=16;
}
system("cls");
cout << "----------初始文明等级----------" << endl;
for (i = 1; i <= n; i++) {
cout << i << ". " << kind[c[i].ki] << "文明" << c[i].name << "-level:";
if (c[i].level <= 21)cout << lv[c[i].level] << endl;
else cout << 10.0 + double(c[i].level) / 2.5 << endl;
}
Sleep(sleep * n / 2);
cout << "宇宙在一片黑暗中诞生了..." << endl;
Sleep(2000);
system("cls");
srand(time(
NULL));//之后的演化会受所有输入名字的共同影响,也会被名字顺序影响
for (i = n + 1; i <= n * 10; i++) { //1~n星球是n个文明的母星
p[i].dist = rand() % 50 + 10;
//n+1~n*2星球是无人星球
p[i].belong = 0;
p[i].name = sFromInt(i - n) + "号";
/*
//n+i星球属于第i个文明
p[i].belong=i-n;
p[i].name=c[i-n].name+"2号";
c[i-n].planets.push_back(i);
*/
}
for (year = 0;; year += rand() % 20) {
// Sleep(sleep);
while (!q.empty() && year > q.top().ti) { //舰队到达
warship now = q.top();
q.pop();
int id = now.to;
i = now.from;
if (p[id].belong == i) continue;
cout << "宇宙历第" << year << "年" << endl;
cout << "来自" << c[i].name << "文明的舰队到达" << p[id].name <<
"星球,";
if (p[id].belong == 0 || (c[p[id].belong].level <= c[i].level &&
rand() % 3 > 0)) {
cout << "并占领了" << p[id].name << "星球" << endl;
lose(id);
p[id].belong = i;
c[i].planets.push_back(id);
if (!c[i].alive) {
cout << c[i].name << "文明重生" << endl;
c[i].alive = true;
sum++;
}
} else {
cout << "攻击失败" << endl;
if (c[p[id].belong].level > 11 && rand() % 100 > 0
) {
cout << p[id].name << "星球广播了" << p[now.frompl].name <<
"星球的位置" << endl;
if (rand() % 2) r.push(warship(0, now.frompl,
rand() % 5 * 10 + year + p[now.frompl].dist + p[id].dist));
}
}
Sleep(sleep);
}
while (!r.empty() && year > r.top().ti) { //黑暗森林打击到达
int id = r.top().to;
r.pop();
cout << "宇宙历第" << year << "年" << endl;
cout << p[id].name << "星球被二向箔降维打击" << endl;
if (p[id].sw == true) {
cout << "但此文明使用反维度打击技术强行升维" << endl;
} else {
lose(id);
p[id].belong = 0;
}
Sleep(sleep);
}
for (i = 1; i <= n; i++) {
if (!c[i].alive) continue;
if (rand() % 400 == 0) { //技术
if (rand() % 40 == 0 && c[i].xg == false && c[i].level >= 7) {
cout << "宇宙历第" << year << "年" << endl;
cout << c[i].name << "文明研发出了行星改造技术。" << endl;
c[i].xg = true;
p[i].xg = true;
Sleep(sleep);
}
if (rand() % 40 == 0 && c[i].xy == false && c[i].level >= 7) {
cout << "宇宙历第" << year << "年" << endl;
cout << c[i].name << "文明研发出了行星延寿技术。" << endl;
c[i].xy = true;
p[i].xy = true;
Sleep(sleep);
}
if (rand() % 40 == 0 && c[i].hl == false && c[i].level >= 9) {
cout << "宇宙历第" << year << "年" << endl;
cout << c[i].name << "文明研发出了恒星利用技术。" << endl;
c[i].hl = true;
p[i].hl = true;
Sleep(sleep);
}
if (rand() % 40 == 0 && c[i].hy == false && c[i].level >= 9) {
cout << "宇宙历第" << year << "年" << endl;
cout << c[i].name << "文明研发出了恒星延寿技术。" << endl;
c[i].hy = true;
p[i].hy = true;
Sleep(sleep);
}
if (rand() % 40 == 0 && c[i].hq == false && c[i].level >= 9) {
cout << "宇宙历第" << year << "年" << endl;
cout << c[i].name << "文明研发出了恒星牵引技术。" << endl;
c[i].hq = true;
p[i].hq = true;
Sleep(sleep);
}
if (rand() % 2 == 0 && c[i].hq == false && c[i].level >= 17) {
cout << "宇宙历第" << year << "年" << endl;
cout << c[i].name << "文明研发出了反维度打击技术。" << endl;
c[i].sw = true;
p[i].sw = true;
Sleep(sleep);
}
int qwe = rand() % 60 + 1;
cout << "宇宙历第" << year << "年" << endl;
if (qwe >= 50) {
cout << c[i].name << "文明发生技术爆炸,";
c[i].level += 2;
} else if (qwe >= 30) {
cout << c[i].name << "文明发生技术突破,";
c[i].level += 1;
} else {
cout << c[i].name << "文明发生技术送代" << endl;
goto Next;
}
if (c[i].level <= 21) {
if (c[i].level < 11) cout << "进入" << lv[c[i].level] << endl;
else cout << "具备" << lv[c[i].level] << "能力" << endl;
} else cout << "等级" << 10.0 + double(double(c[i].level - 10) * 0.17) <<
endl;
Next:
Sleep(sleep);
}
if (rand() % 100 == 0 && c[i].level >= 12 &&
c[i].planets.size() < n * 10) { //发出舰队
int id;
do {
id = rand() % (n * 10) + 1;
} while (p[id].belong == i);
int speed = min(c[i].level, 19);
int d = p[c[i].planets[0]].dist + p[id].dist;
if (speed == 12) d *= 100;
if (speed == 13) d *= 10;
if (speed == 14) d *= 5;
if (speed == 15) d *= 2;
if (speed == 16) d *= 1;
if (speed == 17) d /= 2;
if (speed == 18) d /= 15;
if (speed == 19) d /= 45;
d = d + 1;
if (speed) {
cout << "宇宙历第" << year << "年" << endl;
cout << c[i].name << "文明向" << p[id].name << "星球发出" << lv[speed] <<
"舰队,将在" << d << "年后到达" << endl;
}
q.push(warship(c[i].planets[0], id, year + d));
Sleep(sleep);
}
}
if (rand() % 5000 == 0) { //自然灾害
int id;
do {
id = rand() % (n * 2) + 1;
} while (p[id].belong == 0);
cout << "宇宙历第" << year << "年" << endl;
int q = rand() % 11;
cout << p[id].name << "星球上的文明遭受了" << destroy[q] <<
"灾难,";
if ((q == 0 || q == 1 || q == 2) && p[id].xg == true) {
cout << "但被此文明使用行星改造技术扭转了灾难。" << endl;
} else {
cout << "毁灭了" << endl;
lose(id);
p[id].belong = 0;
Sleep(sleep);
if (sum == 1) {
//system("pause");
return 0;
}
}
}
}
return 0;
}
void lose(int id) {
int i = p[id].belong;
if (i == 0) return;
vector<int>& v = c[i].planets;
vector<int>::iterator it;
for (it = v.begin(); it != v.end(); it++) if (*it == id) break;
v.erase(it);
if (v.size() == 0) {
c[i].alive = false;
sum--;
cout << "--->>" << c[i].name << "文明毁灭了" << endl;
Sleep(sleep * 5);
}
}
string sFromInt(int x) {
string ret;
while (x) {
ret = char(x % 10 + '0') + ret;
x /= 10;
}
return ret;
}
回复
共 14 条回复,欢迎继续交流。
正在加载回复...