Note that there are some explanatory texts on larger screens.

plurals
  1. POArrayList select coordinates, if there are less clients than coordinates, give each client a coordinate
    primarykey
    data
    text
    <pre><code> 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() &lt; 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(); } </code></pre> <p>Basically what I am trying to do here is, if there are more clients than available coordinates (spots), then give each player his own coordinate (So other clients can't have the same coords).</p> <p>But unfortunately it doesn't work, sometimes clients are getting the same coordinates. Why is it happening? what did I do wrong?</p> <p>Coordinate class:</p> <pre><code>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; } } </code></pre> <p>ArrayList:</p> <pre><code>public static ArrayList&lt;Coordinate&gt; spawnPoints = new ArrayList&lt;Coordinate&gt;(); </code></pre> <p><em><strong>So what's wrong there?</em></strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload