Merge develop into main #1
@@ -3,26 +3,75 @@ package org.project.location;
|
|||||||
import org.project.entity.enemies.Enemy;
|
import org.project.entity.enemies.Enemy;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Location {
|
public class Location {
|
||||||
private String name;
|
|
||||||
|
|
||||||
private ArrayList<Enemy> enemies;
|
private final String name;
|
||||||
|
|
||||||
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
|
private final List<Location> connectedLocations;
|
||||||
this.locations = locations;
|
private final List<Enemy> enemies;
|
||||||
this.enemies = enemies;
|
|
||||||
|
public Location(String name) {
|
||||||
|
this.name = name;
|
||||||
|
this.connectedLocations = new ArrayList<>();
|
||||||
|
this.enemies = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location(String name, List<Location> connectedLocations, List<Enemy> enemies) {
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
this.connectedLocations =
|
||||||
|
connectedLocations != null ? new ArrayList<>(connectedLocations) : new ArrayList<>();
|
||||||
|
|
||||||
|
this.enemies =
|
||||||
|
enemies != null ? new ArrayList<>(enemies) : new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Location> getLocations() {
|
public List<Location> getConnectedLocations() {
|
||||||
return locations;
|
return Collections.unmodifiableList(connectedLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Enemy> getEnemies() {
|
public List<Enemy> getEnemies() {
|
||||||
return enemies;
|
return Collections.unmodifiableList(enemies);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------
|
||||||
|
// ADD / REMOVE LOCATIONS
|
||||||
|
// ------------------------------------location
|
||||||
|
|
||||||
|
public void connect(Location other) {
|
||||||
|
if (other == null || other == this) return;
|
||||||
|
|
||||||
|
if (!connectedLocations.contains(other)) {
|
||||||
|
connectedLocations.add(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!other.connectedLocations.contains(this)) {
|
||||||
|
other.connectedLocations.add(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void removeLocation(Location location) {
|
||||||
|
connectedLocations.remove(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------
|
||||||
|
// ADD / REMOVE ENEMIES
|
||||||
|
// ------------------------------------
|
||||||
|
public void addEnemy(Enemy enemy) {
|
||||||
|
if (enemy != null) {
|
||||||
|
enemies.add(enemy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeEnemy(Enemy enemy) {
|
||||||
|
enemies.remove(enemy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user