コード例 #1
0
  private boolean execute(CashCorrectionAction cashAction) {

    boolean result = false;

    CashHolder ch = cashAction.getCashHolder();
    int amount = cashAction.getAmount();

    String errMsg = null;

    while (true) {
      if (amount == 0) {
        errMsg = LocalText.getText("CorrectCashZero");
        break;
      }
      if ((amount + ch.getCash()) < 0) {
        errMsg =
            LocalText.getText(
                "NotEnoughMoney", ch.getName(), Bank.format(ch.getCash()), Bank.format(-amount));
        break;
      }
      break;
    }

    if (errMsg != null) {
      DisplayBuffer.add(LocalText.getText("CorrectCashError", ch.getName(), errMsg));
      result = true;
    } else {
      // no error occured
      gameManager.getMoveStack().start(false);

      Bank bank = gameManager.getBank();

      String msg;
      if (amount < 0) {
        // negative amounts: remove cash from cashholder
        new CashMove(ch, bank, -amount);

        msg = LocalText.getText("CorrectCashSubstractMoney", ch.getName(), Bank.format(-amount));
      } else {
        // positive amounts: add cash to cashholder
        new CashMove(bank, ch, amount);
        msg = LocalText.getText("CorrectCashAddMoney", ch.getName(), Bank.format(amount));
      }
      ReportBuffer.add(msg);
      gameManager.addToNextPlayerMessages(msg, true);
      result = true;
    }

    return result;
  }
コード例 #2
0
 @Override
 public String getText() {
   if (stockPrice != null) {
     return Bank.format(stockPrice.getPrice()) + " (" + stockPrice.getName() + ")";
   }
   return "";
 }