gpt4 book ai didi

java - 循环中标签的正确使用

转载 作者:行者123 更新时间:2023-12-02 07:17:25 37 4
gpt4 key购买 nike

我正在寻找我的应用程序中的错误,它看起来在这里:

for (int y=0; y<MAP_HEIGHT; y+=10) {
for (int x=0; x<MAP_WIDTH; x+=10) {
Label:

for (GameResource res : resources) {
//Checks if some object is already at given point
if (res.getArea().contains(new Point2D.Float(x, y))) {
continue Label;
}
}

if ((int)(Math.random()*200) == 0) {
resources.add(new GameTree(x, y));
}

if ((int)(Math.random()*400) == 0) {
resources.add(new GameMine(x, y));
}
}
}

它创建 map 。我检查过,看起来即使某个对象位于给定点,资源也会被放置。我正确使用标签了吗?如果使用 point,我想进入 x-for 循环中的下一个迭代。

最佳答案

如果您想进入 x 循环的下一次迭代,您的标签应该位于 x 循环上:

Label: for (int x = 0; x < MAP_WIDTH; x += 10)

关于java - 循环中标签的正确使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14757380/

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