示例#1
0
 @Override
 public Field move(
     Moveable moveable,
     SetterOfPosition setterOfPosition,
     MovePath movePath,
     ResourceHolder resourceHolder)
     throws FieldsNotConnectedException, MoveNotPossibleException, NotEnoughResourceException {
   if (canMove(moveable, movePath, resourceHolder)) {
     resourceHolder.pay(movePath.cost().asPayment());
     setterOfPosition.setPosition(movePath.getTarget());
     return movePath.getTarget();
   } else if (!resourceHolder.canPay(movePath.cost().asPayment())) {
     throw new NotEnoughResourceException(
         resourceHolder.get(MovePoint.class), movePath.cost().getAmount());
   } else {
     throw new MoveNotPossibleException();
   }
 }
示例#2
0
 @Override
 public boolean canMove(Moveable moveable, MovePath movePath, ResourceHolder resourceHolder) {
   if (moveable == null || movePath == null || resourceHolder == null) {
     return false;
   }
   Moveable testMoveable = moveable.cloneMoveable();
   ResourceHolder testResourceHolder = resourceHolder.cloneResourceHolder();
   boolean canMove = true;
   for (Field field : movePath.getPathFields()) {
     try {
       testMoveable.move(field, testResourceHolder);
     } catch (Exception e) {
       canMove = false;
       break;
     }
   }
   return canMove;
 }