Esempio n. 1
0
 @Override
 public Field move(
     Moveable moveable,
     SetterOfPosition setterOfPosition,
     Field target,
     ResourceHolder resourceHolder)
     throws FieldsNotConnectedException, MoveNotPossibleException, NotEnoughResourceException {
   if (!moveable.getPosition().isConnected(target)) {
     throw new FieldsNotConnectedException(moveable.getPosition(), target);
   }
   CanMoveReport canMoveReport = canMove(moveable, target, resourceHolder);
   if (canMoveReport.isPossible()) {
     resourceHolder.pay(movePointCollector.collect(moveable, target).asPayment());
     setterOfPosition.setPosition(target);
     return target;
   } else if (!canMoveReport.canPay()) {
     throw new NotEnoughResourceException(
         movePointCollector.collect(moveable, target).asPayment(),
         resourceHolder.amountOf(MovePoint.class));
   } else if (canMoveReport.isBlocked() || !canMoveReport.isAbleToEnd()) {
     throw new MoveNotPossibleException(canMoveReport);
   } else {
     throw new MoveNotPossibleException("move is not possible - unknown reason");
   }
 }
Esempio n. 2
0
 @Override
 public CanMoveReport canMove(Moveable moveable, Field target, ResourceHolder resourceHolder) {
   if (moveable == null || target == null || resourceHolder == null) {
     return new CanMoveReportBasic.Builder().buildNull();
   }
   return new CanMoveReportBasic.Builder()
       .setCost(movePointCollector.collect(moveable, target))
       .setMaxPayment(resourceHolder.get(MovePoint.class))
       .setMoveIsBlockedBy(checkMoveBlocks(moveable, target))
       .setMoveIsUnableToEndBy(checkMoveUnableToEnd(moveable, target))
       .setSource(moveable.getPosition())
       .setTarget(target)
       .build();
 }
Esempio n. 3
0
 protected boolean checkResources(Moveable moveable, Field target, ResourceHolder resourceHolder) {
   return resourceHolder != null
       && resourceHolder.canPay(movePointCollector.collect(moveable, target).asPayment());
 }