2022-11-19 09:46:28 +00:00
|
|
|
package com.github.dtschust.zork.types;
|
2022-11-16 15:18:00 +00:00
|
|
|
|
2022-11-22 09:12:04 +00:00
|
|
|
|
|
|
|
import com.github.dtschust.zork.ZorkTrigger;
|
2022-11-21 23:46:20 +00:00
|
|
|
|
2022-11-22 09:12:04 +00:00
|
|
|
import java.util.*;
|
2022-11-16 15:18:00 +00:00
|
|
|
|
|
|
|
/* Room*/
|
2022-11-21 23:46:20 +00:00
|
|
|
public class ZorkRoom extends ZorkObject implements HasSetOfCollectable {
|
2022-11-22 10:27:56 +00:00
|
|
|
private final String type;
|
|
|
|
private final Map<ZorkDirection, String> border;
|
|
|
|
private final Set<String> container;
|
|
|
|
private final Set<String> item;
|
|
|
|
private final Set<String> creature;
|
2022-11-16 15:18:00 +00:00
|
|
|
|
2022-11-22 08:55:26 +00:00
|
|
|
public ZorkRoom(final String name,
|
|
|
|
final String description,
|
2022-11-22 09:12:04 +00:00
|
|
|
final String type,
|
|
|
|
final String status,
|
|
|
|
final Collection<ZorkTrigger> triggers,
|
2022-11-22 10:27:56 +00:00
|
|
|
final Map<ZorkDirection, String> borders,
|
2022-11-22 09:12:04 +00:00
|
|
|
final Collection<String> containers,
|
|
|
|
final Collection<String> items,
|
|
|
|
final Collection<String> creatures) {
|
|
|
|
super(name, description, status, triggers);
|
2022-11-20 13:11:58 +00:00
|
|
|
this.type = type;
|
2022-11-22 09:12:04 +00:00
|
|
|
this.border = new HashMap<>(borders);
|
|
|
|
this.container = new HashSet<>(containers);
|
|
|
|
this.item = new HashSet<>(items);
|
|
|
|
this.creature = new HashSet<>(creatures);
|
2022-11-16 15:18:00 +00:00
|
|
|
}
|
2022-11-21 23:46:20 +00:00
|
|
|
|
|
|
|
@Override
|
2022-11-22 12:43:15 +00:00
|
|
|
public Set<String> getSetFromType(ZorkGameStatusType type) {
|
2022-11-21 23:46:20 +00:00
|
|
|
switch (type) {
|
|
|
|
case CONTAINER:
|
2022-11-22 10:27:56 +00:00
|
|
|
return getContainer();
|
2022-11-21 23:46:20 +00:00
|
|
|
case CREATURE:
|
2022-11-22 10:27:56 +00:00
|
|
|
return getCreature();
|
2022-11-21 23:46:20 +00:00
|
|
|
case ITEM:
|
2022-11-22 10:27:56 +00:00
|
|
|
return getItem();
|
2022-11-21 23:46:20 +00:00
|
|
|
default:
|
|
|
|
throw new IllegalStateException("Unexpected value: " + type);
|
|
|
|
}
|
|
|
|
}
|
2022-11-22 10:27:56 +00:00
|
|
|
|
|
|
|
public boolean isExit() {
|
|
|
|
return "exit".equals(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeBorderingRoom(String roomName) {
|
|
|
|
for (final ZorkDirection d : this.border.keySet()) {
|
|
|
|
if (this.border.get(d).equals(roomName)) {
|
|
|
|
this.border.remove(d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Optional<String> getBorderingRoom(ZorkDirection border) {
|
|
|
|
return Optional.ofNullable(this.border.get(border));
|
|
|
|
}
|
|
|
|
|
|
|
|
public Set<String> getContainer() {
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Set<String> getItem() {
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Set<String> getCreature() {
|
|
|
|
return creature;
|
|
|
|
}
|
2022-11-16 15:18:00 +00:00
|
|
|
}
|