解出factorio space exp中的Interburbul小游戏的脚本
直接上代码,玩家自行编译
由于脚本中含有中文,如果在终端中出现乱码,请将源文件的编码格式改为GBK,或将终端的显示格式改为UTF-8(或者将所有中文陈述换为英文)。
#include <windows.h>
#include <iostream>
#include <cmath>
using namespace std;
class Point
{
public:
double x;
double y;
double z;
void printPoint()
{
printf("该点坐标为:(%lf,%lf,%lf)\n", x, y, z);
}
};
class Grid
{
public:
int x;
int y;
};
void Initialization(int& grid_len, Grid& target_grid, Point& top_left, Point& top_right, Point& bottom_left);
Point GetShadowCenter(int grid_len, Grid target_grid, Point top_left, Point top_right, Point bottom_left);
int main()
{
int grid_len; // 栅格大小
Grid target_grid; // 目标格
Point top_left, top_right, bottom_left; // 已知三点坐标
bool restart = false;
unsigned int loop_times = 0;
printf("脚本制作人:CYD88659\n");
printf("如果你需要连续使用该脚本多次,请输入y: ");
char input_result = getchar();
getchar();
if (input_result == 'y' || input_result == 'Y')
{
restart = true;
}
while (restart == true)
{
printf("这是第%u次执行该脚本\n", loop_times);
Initialization(grid_len, target_grid, top_left, top_right, bottom_left);
// 计算阴影部分的中间点坐标
GetShadowCenter(grid_len, target_grid, top_left, top_right, bottom_left).printPoint();
loop_times++;
}
if(restart == false)
{
Initialization(grid_len, target_grid, top_left, top_right, bottom_left);
// 计算阴影部分的中间点坐标
GetShadowCenter(grid_len, target_grid, top_left, top_right, bottom_left).printPoint();
}
return 0;
}
void Initialization(int& grid_len, Grid& target_grid, Point& top_left, Point& top_right, Point& bottom_left)
{
printf("请输入栅格大小:");
scanf("%d", &grid_len);
getchar();
printf("请输入目标格,格式:(x,y)\n");
scanf("(%d,%d)", &target_grid.x, &target_grid.y);
getchar();
printf("请输入左上角坐标,格式:(x,y,z)\n");
scanf("(%lf,%lf,%lf)", &top_left.x, &top_left.y, &top_left.z);
getchar();
printf("请输入右上角坐标,格式:(x,y,z)\n");
scanf("(%lf,%lf,%lf)", &top_right.x, &top_right.y, &top_right.z);
getchar();
printf("请输入左下角坐标,格式:(x,y,z)\n");
scanf("(%lf,%lf,%lf)", &bottom_left.x, &bottom_left.y, &bottom_left.z);
getchar();
}
/* 要计算阴影部分中心点所在坐标 */
Point GetShadowCenter(int grid_len, Grid target_grid, Point top_left, Point top_right, Point bottom_left)
{
Point unit_offset_horizontal, unit_offset_vertical;
unit_offset_horizontal.x = (top_right.x - top_left.x) / grid_len; // 水平方向发生的总位移,除以格子数量表示移动单位格子长度时所发生的偏移
unit_offset_horizontal.y = (top_right.y - top_left.y) / grid_len;
unit_offset_horizontal.z = (top_right.z - top_left.z) / grid_len;
unit_offset_vertical.x = (bottom_left.x - top_left.x) / grid_len; // 垂直方向发生的总位移,除以格子数量表示移动单位格子长度时所发生的偏移
unit_offset_vertical.y = (bottom_left.y - top_left.y) / grid_len;
unit_offset_vertical.z = (bottom_left.z - top_left.z) / grid_len;
Point result_vector = top_left; // 将初始点定为左上角,将target_grid的x方向定义为二维俯视横向,grid的y方向定义为二维俯视纵向
/* 首先从横向开始下降 */
result_vector.x = result_vector.x + unit_offset_horizontal.x * (target_grid.x - 0.5);
result_vector.y = result_vector.y + unit_offset_horizontal.y * (target_grid.x - 0.5);
result_vector.z = result_vector.z + unit_offset_horizontal.z * (target_grid.x - 0.5);
/* 纵向开始下降 */
result_vector.x = result_vector.x + unit_offset_vertical.x * (target_grid.y - 0.5);
result_vector.y = result_vector.y + unit_offset_vertical.y * (target_grid.y - 0.5);
result_vector.z = result_vector.z + unit_offset_vertical.z * (target_grid.y - 0.5);
return result_vector;
}