This repository has been archived on 2022-12-21. You can view files and clone it, but cannot push or open issues or pull requests.
sdm03/src/main/java/com/github/dtschust/zork/ZorkConditionHas.java

31 lines
1.2 KiB
Java

package com.github.dtschust.zork;
/* Has conditions*/
public class ZorkConditionHas extends ZorkCondition {
public String has;
public String owner;
public boolean evaluate(Zork zork) {
/*Inventory is a special case as it isn't the name of any object in the game, check for it specifically*/
if (owner.equals("inventory")) {
return zork.game.Inventory.get(object) != null && has.equals("yes") || zork.game.Inventory.get(object) == null && has.equals("no");
} else {
/* is it a room?*/
ZorkRoom roomObject = zork.game.Rooms.get(owner);
if (roomObject != null) {
return (roomObject).item.get(object) != null && has.equals("yes") || (roomObject).item.get(object) == null && has.equals("no");
}
/* is it a container?*/
else {
ZorkContainer containerObject = zork.game.Containers.get(owner);
if (containerObject != null) {
return (containerObject).item.get(object) != null && has.equals("yes") || (containerObject).item.get(object) == null && has.equals("no");
}
}
}
return false;
}
}