跳到正文

休闲·娱乐

三体 beta.1.0

HappyJaPhy约 58 分钟
原文
文章信息与版本

文章信息

发布
2026年2月18日
收录
2026年9月26日
更新
2026年11月18日
篇幅
约 58 分钟

版本

  1. v1当前
  • 不说了(其实是bug还没修完),先上代码
C++
#include <bits/stdc++.h>
#include <io.h>
#include <windows.h>
#include <chrono>
#define inm 0.00001
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1 : 0)
using namespace std;
using namespace std::chrono;
const double c = 24;
const int MapRange = 175200;
const double pi = acos(-1.0);

double Time_Sum;
struct Object{
	int type, code, firecnt, id;
	double x, y, v, a, theta, vtheta, b;
	double Time, blood, lastattacktime;
	bool isSaw, isShow;
	Object(int t = 0, int c = 0, double X = 0, double Y = 0, double V = 0, double A = 0, double T = 0, double VT = 0, double B = 0) {
		type = t, code = c;
		x = X, y = Y, v = V, a = A, theta = T, vtheta = VT, b = B;
		lastattacktime = -100, firecnt = isSaw = 0, id = isShow = 1;
	}
	void update(double deltat) {
		v += pow(1 - pow(v / c, 2), 3 / 2) * a * deltat;
		vtheta += b * deltat;
		theta += vtheta * deltat;
		if (theta > 2 * pi) theta -= 2 * pi;
		if (theta < 0) theta += 2 * pi;
		x += v * deltat * cos(theta);
		y += v * deltat * sin(theta);
		Time = Time_Sum;
	}
	bool operator <(const Object& o)const {
		return code == o.code ? (fabs(Time - o.Time) > inm && Time < o.Time) : code < o.code;
	}
	bool operator ==(const Object& o)const {
		return !(*this < o || o < *this);
	}
} Me;

struct Show {
	int type, code, id;
	double x, y;
	bool isShow;
	Show (Object o) {
		type = o.type, code = o.code, x = o.x, y = o.y, isShow = o.isShow, id = o.id;
	}
	bool operator <(const Show& s)const {
		return code == s.code ? (type == s.type ? id < s.id : type < s.type) : code < s.code;
	}
};

vector<Object> Objects, Create_Issue;
set<Object> Light_Issue;
set<Show> Show_Issue;
int Sun_Num, Civil_Num, Code_Top;
int Code_stk[MapRange + 10];
double visdis[20] = {0, 10, 1, 3, 20, 0, 0, 0, 0, 0, 1};
int nowvis = 1, nowamod = 0, STOP = 0, turning = 0;
double Max_Fuel = 800000, Fuel = 600000;
double Time_Speed;
steady_clock::time_point nowtime, lasttime, lastsavetime;
double deltaT, deltat;
bool isup[260];
float xt;
string thisgamename;
char keyname[260][60] = {"", "鼠标左键", "鼠标右键", "[Ctrl]+[Break]",
                         "鼠标中键", "X1 鼠标按钮", "X2 鼠标按钮", "", "[Backspace]", "[Tab]", "", "",
                         "[Clear]", "[Enter]", "", "", "[Shift]", "[Ctrl]", "[Alt]", "[Pause]",
                         "[CapsLock]", "", "", "", "", "", "", "[Esc]", "", "", "", "", "[Space]",
                         "[PageUp]", "[PageDown]", "[End]", "[Home]", "[Left]", "[Up]", "[Right]",
                         "[Down]", "[Select]", "[Print]", "[Execute]", "[PrintScreen]", "[Insert]",
                         "[Delete]", "[Help]", "[0]", "[1]", "[2]", "[3]", "[4]", "[5]", "[6]", "[7]",
                         "[8]", "[9]", "", "", "", "", "", "", "", "[A]", "[B]", "[C]", "[D]", "[E]",
                         "[F]", "[G]", "[H]", "[I]", "[J]", "[K]", "[L]", "[M]", "[N]", "[O]", "[P]",
                         "[Q]", "[R]", "[S]", "[T]", "[U]", "[V]", "[W]", "[X]", "[Y]", "[Z]", "左[Win]",
                         "右[Win]", "[App]", "", "[Sleep]", "小键盘[0]", "小键盘[1]", "小键盘[2]",
                         "小键盘[3]", "小键盘[4]", "小键盘[5]", "小键盘[6]", "小键盘[7]", "小键盘[8]",
                         "小键盘[9]", "[×]", "[+]", "[分隔符]", "[-]", "[Dec]", "[/]", "[F1]", "[F2]",
                         "[F3]", "[F4]", "[F5]", "[F6]", "[F7]", "[F8]", "[F9]", "[F10]", "[F11]",
                         "[F12]", "[F13]", "[F14]", "[F15]", "[F16]", "[F17]", "[F18]", "[F19]", "[F20]",
                         "[F21]", "[F22]", "[F23]", "[F24]", "", "", "", "", "", "", "", "", "[NumLock]",
                         "[ScrollLock]", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
                         "左[Shift]", "右[Shift]", "左[Ctrl]", "右[Ctrl]", "左[Alt]", "右[Alt]", "", "", "", "",
                         "", "", "", "静音", "音量减小", "音量增加", "下一首", "上一首", "停止", "播放/暂停",
                         "启动邮件", "选择媒体", "启动应用程序_1", "启动应用程序_2", "", "", "[;]",
                         "[=]", "[,]", "[-]", "[.]", "[/]", "[~]", "", "", "", "", "", "", "", "", "",
                         "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "[{]", "[\\]",
                         "[}]", "[']", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
                         "", "", "", "", "", "", "[Attn]", "[CrSel]", "[ExSel]", "[ErEOF]", "播放键",
                         "缩放键", "", "[PA1]", "清除键"
                        };

inline void color(int a) {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), a);
}

