Coordinate[] coords = {
new Coordinate(3093, 3630), new Coordinate(3095, 3632), new Coordinate(3098, 3633),
new Coordinate(3101, 3633), new Coordinate(3104, 3631), new Coordinate(3106, 3629),
new Coordinate(3107, 3627), new Coordinate(3108, 3624), new Coordinate(3109, 3620),
new Coordinate(3108, 3617), new Coordinate(3106, 3614), new Coordinate(3102, 3613),
new Coordinate(3099, 3613), new Coordinate(3097, 3613), new Coordinate(3093, 3614),
new Coordinate(3090, 3617), new Coordinate(3087, 3619)
};
int random = Misc.random(coords.length - 1);
Coordinate coord = coords[random];
boolean found = false;
if (insidePlayers.size() < coords.length) {
if (spawnPoints.contains(coord)) {
found = false;
}
while (!found) {
random = Misc.random(coords.length - 1);
coord = coords[random];
if (!spawnPoints.contains(coord)) {
player.spawnPointX = coords[random].getX();
player.spawnPointY = coords[random].getY();
spawnPoints.add(coord);
found = true;
break;
}
}
}
else {
player.spawnPointX = coords[random].getX();
player.spawnPointX = coords[random].getY();
}
基本上我在这里要做的是,如果客户端比可用坐标(点)多,那么给每个玩家自己的坐标(所以其他客户端不能有相同的坐标)。
但不幸的是它不起作用,有时客户会得到相同的坐标。为什么会这样?我做错了什么?
坐标类:
public class Coordinate {
private int x = 0;
private int y = 0;
public Coordinate(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}
数组列表:
public static ArrayList<Coordinate> spawnPoints = new ArrayList<Coordinate>();
那么那里有什么问题呢?