Skip to content

Commit

Permalink
Improve location (wasd) commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Feb 7, 2020
1 parent 8fbb0bd commit 0348b97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,13 @@ public void objectAdded(LwM2mObjectEnabler object) {
commandsHelp.append(System.lineSeparator());
commandsHelp.append(" - delete <objectId> : to disable a new object.");
commandsHelp.append(System.lineSeparator());
commandsHelp.append(" - 'w','a','s','d' : to change reported Location.");
commandsHelp.append(" - w : to move to North.");
commandsHelp.append(System.lineSeparator());
commandsHelp.append(" - a : to move to East.");
commandsHelp.append(System.lineSeparator());
commandsHelp.append(" - s : to move to South.");
commandsHelp.append(System.lineSeparator());
commandsHelp.append(" - d : to move to West.");
commandsHelp.append(System.lineSeparator());
LOG.info(commandsHelp.toString());

Expand All @@ -482,6 +488,7 @@ public void run() {

// Change the location through the Console
try (Scanner scanner = new Scanner(System.in)) {
List<Character> wasdCommands = Arrays.asList('w', 'a', 's', 'd');
while (scanner.hasNext()) {
String command = scanner.next();
if (command.startsWith("create")) {
Expand Down Expand Up @@ -518,8 +525,10 @@ public void run() {
scanner.next();
LOG.info("\"Invalid syntax, <objectid> must be an integer : delete <objectId>");
}
} else {
} else if (command.length() == 1 && wasdCommands.contains(command.charAt(0))) {
locationInstance.moveLocation(command);
} else {
LOG.info("Unknown command '{}'", command);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ public void moveLocation(String nextMove) {
switch (nextMove.charAt(0)) {
case 'w':
moveLatitude(1.0f);
LOG.info("Move to North {}/{}", getLatitude(), getLongitude());
break;
case 'a':
moveLongitude(-1.0f);
LOG.info("Move to East {}/{}", getLatitude(), getLongitude());
break;
case 's':
moveLatitude(-1.0f);
LOG.info("Move to South {}/{}", getLatitude(), getLongitude());
break;
case 'd':
moveLongitude(1.0f);
LOG.info("Move to West {}/{}", getLatitude(), getLongitude());
break;
}
}
Expand Down

0 comments on commit 0348b97

Please sign in to comment.