gpt4 book ai didi

java - 我如何找到这三个点之间的距离java

转载 作者:行者123 更新时间:2023-11-29 04:56:40 25 4
gpt4 key购买 nike

<分区>

我需要计算出每个士兵之间的距离,但我无法计算出如何计算,因为它们都来自相同的 xPos 和 yPos,而我在网上找到的所有内容都是针对 x1、y1、x2、y2 之类的情况.

想法是它们随机生成然后可以移动攻击对方但我需要知道它们之间的距离才能继续

public class Soldier {

double xPos;
double yPos;

public Soldier(/*double distance, double speed*/) {
double lower = 0;
double upper = 100; //setting the upper and lower limits for the soldiers
xPos = Math.random() * (upper - lower) + lower;
yPos = Math.random() * (upper - lower) + lower; //creating x and y values
xPos = Math.round(xPos * 10) / 10.0d;
yPos = Math.round(yPos * 10) / 10.0d; //making sure the x and y value is to 1dp
System.out.println("(" + xPos + ", " + yPos + ")"); //printing the location
}
}

我的主要类(class)是,

public class Main {                                   
public static void main(String[] args) {
Soldier Cavalier = new Soldier(/*5.9, 1*/);
Soldier Pikeman = new Soldier(/*10.3, 12.6*/);
Soldier Crossbowman = new Soldier(/*4.9, 3*/);
System.out.println();
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com