@Test public void testGetCharactersNearby() { final Tile[] tiles = new Tile[2600]; for (int i = 0; i < 2600; i++) { tiles[i] = new Tile(true, true, false, Trigger.NONE, null, null, null); } map = new WorldMap("foo", 1, (short) 1, tiles); map.getTile(8, 8).setCharacter(mock(Character.class)); map.getTile(15, 8).setCharacter(mock(Character.class)); map.getTile(8, 15).setCharacter(mock(Character.class)); map.getTile(15, 15).setCharacter(mock(Character.class)); map.getTile(5, 5).setCharacter(mock(Character.class)); map.getTile(25, 5).setCharacter(mock(Character.class)); final List<Character> chars = map.getCharactersNearby(7, 7); assertEquals(5, chars.size()); assertThat(chars, hasItem(map.getTile(8, 8).getCharacter())); assertThat(chars, hasItem(map.getTile(15, 8).getCharacter())); assertThat(chars, hasItem(map.getTile(8, 15).getCharacter())); assertThat(chars, hasItem(map.getTile(15, 15).getCharacter())); assertThat(chars, hasItem(map.getTile(5, 5).getCharacter())); }
public List<Character> getCharactersNearby(int x, int y) { List<Character> charList = new LinkedList<Character>(); Character character; int yy; int toX = Math.min(x + WorldMap.VISIBLE_AREA_WIDTH * 2, MAX_X); int toY = Math.min(y + WorldMap.VISIBLE_AREA_HEIGHT * 2, MAX_Y); int fromY = Math.max(y - WorldMap.VISIBLE_AREA_HEIGHT, MIN_Y); int fromX = Math.max(x - WorldMap.VISIBLE_AREA_WIDTH, MIN_X); for (int xx = fromX; xx < toX; xx++) { for (yy = fromY; yy < toY; yy++) { character = getTile(xx, yy).getCharacter(); if (character != null && (xx != x && yy != y)) { charList.add(character); } } } return charList; }
WorldMap { public List<Character> getCharactersNearby(int x, int y) { List<Character> charList = new LinkedList<Character>(); Character character; int yy; int toX = Math.min(x + WorldMap.VISIBLE_AREA_WIDTH * 2, MAX_X); int toY = Math.min(y + WorldMap.VISIBLE_AREA_HEIGHT * 2, MAX_Y); int fromY = Math.max(y - WorldMap.VISIBLE_AREA_HEIGHT, MIN_Y); int fromX = Math.max(x - WorldMap.VISIBLE_AREA_WIDTH, MIN_X); for (int xx = fromX; xx < toX; xx++) { for (yy = fromY; yy < toY; yy++) { character = getTile(xx, yy).getCharacter(); if (character != null && (xx != x && yy != y)) { charList.add(character); } } } return charList; } }
WorldMap { public List<Character> getCharactersNearby(int x, int y) { List<Character> charList = new LinkedList<Character>(); Character character; int yy; int toX = Math.min(x + WorldMap.VISIBLE_AREA_WIDTH * 2, MAX_X); int toY = Math.min(y + WorldMap.VISIBLE_AREA_HEIGHT * 2, MAX_Y); int fromY = Math.max(y - WorldMap.VISIBLE_AREA_HEIGHT, MIN_Y); int fromX = Math.max(x - WorldMap.VISIBLE_AREA_WIDTH, MIN_X); for (int xx = fromX; xx < toX; xx++) { for (yy = fromY; yy < toY; yy++) { character = getTile(xx, yy).getCharacter(); if (character != null && (xx != x && yy != y)) { charList.add(character); } } } return charList; } WorldMap(final String name, final int id, final short version, final Tile[] tiles); }
WorldMap { public List<Character> getCharactersNearby(int x, int y) { List<Character> charList = new LinkedList<Character>(); Character character; int yy; int toX = Math.min(x + WorldMap.VISIBLE_AREA_WIDTH * 2, MAX_X); int toY = Math.min(y + WorldMap.VISIBLE_AREA_HEIGHT * 2, MAX_Y); int fromY = Math.max(y - WorldMap.VISIBLE_AREA_HEIGHT, MIN_Y); int fromX = Math.max(x - WorldMap.VISIBLE_AREA_WIDTH, MIN_X); for (int xx = fromX; xx < toX; xx++) { for (yy = fromY; yy < toY; yy++) { character = getTile(xx, yy).getCharacter(); if (character != null && (xx != x && yy != y)) { charList.add(character); } } } return charList; } WorldMap(final String name, final int id, final short version, final Tile[] tiles); short getVersion(); Tile getTile(int x, int y); static int getTileKey(final int x, final int y); String getName(); int getId(); List<Character> getCharactersNearby(int x, int y); void putCharacterAtPos(Character chara, byte x, byte y); @Override int hashCode(); @Override boolean equals(Object obj); Tile getNearestAvailableTile(byte x, byte y, byte maxDistance, boolean includeGroundTiles,
			boolean includeWaterTiles, boolean includeLavaTiles, boolean includeExitTiles); boolean isTileAvailable(byte x, byte y, boolean canBeGround, boolean canBeWater, boolean canBeLava,
			boolean canBeExitTile); void moveCharacterTo(final Character character, final byte x, final byte y); }
WorldMap { public List<Character> getCharactersNearby(int x, int y) { List<Character> charList = new LinkedList<Character>(); Character character; int yy; int toX = Math.min(x + WorldMap.VISIBLE_AREA_WIDTH * 2, MAX_X); int toY = Math.min(y + WorldMap.VISIBLE_AREA_HEIGHT * 2, MAX_Y); int fromY = Math.max(y - WorldMap.VISIBLE_AREA_HEIGHT, MIN_Y); int fromX = Math.max(x - WorldMap.VISIBLE_AREA_WIDTH, MIN_X); for (int xx = fromX; xx < toX; xx++) { for (yy = fromY; yy < toY; yy++) { character = getTile(xx, yy).getCharacter(); if (character != null && (xx != x && yy != y)) { charList.add(character); } } } return charList; } WorldMap(final String name, final int id, final short version, final Tile[] tiles); short getVersion(); Tile getTile(int x, int y); static int getTileKey(final int x, final int y); String getName(); int getId(); List<Character> getCharactersNearby(int x, int y); void putCharacterAtPos(Character chara, byte x, byte y); @Override int hashCode(); @Override boolean equals(Object obj); Tile getNearestAvailableTile(byte x, byte y, byte maxDistance, boolean includeGroundTiles,
			boolean includeWaterTiles, boolean includeLavaTiles, boolean includeExitTiles); boolean isTileAvailable(byte x, byte y, boolean canBeGround, boolean canBeWater, boolean canBeLava,
			boolean canBeExitTile); void moveCharacterTo(final Character character, final byte x, final byte y); static final int MAP_WIDTH; static final int MAP_HEIGHT; static final int VISIBLE_AREA_WIDTH; static final int VISIBLE_AREA_HEIGHT; static final int MAX_DISTANCE; static final int MAX_X; static final int MAX_Y; static final int MIN_X; static final int MIN_Y; }