解出factorio space exp中的Interburbul小游戏的脚本

文章介绍了如何在C++编程中实现Interburbul小游戏的脚本,包括`Initialization`和`GetShadowCenter`函数,用于计算阴影部分的中间点坐标,以及处理可能的编码问题.

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

解出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;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值