inline void gto(int x, int y) {
	COORD pos;
	pos.X = y;
	pos.Y = x;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

HWND MyhWnd;
bool IsConsoleFocused() {
    HWND NowHwnd = GetForegroundWindow();
	if (NowHwnd == MyhWnd) {
		return 1;
	} else if (KEY_DOWN(18) && KEY_DOWN(16)) {
		return 1;
	}
	return 0;
}

void clearScreen() {
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    DWORD count;
    DWORD cellCount;
    COORD homeCoords = {0, 0};

    if (hConsole == INVALID_HANDLE_VALUE) return;
    if (!GetConsoleScreenBufferInfo(hConsole, &csbi)) return;

    cellCount = csbi.dwSize.X * csbi.dwSize.Y;
    // 用空格填充整个缓冲区
    FillConsoleOutputCharacter(hConsole, (TCHAR)' ', cellCount, homeCoords, &count);
    // 恢复默认颜色属性
    FillConsoleOutputAttribute(hConsole, csbi.wAttributes, cellCount, homeCoords, &count);
    // 光标归位
    SetConsoleCursorPosition(hConsole, homeCoords);
}

int Rand_Seed;
inline int Rand() {
	Rand_Seed ^= rand();
	Rand_Seed ^= Rand_Seed >> 7;
	Rand_Seed ^= Rand_Seed << 13;
	Rand_Seed ^= Rand_Seed >> 17;
	return Rand_Seed;
}

inline int RandInt(int l, int r) {
	int res = Rand();
	return res % (r - l + 1) + l;
}

bool cundang(), read(string name);
bool game_prepare();
void start(), jiaocheng(), new_game(), work();
void Map_Generate(), attack(Object o, Object Issue);
void whichxitong(), dlt(string name), save(string name);

void whichxitong() {
	typedef void(__stdcall * NTPROC)(DWORD *, DWORD *, DWORD *);
	HINSTANCE hinst = LoadLibrary("ntdll.dll");
	DWORD dwMajor, dwMinor, dwBuildNumber;
	NTPROC proc = (NTPROC)GetProcAddress(hinst, "RtlGetNtVersionNumbers");
	proc(&dwMajor, &dwMinor, &dwBuildNumber);
	if (dwMajor == 10 && dwMinor == 0) {
		xt = 10;
		return ;
	}
	SYSTEM_INFO info;
	GetSystemInfo(&info);
	OSVERSIONINFOEX os;
	os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
	if (GetVersionEx((OSVERSIONINFO *)&os)) {
		if (os.dwMajorVersion == 6 && os.wProductType == VER_NT_WORKSTATION) {
			xt = 7;
		}
	}
}

int main() {
	SetConsoleTitle("三体           v beta.2.0");
	MyhWnd = GetForegroundWindow();
	srand((unsigned)time(NULL));
	Rand_Seed = rand();
	for (int i = 1; i <= 256; i++) {
		if (!KEY_DOWN(i)) {
			isup[i] = 1;
		}
	}
	start();
	return 0;
}

bool read(string name) {
	string str = name + ".save";
	char ch[30];
	memset(ch, 0, sizeof ch);
	for (unsigned int i = 0; i < str.size(); i++) {
		ch[i] = str[i];
	}
	char *s = ch;
	FILE *fp = fopen(s, "r");
	fscanf(fp, "%d%d%d", &Sun_Num, &Civil_Num, &Code_Top);
	for (int i = 1; i <= Code_Top; i++) {
		fscanf(fp, "%d", &Code_stk[i]);
	}
	for (int i = 1; i <= 10; i++) {
		fscanf(fp, "%lf", &visdis[i]);
	}
	fscanf(fp, "%d%d%d%d", &nowvis, &nowamod, &STOP, &turning);
	fscanf(fp, "%lf%lf%lf%lf", &Max_Fuel, &Fuel, &Time_Sum, &Time_Speed);
	fscanf(fp, "%lf%lf%lf%d%lf%lf%d%lf%lf%lf%lf", &Me.a, &Me.b, &Me.blood, &Me.code, &Me.theta, &Me.Time, &Me.type, &Me.v, &Me.vtheta, &Me.x, &Me.y);
	long long int Size;
	Object o;
	fscanf(fp, "%lld", &Size);
	Objects.clear();
	for (int i = 1; i <= Size; i++) {
		fscanf(fp, "%lf%lf%lf%d%lf%lf%d%lf%lf%lf%lf", &o.a, &o.b, &o.blood, &o.code, &o.theta, &o.Time, &o.type, &o.v, &o.vtheta, &o.x, &o.y);
		Objects.push_back(o);
	}
	fscanf(fp, "%lld", &Size);
	Create_Issue.clear();
	for (int i = 1; i <= Size; i++) {
		fscanf(fp, "%lf%lf%lf%d%lf%lf%d%lf%lf%lf%lf", &o.a, &o.b, &o.blood, &o.code, &o.theta, &o.Time, &o.type, &o.v, &o.vtheta, &o.x, &o.y);
		Create_Issue.push_back(o);
	}
	fscanf(fp, "%lld", &Size);
	Light_Issue.clear();
	for (int i = 1; i <= Size; i++) {
		fscanf(fp, "%lf%lf%lf%d%lf%lf%d%lf%lf%lf%lf", &o.a, &o.b, &o.blood, &o.code, &o.theta, &o.Time, &o.type, &o.v, &o.vtheta, &o.x, &o.y);
		Light_Issue.insert(o);
	}
	fscanf(fp, "%lld", &Size);
	Show_Issue.clear();
	Show sh(o);
	for (int i = 1; i <= Size; i++) {
		fscanf(fp, "%d%d%lf%lf", &sh.code, &sh.type, &sh.x, &sh.y);
		Show_Issue.insert(sh);
	}
	fclose(fp);
	save(name);
	return 1;
}

void save(string name) {
	name += ".save";
	char ch[30];
	memset(ch, 0, sizeof ch);
	for (unsigned int i = 0; i < name.size(); i++) ch[i] = name[i];
	char *s = ch;
	FILE *fp = fopen(s, "w");
	fprintf(fp, "%d %d %d ", Sun_Num, Civil_Num, Code_Top);
	for (int i = 1; i <= Code_Top; i++) {
		fprintf(fp, "%d ", Code_stk[i]);
	}
	for (int i = 1; i <= 10; i++) {
		fprintf(fp, "%lf ", visdis[i]);
	}
	fprintf(fp, "%d %d %d %d ", nowvis, nowamod, STOP, turning);
	fprintf(fp, "%lf %lf %lf %lf ", Max_Fuel, Fuel, Time_Sum, Time_Speed);
	fprintf(fp, "%lf %lf %lf %d %lf %lf %d %lf %lf %lf %lf \n", Me.a, Me.b, Me.blood, Me.code, Me.theta, Me.Time, Me.type, Me.v, Me.vtheta, Me.x, Me.y);
	fprintf(fp, "%lld ", Objects.size());
	for (auto o : Objects) {
		fprintf(fp, "%lf %lf %lf %d %lf %lf %d %lf %lf %lf %lf ", o.a, o.b, o.blood, o.code, o.theta, o.Time, o.type, o.v, o.vtheta, o.x, o.y);
	}
	fprintf(fp, "%lld ", Create_Issue.size());
	for (auto o : Create_Issue) {
		fprintf(fp, "%lf %lf %lf %d %lf %lf %d %lf %lf %lf %lf ", o.a, o.b, o.blood, o.code, o.theta, o.Time, o.type, o.v, o.vtheta, o.x, o.y);
	}
	fprintf(fp, "%lld ", Light_Issue.size());
	for (auto o : Light_Issue) {
		fprintf(fp, "%lf %lf %lf %d %lf %lf %d %lf %lf %lf %lf ", o.a, o.b, o.blood, o.code, o.theta, o.Time, o.type, o.v, o.vtheta, o.x, o.y);
	}
	fprintf(fp, "%lld ", Show_Issue.size());
	for (auto o : Show_Issue) {
		fprintf(fp, "%d %d %lf %lf ", o.code, o.type, o.x, o.y);
	}
	fclose(fp);
	return ;
}

void start() {
A:
	system("cls");
	system("mode con cols=40 lines=30");
	int isk = 1, lst = 0;
	color(7), gto(7, 10), printf("三体  v beta.2.0");
B:
	gto(13, 25), printf("开始教程!");
	gto(15, 25), printf("新游戏!");
	gto(17, 25), printf("读取存档!");
	color(13);
	if (isk == 1) {
		gto(13, 25), printf("开始教程!");
	} else if (isk == 2) {
		gto(15, 25), printf("新游戏!");
	} else {
		gto(17, 25), printf("读取存档!");
	}
	color(7);
	gto(29, 39);
	while (1) {
		Sleep(30);
		if (!KEY_DOWN(40)) isup[40] = 1;
		if (!KEY_DOWN(38)) isup[38] = 1;
		if (!KEY_DOWN(27)) isup[27] = 1;
		if (isup[40] && KEY_DOWN(40)) isup[40] = 0, isk = min(3, isk + 1), Sleep(30);
		if (isup[38] && KEY_DOWN(38)) isup[38] = 0, isk = max(1, isk - 1), Sleep(30);
		if (isk != lst) {
			lst = isk;
			goto B;
		}
		if (KEY_DOWN(13)) {
			if (isk == 1) {
				jiaocheng();
				goto A;
			} else if (isk == 2) {
				new_game();
				if (!game_prepare()) return ;
				goto A;
			} else {
				if (cundang()) if (!game_prepare()) return ;
				goto A;
			}
		}
		if (isup[27] && KEY_DOWN(27)) {
			isup[27] = 0;
			break;
		}
	}
	return ;
}

vector<string> vec;
vector<int> TS, Bld;
bool cundang() {
	vec.clear(), TS.clear(), Bld.clear();
	system("cls"), Sleep(100);
	struct _finddata_t filefind;
	string curr = "./*.save", now;
	int handle = _findfirst(curr.c_str(), &filefind);
	if (handle == -1) {
		gto(12, 6), color(12), printf("您还没有存档!按[Enter]返回!"), color(7);
		while (1) {
			Sleep(50);
			if (KEY_DOWN(13)) break;
		}
		return 0;
	}
	do {
		if (!strcmp(filefind.name, "..")) continue;
		now = filefind.name;
		now.erase(now.end() - 5, now.end());
		vec.push_back(now);
	} while (!(_findnext(handle, &filefind)));
	_findclose(handle);
	int num = vec.size(), which = 0, lst = 0;
	for (int i = 0; i < num; i++) {
		read(vec[i]);
		TS.push_back(Time_Sum);
		Bld.push_back(Me.blood);
	}
A:
	system("cls"), color(7);
	gto(0, 5), printf("press [Enter] to chose;");
	gto(1, 5), printf("press [Delete] to remove;");
	gto(2, 5), printf("press [Esc] to exit.");
	for (int i = 0; i < num; i++) {
		gto((i + 1) * 3 + 1, 4), printf("生存时间: %d 天", TS[i]);
	}
B:
	for (int i = 0; i < num; i++) {
		gto((i + 1) * 3, 6);
		if (i == which) color(12);
		else color(7);
		cout << vec[i] << "        血量:" << Bld[i];
	}
	gto(29, 39);
	while (1) {
		Sleep(50);
		if (KEY_DOWN(40)) {
			which = min(num - 1, which + 1);
			Sleep(30);
		}
		if (KEY_DOWN(38)) {
			which = max(0, which - 1);
			Sleep(30);
		}
		if (which != lst) {
			lst = which;
			goto B;
		}
		if (KEY_DOWN(13)) {
			thisgamename = vec[which];
			read(thisgamename);
			break;
		}
		if (KEY_DOWN(46)) {
			thisgamename = vec[which];
			dlt(thisgamename);
			vec.erase(vec.begin() + which);
			TS.erase(TS.begin() + which);
			num--, which = 0;
			goto A;
		}
		if (KEY_DOWN(27) || num == 0) return 0;
	}
	return 1;
}

void dlt(string name) {
	name += ".save";
	char ch[30];
	memset(ch, 0, sizeof ch);
	for (unsigned int i = 0; i < name.size(); i++) {
		ch[i] = name[i];
	}
	char *s = ch;
	remove(s);
}

void jiaocheng() {
	system("cls");
	gto(8, 0);
	printf("上下左右对应引擎操纵,注意左右键操控的是左右转速的加减,不按时自动转速逐渐归零\n\n");
	printf("右侧有燃料余量表,注意 1%% 以下时无法使用前进/后退五\n\n");
	printf("加减号用来调整地图缩放\n\n");
	printf("小于大于号用来调整时间流速\n\n");
	printf("游戏中每一分钟会自动存档,如果想自行存档请按 [s] 键\n\n\n");
	system("pause");
}

void new_game() {
	system("cls"), system("mode con cols=100 lines=30");
	gto(10, 30), printf("为坠落的存档命名:");
	fflush(stdin);
	cin >> thisgamename;
	gto(15, 20), printf("输入恒星数量 & 文明数量:(建议40、50)\n");
	scanf("%d%d", &Sun_Num, &Civil_Num);
	Objects.clear(), Create_Issue.clear(), Light_Issue.clear(), Show_Issue.clear();
	Code_Top = 0;
	for (int i = MapRange; i; i--) Code_stk[++Code_Top] = i;
	visdis[1] = 10, visdis[2] = visdis[10] = 1, visdis[3] = 3, visdis[4] = 20;
	nowvis = 1, nowamod = 0, STOP = 0, turning = 0;
	Max_Fuel = 800000, Fuel = 600000, Time_Sum = 0, Time_Speed = 1;
	Map_Generate();
	save(thisgamename);
}

bool game_prepare() {
	system("cls"), system("mode con cols=100 lines=30");
	lastsavetime = lasttime = chrono::steady_clock::now();
	work();
	return 1;
}

void Map_Generate() {
	Object o(1, Code_stk[Code_Top--], MapRange / 2, MapRange / 2, 0);
	o.blood = 10000;
	Objects.push_back(o);
	for (int i = 1; i <= Sun_Num; i++) {
		double x, y, v, vtheta;
		x = 1.0 * RandInt(0, MapRange);
		y = 1.0 * RandInt(0, MapRange);
		v = 0.08 * RandInt(0, MapRange) / MapRange;
		vtheta = 2.0 * pi * RandInt(0, MapRange) / MapRange;
		Object o(1, Code_stk[Code_Top--], x, y, v, 0, vtheta);
		o.blood = 10000;
		Objects.push_back(o);
	}
	for (int i = 1; i <= Civil_Num; i++) {
		double x, y, v, vtheta;
		x = 1.0 * RandInt(0, MapRange);
		y = 1.0 * RandInt(0, MapRange);
		v = 24.0 * RandInt(0, MapRange) / MapRange;
		vtheta = 2.0 * pi * RandInt(0, MapRange) / MapRange;
		Object o(2, Code_stk[Code_Top--], x, y, v, 0, vtheta);
		o.blood = 10000.0 * RandInt(MapRange / 20, MapRange) / MapRange;
		Objects.push_back(o);
	}
	Object oo(10, Code_stk[Code_Top--], MapRange / 2 + 3, MapRange / 2, 0, 0, 3 * pi / 2);
	Me = oo;
	Me.blood = 1000;
}

void txv_update(double Speed = 1.0) {
	nowtime = steady_clock::now();
	deltaT = duration_cast<microseconds>(nowtime - lasttime).count() / 1000000.0;
	lasttime = nowtime;
	deltat = deltaT / sqrt(1 - pow(Me.v / c, 2)) * Time_Speed * Speed;
	Time_Sum += deltat;
	for (auto &o : Objects) {
//		if (sqrt(pow(o.x - Me.x, 2) + pow(o.y - Me.y, 2)) > visdis[o.type] * 360 * 2) continue;
		if (o.type != 4 && o.v > 0.9999 * c) o.v = 0.9999 * c;
		if (o.type != 4 && o.v < -0.9999 * c) o.v = -0.9999 * c;
		o.update(deltat);
		if (o.x < 0) o.x += MapRange;
		if (o.x > MapRange) o.x -= MapRange;
		if (o.y < 0) o.y += MapRange;
		if (o.y > MapRange) o.y -= MapRange;
		if ((abs(floor(o.x) - floor(o.x - o.v * deltat * cos(o.theta)) > 0) ||
			abs(floor(o.y) - floor(o.y - o.v * deltat * sin(o.theta))) > 0) && 
			sqrt(pow(o.x - Me.x, 2) + pow(o.y - Me.y, 2)) <= visdis[o.type] * 360 * 2) {
			Light_Issue.insert(o);
		}
	}
	if (STOP == 1) {
		if (Me.v > inm) nowamod = -5;
		else STOP = 0, nowamod = 0, Me.v = 0;
	} else if (STOP == -1) {
		if (Me.v < -inm) nowamod = 5;
		else STOP = 0, nowamod = 0, Me.v = 0;
	}
	if (Me.v > 0.999 * c) Me.v = 0.999 * c, nowamod = 0;
	if (Me.v < -0.999 * c) Me.v = -0.999 * c, nowamod = 0;
	if (Fuel < inm) nowamod = 0;
	else if (Fuel / Max_Fuel <= 0.01) {
		if (nowamod == 5) nowamod--;
		if (nowamod == -5) nowamod++;
	}
	if (abs(nowamod) == 5) nowamod *= 10;
	Fuel -= deltat * abs(nowamod) * 10;
	Me.a = 6912.0 * nowamod / 1000000;
	if (abs(nowamod) > 5) nowamod /= 10;
	if (turning == 1 || (turning == 0 && Me.vtheta < -pi / 180)) Me.b = pi / 180;
	else if (turning == -1 || (turning == 0 && Me.vtheta > pi / 180)) Me.b = -pi / 180;
	else Me.b = 0, Me.vtheta = 0;
	auto old_Me = Me;
	Me.update(deltat);
	if (Me.v > 0.999 * c) Me.v = 0.999 * c;
	if (Me.v < -0.999 * c) Me.v = -0.999 * c;
	if (Me.x < 0) Me.x = 0;
	if (Me.x > MapRange) Me.x = MapRange;
	if (Me.y < 0) Me.y = 0;
	if (Me.y > MapRange) Me.y = MapRange;
	if (abs(floor(Me.x) - floor(old_Me.x)) > 0 ||
		abs(floor(Me.y) - floor(old_Me.y)) > 0) {
		Light_Issue.insert(Me);
	}
}

set<Object> tempset; 
steady_clock::time_point lastupdatetime;
void Light_Issue_Update() {
	nowtime = steady_clock::now();
	if (duration_cast<milliseconds>(nowtime - lastupdatetime).count() >= 1000) {
		lastupdatetime = nowtime;
		for (auto o : Objects) {
			if (o.v < 1) Light_Issue.insert(o);
		}
		if (Me.v < 1) Light_Issue.insert(Me);
	}
	for (auto it = Light_Issue.begin(); it != Light_Issue.end(); ) {
		Object Issue = *it;
		if (Time_Sum - Issue.Time > visdis[Issue.type] * 360) {
			it = Light_Issue.erase(it);
			continue;
		}
		if (Issue.type == 1 || Issue.type == 3) {
			if (Time_Sum - Issue.Time >= sqrt(pow(Issue.x - Me.x, 2) + pow(Issue.y - Me.y, 2)) / c) {
				Show_Issue.erase(Show(Issue));
				if (Issue.isShow) Show_Issue.insert(Show(Issue));
				it = Light_Issue.erase(it);
			} else it++;
		} else {
			if (Time_Sum >= inm) for (auto &o : Objects) {
				if (o.type != 2 || o.code == Issue.code) continue;
				double VisTime = sqrt(pow(Issue.x - o.x, 2) + pow(Issue.y - o.y, 2)) / c;
				if (Time_Sum - Issue.Time >= VisTime && 
					Time_Sum - Issue.Time <= VisTime + deltat && 
					Time_Sum - o.lastattacktime > 100) {
					o.lastattacktime = Time_Sum;
					o.firecnt++;
					attack(o, Issue);
				}
			}
			if (Time_Sum - Issue.Time >= sqrt(pow(Issue.x - Me.x, 2) + pow(Issue.y - Me.y, 2)) / c && Issue.isSaw == 0) {
				Issue.isSaw = 1;
				it = Light_Issue.erase(it);
				tempset.insert(Issue);
				Show_Issue.erase(Show(Issue));
				Show_Issue.insert(Show(Issue));
			} else it++;
		}
	}
	for (auto o : tempset) Light_Issue.insert(o);
	tempset.clear();
}

void attack(Object o, Object Issue) {
	double t0 = o.Time - Issue.Time, x = Issue.x - o.x, y = Issue.y - o.y;
	double vx = Issue.v * cos(Issue.theta), vy = Issue.v * sin(Issue.theta);
	double kc = c * min(o.blood / 10000, 0.9);
	double delta = pow(vx * x + vy * y + kc * kc * t0, 2) - (vx * vx + vy * vy - kc * kc) * (x * x + y * y - kc * kc * t0 * t0);
	delta *= 4.0;
	if (delta < inm) return ;
	double a = vx * vx + vy * vy - kc * kc, b = 2 * (vx * x + vy * y + kc * kc * t0);
	double t1 = (-b + sqrt(delta)) / (2 * a), t2 = (-b - sqrt(delta)) / (2 * a);
	if (t1 < inm) t1 = t2;
	x += vx * t1, y += vy * t1;
	double theta = atan2(y, x);
	auto newo = Object(3, o.code, o.x, o.y, kc, 0, theta);
	newo.id = o.firecnt;
	Create_Issue.push_back(newo);
}

void Damage_Judge() {
	for (auto it = Objects.begin(); it != Objects.end(); it++) {
		auto o1 = *it;
		if (o1.type == 4) continue;
		double o1vx = o1.v * cos(o1.theta), o1vy = o1.v * sin(o1.theta);
		for (auto lt = it + 1; lt != Objects.end(); lt++) {
			auto o2 = *lt;
			if (o2.type == 4 || (o1.type == 1 && o2.type == 1) || (o1.type == 3 && o2.type == 3) || (o1.code == o2.code)) {
				continue;
			}
			if (pow(o1.x - o2.x, 2) + pow(o1.y - o2.y, 2) >= 1.0 || o1.code == o2.code) continue;
			double o2vx = o2.v * cos(o2.theta), o2vy = o2.v * sin(o2.theta);
			double vre = sqrt(pow(o1vx - o2vx, 2) + pow(o1vy - o2vy, 2));
			it->blood -= 100.0 / sqrt(1 - pow(vre / c, 2));
			lt->blood -= 100.0 / sqrt(1 - pow(vre / c, 2));
			if (o1.type == 1) lt->blood = -1;
			if (o2.type == 1) it->blood = -1;
		}
		if (pow(o1.x - Me.x, 2) + pow(o1.y - Me.y, 2) >= 0.5) continue;
		double Mevx = Me.v * cos(Me.theta), Mevy = Me.v * sin(Me.theta);
		double vre = sqrt(pow(o1vx - Mevx, 2) + pow(o1vy - Mevy, 2));
		it->blood -= 100.0 / sqrt(1 - pow(vre / c, 2));
		Me.blood -= 100.0 / sqrt(1 - pow(vre / c, 2));
		if (o1.type == 1) Me.blood = -1;
	}
	for (auto it = Objects.begin(); it != Objects.end(); ) {
		auto o = *it;
		if (o.blood > inm) {
			it++; continue;
		}
		if (o.type != 3) Create_Issue.push_back(Object(o.type, 0, 0, 0, 0)), Code_stk[++Code_Top] = o.code;
		it = Objects.erase(it);
		Light_Issue.erase(o);
		o.isShow = 0;
		Light_Issue.insert(o);
	}
}

void Object_Issue_Update() {
	//Add Fuel
	int cnt = 0;
	for (auto o : Objects) {
		double omdis = sqrt(pow(o.x - Me.x, 2) + pow(o.y - Me.y, 2));
		if (omdis <= 5000.0) ++cnt, gto(3 + cnt, 2), printf("距离 %.1lf 血量 %.0lf", omdis, o.blood);
		if (o.type != 1) continue;
		if (omdis <= 10.0) {
			Fuel = min(Max_Fuel + 1, Fuel + 2000 / omdis * deltat);
		}
	}
	//Create
	for (auto o : Create_Issue) {
		int type = o.type, code = o.code, id = o.id;
		double x = o.x, y = o.y, v = o.v, theta = o.theta, blood = o.blood;
		if (type != 3) theta = 2 * pi * RandInt(0, MapRange) / MapRange, code = Code_stk[Code_Top--];
		int edge = RandInt(1, 4);
		if (type != 3) {
			if (edge == 1) x = 0, y = RandInt(0, MapRange);
			else if (edge == 2) x = MapRange, y = RandInt(0, MapRange);
			else if (edge == 3) x = RandInt(0, MapRange), y = 0;
			else x = RandInt(0, MapRange), y = MapRange;
		}
		if (type == 1) blood = 10000, v = 0.08 * RandInt(0, MapRange) / MapRange;
		else if (type == 2) {
			blood = 10000.0 * RandInt(MapRange / 20, MapRange) / MapRange;
			v = 24.0 * RandInt(0, MapRange) / MapRange;
		} else if (type == 3) blood = 1;
		Object newo(type, code, x, y, v, 0, theta);
		newo.blood = blood, newo.id = id;
		Objects.push_back(newo);
	}
	Create_Issue.clear();
}

steady_clock::time_point lastshowtime;
bool Light_Show() {
	nowtime = steady_clock::now();
	if (duration_cast<milliseconds>(nowtime - lastshowtime).count() < 200) return 0;
	lastshowtime = nowtime;
	clearScreen();
	int xlen = 50 * pow(4, nowvis - 1), ylen = 30 * pow(4, nowvis - 1);
	for (auto s : Show_Issue) {
		if (abs(s.x - Me.x) > xlen / 2 || abs(s.y - Me.y) > ylen / 2) continue;
		int gtox = (xlen / 2 + s.x - Me.x) * 100 / xlen;
		int gtoy = (ylen / 2 + s.y - Me.y) * 30 / ylen;
		if (gtox < 0 || gtox >= 100 || gtoy < 0 || gtoy >= 29) continue;
		gto(gtoy, gtox);
		if (s.type == 1) {
			color(96), putchar(' '); if (gtox < 99) putchar(' ');
		} else if (s.type == 2) {
			color(240), putchar(' '); if (gtox < 99) putchar(' ');
		} else if (s.type == 3) {
			color(64), putchar(' '); if (gtox < 99) putchar(' ');
		} else if (s.type == 4) {
			color(144), putchar(' '); if (gtox < 99) putchar(' ');
		}
	}
	double l = (xlen / 2.0 - Me.x) * 50 / xlen, r = (xlen / 2.0 + MapRange - Me.x) * 50 / xlen;
	double u = (ylen / 2.0 - Me.y) * 30 / ylen, d = (ylen / 2.0 + MapRange - Me.y) * 30 / ylen;
	color(240);
	if (0 <= u && u < 29) {
		gto(u, max(0.0, l * 2 + 1));
		for (int i = max(0.0, l * 2 + 1); i < min(100.0, r * 2 + 1); i++) {
			putchar(' ');
		}
	}
	if (0 <= d && d < 29) {
		gto(d, max(0.0, l * 2 + 1));
		for (int i = max(0.0, l * 2 + 1); i <= min(100.0, r * 2 + 1); i++) {
			putchar(' ');
		}
	}
	if (0 <= l && l < 49) {
		for (int i = max(0.0, u); i < min(30.0, d); i++) {
			gto(i, l * 2), putchar(' ');
		}
	}
	if (0 <= r && r <= 49) {
		for (int i = max(0.0, u); i < min(30.0, d); i++) {
			gto(i, r * 2 + 1), putchar(' ');
		}
	}
	gto(15, 50);
	color(240), putchar(' '), putchar(' ');
	color(7), gto(29, 99), putchar(' ');
	return 1;
}

string num[] = {"", "一", "二", "三", "四", "五"}; 
void UI_Show() {
	//deltaT
	gto(2, 82), printf("deltaT = %.0lfms", deltaT * 1000);
	//Engine Mod & Speed & Time
	gto(20, 2), printf("______");
	gto(24, 2), printf(xt == 7 ? "▔▔▔" : "▔▔▔▔▔");
	gto(22, 2);
	if (nowamod > 0) {
		color(226);
		if (STOP == -1) color(82);
		cout << "前进" << num[nowamod];
		color(7), gto(23, 2);
		if (nowamod == 1) cout << " 停车 ";
		else cout << "前进" << num[nowamod - 1];
		gto(21, 2);
		if (nowamod != 5) cout << "前进" << num[nowamod + 1];
	} else if (nowamod < 0) {
		color(236);
		if (STOP == 1) color(92);
		cout << "后退" << num[-nowamod];
		color(7), gto(21, 2);
		if (nowamod == -1) cout << " 停车 ";
		else cout << "后退" << num[-nowamod - 1];
		gto(23, 2);
		if (nowamod != -5) cout << "后退" << num[-nowamod + 1];
	} else {
		color(229);
		cout << " 停车 ";
		color(7), gto(23, 2), cout << "后退一"; 
		gto(21, 2), cout << "前进一";
	}
	color(7);
	gto(22, 8);
	printf("  %.2lf%%c", Me.v / c * 100);
	gto(28, 2);
	printf("时间比  %.1lf 天 / s", Time_Speed / sqrt(1 - pow(Me.v / c, 2)));
	//Scale
	gto(28, 80);
	printf("地图等级  第 %d 级", nowvis);
	gto(29, 80);
	printf("1 格 = ");
	if (nowvis <= 3) printf("%.0lf 光时", pow(4, nowvis - 1));
	else if (nowvis <= 6) printf("%.2lf 光天", pow(4, nowvis - 1) / 24.0);
	else if (nowvis <= 7) printf("%.2lf 光月", pow(4, nowvis - 1) / 24.0 / 30.0);
	else printf("%.2lf 光年", pow(4, nowvis - 1) / 24.0 / 30.0 / 12.0);
	//Direction
	if (Me.theta > pi) {
		gto(25, 50);
		color(208), putchar(' '), color(7);
		gto(25, 50 + (2 * Me.theta / pi - 3) * 10);
		color(160), putchar(' '), color(7);
		gto(24, 49), printf("%2d", int(Me.theta / pi * 180) - 270);
	} else {
		gto(27, 50);
		color(208), putchar(' '), color(7);
		gto(27, 50 + (-2 * Me.theta / pi + 1) * 10);
		color(160), putchar(' '), color(7);
		gto(28, 49), printf("%2d", int(Me.theta / pi * 180) - 90);
	}
	//Position & Time
	int x = floor(Me.x - MapRange / 2), xcnt = 0;
	if (x <= 0) x = -x, xcnt++;
	while (x) x = x / 10, xcnt++; 
	gto(26, 48 - xcnt);
	printf("(%d , %d)", int(Me.x - MapRange / 2), int(MapRange / 2 - Me.y));
	gto(1, 2);
	printf("%d 年 %2d 月 %2d 日", int(Time_Sum / 360), int(Time_Sum / 30) % 12, int(Time_Sum) % 30);
	//Fuel
	double FuelPercent = Fuel / Max_Fuel;
	gto(25, 85), printf(Fuel < Max_Fuel ? "Fuel: %2d%%" : "Fuel: %3d%%", int(FuelPercent * 100));
	int FuelColor;
	if (FuelPercent < 0.1) FuelColor = 64;
	else if (FuelPercent < 0.2) FuelColor = 192;
	else if (FuelPercent < 0.7) FuelColor = 96;
	else if (FuelPercent < 0.9) FuelColor = 32;
	else FuelColor = 160;
	for (int i = 1; i <= int(FuelPercent * 16); i++) {
		gto(25 - i, 87), color(FuelColor);
		putchar(' '), putchar(' '), putchar(' '), putchar(' '), putchar(' '), putchar(' ');
		color(7);
	}
	//Blood
	gto(4, 84), printf("血量:%.0lf", Me.blood); 
	//Return
	gto(29, 99);
}

bool Key_Judge() {
	if (!IsConsoleFocused()) return 0;
	nowtime = steady_clock::now();
	for (int i = 1; i <= 256; i++) if (!KEY_DOWN(i)) isup[i] = 1;
	if (isup[187] && KEY_DOWN(187)) isup[187] = 0, nowvis = max(1, nowvis - 1);
	if (isup[189] && KEY_DOWN(189)) isup[189] = 0, nowvis = min(8, nowvis + 1);
	if (isup[38] && KEY_DOWN(38)) isup[38] = 0, nowamod = min(5, nowamod + 1), STOP = 0;
	if (isup[40] && KEY_DOWN(40)) isup[40] = 0, nowamod = max(-5, nowamod - 1), STOP = 0;
	if (isup[66] && KEY_DOWN(66)) isup[66] = 0, STOP = Me.v > 0 ? 1 : -1;
	if (KEY_DOWN(37)) isup[37] = 0, turning = -1;
	if (KEY_DOWN(39)) isup[39] = 0, turning = 1;
	if (isup[37] && isup[39]) turning = 0;
	if ((isup[83] && KEY_DOWN(83)) || duration_cast<milliseconds>(nowtime - lastsavetime).count() > 60000) {
		if (duration_cast<milliseconds>(nowtime - lastsavetime).count() >= 60000) {
			gto(13, 45), printf("自动");
		} else gto(13, 46), isup[83] = 0;
		lastsavetime = nowtime;
		nowtime = steady_clock::now();
		printf("存档中……");
		save(thisgamename);
		lasttime += steady_clock::now() - nowtime;
	}
	if (isup[27] && KEY_DOWN(27)) {
		isup[27] = 0;
		return 1;
	}
	if (isup[188] && KEY_DOWN(188)) isup[188] = 0, Time_Speed = max(0.0, Time_Speed - 0.5);
	if (isup[190] && KEY_DOWN(190)) isup[190] = 0, Time_Speed = min(4.0, Time_Speed + 0.5);
	return 0;
}

void work() {
	if (Time_Sum < inm) {
		Time_Sum -= 3600;
		gto(20, 33), printf("世界加载中:");
		while (Time_Sum < inm) {
			txv_update(50);
			Object_Issue_Update();
			Light_Issue_Update();
			gto(20, 45);
			color(240);
			for (int i = 1; i <= int(20.0 * (3600 + Time_Sum) / 3600); i++) putchar(' ');
			color(7);
			gto(20, 66), printf("%3d%%", int((3600.0 + Time_Sum) / 36));
		}
	}
	Object o = Object(4, 0, MapRange / 2, MapRange / 2);
	o.Time = Time_Sum;
	Light_Issue.insert(o);
	save(thisgamename);
	while (1) {
		txv_update();
		Damage_Judge();
		Object_Issue_Update();
		Light_Issue_Update();
		if (Light_Show()) UI_Show();
		if (Key_Judge()) break;
		this_thread::sleep_for(microseconds(max(0, 1000 - int(deltaT * 1000000))));
	}
	save(thisgamename);
}
原文