Files
worms/OGP1718-Worms/src/worms/programs/Statement.java
2018-05-19 19:43:06 +02:00

128 lines
2.5 KiB
Java

package worms.programs;
public class Statement {
private final Type type;
private final Object data;
public Statement(Type type, Object data) {
this.type = type;
this.data = data;
}
public Type getType() {
return this.type;
}
public Object getData() {
return data;
}
public enum Type {
ASSIGN,
PRINT,
ACTION,
WHILE,
IF,
BLOCK,
INVOKE,
BREAK
}
public static class If {
private final Statement ifBody;
private final Statement elseBody;
private final Expression condition;
public If(Expression condition, Statement ifBody, Statement elseBody) {
this.ifBody = ifBody;
this.elseBody = elseBody;
this.condition = condition;
}
public Statement getIfBody() {
return ifBody;
}
public Statement getElseBody() {
return elseBody;
}
public Expression getCondition() {
return condition;
}
}
public static class While {
private final Expression condition;
private final Statement body;
public While(Expression condition, Statement body) {
this.condition = condition;
this.body = body;
}
public Statement getBody() {
return body;
}
public Expression getCondition() {
return condition;
}
}
public static class Action {
private final Type type;
private final Expression<Double> value;
/**
*
* @param type
* @param value
*/
@SuppressWarnings("unchecked")
public Action(Type type, Expression<Double> value) {
this.type = type;
this.value = value;
}
public Type getType() {
return type;
}
public Expression<Double> getValue() {
return value;
}
public enum Type {
TURN,
MOVE,
JUMP,
EAT,
FIRE
}
}
public static class Assign {
private final String variableName;
private final Expression value;
public Assign(String variableName, Expression value) {
this.variableName = variableName;
this.value = value;
}
public Expression getValue() {
return value;
}
public String getVariableName() {
return variableName;
}
}
}