Minor cleanup
This commit is contained in:
parent
4c70ba2800
commit
6df81726d1
18 changed files with 18 additions and 74 deletions
|
@ -1,8 +0,0 @@
|
|||
# Refactors done
|
||||
|
||||
- chore: move to package `com.github.dtschust.zork`
|
||||
- default package is bad
|
||||
- remove 5 redundant `if` statements from `ZorkCommand`, `ZorkCommandHas`, `ZorkCondtionStatus'
|
||||
- e.g. `if (blah) return true; else return false;` can be simplified to `return blah;`
|
||||
- replaced 2 `for` with foreach loops in `ZorkCreature` and `ZorkTrigger`
|
||||
- 23 use of diamond operator in `Zork`, `ZorkContainer`, `ZorkCreature`, `ZorkItem`, `ZorkObject`, `ZorkRoom`, `ZorkTrigger`
|
|
@ -2,7 +2,6 @@ package com.github.dtschust.zork;
|
|||
|
||||
import com.github.dtschust.zork.types.HasPrintsAndActions;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
|
|
@ -13,10 +13,6 @@ public abstract class ZorkObject {
|
|||
private final List<ZorkTrigger> trigger;
|
||||
private String status;
|
||||
|
||||
protected ZorkObject(String name, String description) {
|
||||
this(name, description, null, Collections.emptyList());
|
||||
}
|
||||
|
||||
protected ZorkObject(final String name,
|
||||
final String description,
|
||||
final String status,
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package com.github.dtschust.zork.objects;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Optional;
|
||||
|
||||
public enum ZorkObjectTypes {
|
||||
ROOM("room"),
|
||||
ITEM("item"),
|
||||
CONTAINER("container"),
|
||||
CREATURE("creature");
|
||||
|
||||
private final String propertyName;
|
||||
|
||||
ZorkObjectTypes(final String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
public static Optional<ZorkObjectTypes> fromPropertyName(final String propertyName) {
|
||||
return EnumSet.allOf(ZorkObjectTypes.class).stream().filter(e -> e.propertyName.equals(propertyName)).findFirst();
|
||||
}
|
||||
}
|
|
@ -8,8 +8,6 @@ import com.github.dtschust.zork.types.ZorkDirection;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import static com.github.dtschust.zork.objects.ZorkObjectTypes.*;
|
||||
|
||||
/* Room*/
|
||||
public class ZorkRoom extends ZorkObject implements ObjectCollector {
|
||||
private final String type;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.github.dtschust.zork.parser;
|
||||
|
||||
import com.github.dtschust.zork.ZorkCondition;
|
||||
import com.github.dtschust.zork.parser.strategies.*;
|
||||
import com.github.dtschust.zork.objects.ZorkContainer;
|
||||
import com.github.dtschust.zork.objects.ZorkCreature;
|
||||
import com.github.dtschust.zork.objects.ZorkItem;
|
||||
import com.github.dtschust.zork.objects.ZorkRoom;
|
||||
import com.github.dtschust.zork.parser.strategies.*;
|
||||
|
||||
/**
|
||||
* Inversion of control for Zork parse strategies
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.github.dtschust.zork.parser;
|
||||
|
||||
import com.github.dtschust.zork.parser.dom.DOMElement;
|
||||
import com.github.dtschust.zork.objects.ZorkContainer;
|
||||
import com.github.dtschust.zork.objects.ZorkCreature;
|
||||
import com.github.dtschust.zork.objects.ZorkItem;
|
||||
import com.github.dtschust.zork.objects.ZorkRoom;
|
||||
import com.github.dtschust.zork.parser.dom.DOMElement;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.github.dtschust.zork.parser.strategies;
|
||||
|
||||
import com.github.dtschust.zork.ZorkTrigger;
|
||||
import com.github.dtschust.zork.objects.ZorkContainer;
|
||||
import com.github.dtschust.zork.parser.Property;
|
||||
import com.github.dtschust.zork.parser.PropertyParseStrategy;
|
||||
import com.github.dtschust.zork.parser.TriggerPropertyParseStrategy;
|
||||
import com.github.dtschust.zork.objects.ZorkContainer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
|
@ -2,10 +2,10 @@ package com.github.dtschust.zork.parser.strategies;
|
|||
|
||||
import com.github.dtschust.zork.ZorkCondition;
|
||||
import com.github.dtschust.zork.ZorkTrigger;
|
||||
import com.github.dtschust.zork.objects.ZorkCreature;
|
||||
import com.github.dtschust.zork.parser.Property;
|
||||
import com.github.dtschust.zork.parser.PropertyParseStrategy;
|
||||
import com.github.dtschust.zork.parser.TriggerPropertyParseStrategy;
|
||||
import com.github.dtschust.zork.objects.ZorkCreature;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.github.dtschust.zork.parser.strategies;
|
||||
|
||||
import com.github.dtschust.zork.ZorkTrigger;
|
||||
import com.github.dtschust.zork.objects.ZorkItem;
|
||||
import com.github.dtschust.zork.parser.Property;
|
||||
import com.github.dtschust.zork.parser.PropertyParseStrategy;
|
||||
import com.github.dtschust.zork.parser.TriggerPropertyParseStrategy;
|
||||
import com.github.dtschust.zork.objects.ZorkItem;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.github.dtschust.zork.parser.strategies;
|
||||
|
||||
import com.github.dtschust.zork.ZorkTrigger;
|
||||
import com.github.dtschust.zork.objects.ZorkRoom;
|
||||
import com.github.dtschust.zork.parser.Property;
|
||||
import com.github.dtschust.zork.parser.PropertyParseStrategy;
|
||||
import com.github.dtschust.zork.parser.TriggerPropertyParseStrategy;
|
||||
import com.github.dtschust.zork.types.ZorkDirection;
|
||||
import com.github.dtschust.zork.objects.ZorkRoom;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
|
@ -1,17 +1,10 @@
|
|||
package com.github.dtschust.zork.repl.actions;
|
||||
|
||||
import com.github.dtschust.zork.ZorkGame;
|
||||
import com.github.dtschust.zork.objects.ZorkItem;
|
||||
import com.github.dtschust.zork.repl.Action;
|
||||
import com.github.dtschust.zork.types.ObjectCollector;
|
||||
import com.github.dtschust.zork.objects.ZorkObjectTypes;
|
||||
import com.github.dtschust.zork.objects.ZorkObject;
|
||||
import com.github.dtschust.zork.objects.ZorkRoom;
|
||||
import com.github.dtschust.zork.repl.Action;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.github.dtschust.zork.objects.ZorkObjectTypes.*;
|
||||
|
||||
/**
|
||||
* Delete: figure out what object it is and delete it accordingly. Rooms are especially tricky
|
||||
|
|
|
@ -2,12 +2,9 @@ package com.github.dtschust.zork.repl.actions;
|
|||
|
||||
import com.github.dtschust.zork.ZorkGame;
|
||||
import com.github.dtschust.zork.repl.Action;
|
||||
import com.github.dtschust.zork.objects.ZorkItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.github.dtschust.zork.objects.ZorkObjectTypes.ITEM;
|
||||
|
||||
public class ReadAction implements Action {
|
||||
@Override
|
||||
public boolean matchesInput(List<String> arguments) {
|
||||
|
|
|
@ -2,11 +2,9 @@ package com.github.dtschust.zork.repl.actions;
|
|||
|
||||
import com.github.dtschust.zork.ZorkGame;
|
||||
import com.github.dtschust.zork.objects.ZorkContainer;
|
||||
import com.github.dtschust.zork.objects.ZorkItem;
|
||||
import com.github.dtschust.zork.repl.Action;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TakeAction implements Action {
|
||||
@Override
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package com.github.dtschust.zork.types;
|
||||
|
||||
import com.github.dtschust.zork.objects.ZorkObject;
|
||||
import com.github.dtschust.zork.objects.ZorkObjectTypes;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface ObjectCollector {
|
||||
void addObject(final ZorkObject object);
|
||||
|
||||
void removeObject(final ZorkObject object);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ import com.github.dtschust.zork.utils.CommandReader;
|
|||
import com.github.dtschust.zork.utils.IOWrapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import static com.github.stefanbirkner.systemlambda.SystemLambda.catchSystemExit;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
@ -19,16 +17,12 @@ class ZorkTest {
|
|||
String gameConfig = "sampleGame.xml";
|
||||
String gameExecution = "RunThroughResults.txt";
|
||||
|
||||
PrintStream out = System.out;
|
||||
|
||||
CommandReader run = new CommandReader(gameExecution);
|
||||
IOWrapper io = new IOWrapper(true);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
catchSystemExit(() -> new Zork(gameConfig));
|
||||
} catch (Exception ignored) {
|
||||
ignored.printStackTrace(out);
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}).start();
|
||||
while(true){
|
||||
switch(run.getInstructionType()) {
|
||||
|
|
Reference in a new issue