Monopoly/src/main/java/de/joethei/monopoly/action/Action.java

53 lines
1.5 KiB
Java

package de.joethei.monopoly.action;
import de.joethei.monopoly.Monopoly;
import de.joethei.monopoly.Player;
import de.joethei.monopoly.fields.Field;
import de.joethei.monopoly.fields.OwnableField;
public abstract class Action {
private String name;
private Field field;
private ActionType actionType;
public Action(String name, Field field, ActionType actionType) {
this.name = name;
this.field = field;
this.actionType = actionType;
}
public abstract void execute(Player player);
public boolean isRequired() {
return actionType == ActionType.REQUIRED || actionType == ActionType.REQUIRED_OWNER;
}
public boolean canExecute(Player player) {
if(Monopoly.getFields().get(player.getField()).equals(field)) {
if(field instanceof OwnableField) {
OwnableField ownableField = (OwnableField) field;
if(actionType == ActionType.OPTIONAL && ownableField.getOwner() == null) return true;
if(actionType == ActionType.OPTIONAL_OWNER && ownableField.getOwner() == player) return true;
if(actionType == ActionType.REQUIRED && ownableField.getOwner() != player) return true;
return false;
}
return true;
}
return false;
}
public String getName() {
return name;
}
public Field getField() {
return field;
}
public ActionType getActionType() {
return actionType;
}
}