implement Location.java
This commit is contained in:
@@ -3,26 +3,75 @@ package org.project.location;
|
||||
import org.project.entity.enemies.Enemy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Location {
|
||||
private String name;
|
||||
|
||||
private ArrayList<Enemy> enemies;
|
||||
private final String name;
|
||||
|
||||
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
|
||||
this.locations = locations;
|
||||
this.enemies = enemies;
|
||||
private final List<Location> connectedLocations;
|
||||
private final List<Enemy> 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() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ArrayList<Location> getLocations() {
|
||||
return locations;
|
||||
public List<Location> getConnectedLocations() {
|
||||
return Collections.unmodifiableList(connectedLocations);
|
||||
}
|
||||
|
||||
public ArrayList<Enemy> getEnemies() {
|
||||
return enemies;
|
||||
public List<Enemy> getEnemies() {
|
||||
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