Hi
I am a Java novice and I am struggling with the “ShootCommand” and the related “Direction” Enum that is part of the Java Starter Bot. Actually more the ResolveDirection code that is part of the Starter Bot…
I am hoping some kindhearted soul will help!
Basically I am calling the same piece of code in the Java Starter Bot …just in a different context.
The code complies, but when I run it through the game runner I get…
JAVA CODE
//Determine which direction, I need to fire in//
// This code calls the resolveDirection class below, providing currentWorm pos and Target Cell Pos…basically I want to determine which fire direction the Target Cell is//
Direction direction = resolveDirection(currentWorm.position,TargetPosition);
return new ShootCommand(direction);
private Direction resolveDirection(Position a, Position b) {
StringBuilder builder = new StringBuilder();
int verticalComponent = b.y - a.y;
int horizontalComponent = b.x - a.x;
if (verticalComponent < 0) {
builder.append('N');
} else if (verticalComponent > 0) {
builder.append('S');
}
if (horizontalComponent < 0) {
builder.append('W');
} else if (horizontalComponent > 0) {
builder.append('E');
}
return Direction.valueOf(builder.toString());
}
}
_U