Progress saving
This commit is contained in:
@@ -113,12 +113,17 @@ public class Game implements IGame {
|
||||
|
||||
@Override
|
||||
public ILocation attack(GridDirection dir, IItem target) {
|
||||
ILocation loc = map.go(currentLocation, dir);
|
||||
if (map.has(loc, target))
|
||||
ILocation loc = currentLocation.go(dir);
|
||||
if (!map.has(loc, target)) {
|
||||
throw new IllegalMoveException("Target isn't there!");
|
||||
|
||||
// TODO: implement attack
|
||||
|
||||
}
|
||||
int damage = currentActor.getAttack() + random.nextInt(20) + 1;
|
||||
if (damage >= target.getDefence() + 10) {
|
||||
int actualDamage = target.handleDamage(this, target, damage);
|
||||
formatMessage("%s hits %s for %d damage", currentActor.getName(), target.getName(), actualDamage);
|
||||
} else {
|
||||
displayMessage("The attack missed.");
|
||||
}
|
||||
|
||||
map.clean(loc);
|
||||
|
||||
@@ -371,9 +376,7 @@ public class Game implements IGame {
|
||||
|
||||
@Override
|
||||
public List<ILocation> getVisible() {
|
||||
// TODO: maybe replace 3 by some sort of visibility range obtained from
|
||||
// currentActor?
|
||||
return map.getNeighbourhood(currentLocation, 3);
|
||||
return map.getNeighbourhood(currentLocation, currentActor.getVision());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -495,4 +498,45 @@ public class Game implements IGame {
|
||||
public Random getRandom() {
|
||||
return random;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridDirection locationDirection(ILocation start, ILocation target) {
|
||||
int targetX = target.getX(), targetY = target.getY();
|
||||
int startX = start.getX(), startY = start.getY();
|
||||
GridDirection dir = GridDirection.CENTER;
|
||||
if (targetX > startX && targetY > startY) {
|
||||
if (Math.abs(targetX - startX) < Math.abs(targetY - startY)) {
|
||||
dir = GridDirection.SOUTH;
|
||||
} else {
|
||||
dir = GridDirection.EAST;
|
||||
}
|
||||
} else if (targetX > startX && targetY < startY) {
|
||||
if (Math.abs(targetX - startX) < Math.abs(targetY - startY)) {
|
||||
dir = GridDirection.NORTH;
|
||||
} else {
|
||||
dir = GridDirection.EAST;
|
||||
}
|
||||
} else if (targetX < startX && targetY > startY) {
|
||||
if (Math.abs(targetX - startX) < Math.abs(targetY - startY)) {
|
||||
dir = GridDirection.SOUTH;
|
||||
} else {
|
||||
dir = GridDirection.WEST;
|
||||
}
|
||||
} else if (targetX < startX && targetY < startY) {
|
||||
if (Math.abs(targetX - startX) < Math.abs(targetY - startY)) {
|
||||
dir = GridDirection.NORTH;
|
||||
} else {
|
||||
dir = GridDirection.WEST;
|
||||
}
|
||||
} else if (targetX > startX) {
|
||||
dir = GridDirection.EAST;
|
||||
} else if (targetX < startX) {
|
||||
dir = GridDirection.WEST;
|
||||
} else if (targetY > startY) {
|
||||
dir = GridDirection.SOUTH;
|
||||
} else if (targetY < startY) {
|
||||
dir = GridDirection.NORTH;
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
|
@@ -317,4 +317,14 @@ public interface IGame {
|
||||
* @return A random generator
|
||||
*/
|
||||
Random getRandom();
|
||||
|
||||
/**
|
||||
* Gets the best direction to go from current to neighbour.
|
||||
* If the target is positioned diagonally from the start, the direction requiring the most steps is chosen.
|
||||
*
|
||||
* @param current The location to go from
|
||||
* @param neighbour The location to go to
|
||||
* @return A direction
|
||||
*/
|
||||
GridDirection locationDirection(ILocation current, ILocation neighbour);
|
||||
}
|
||||
|
Reference in New Issue
Block a user