Esempio n. 1
0
  public void doCommandWith(AdventureCommand c, AdventureEngine e, AdventureWindow w)
      throws DoNotUnderstandException {
    String key = myDirectObjectCommands.get(c.getVerb());
    if (key != null
        && key.equals("use")
        && myIndirectObjectCommands.contains(key)
        && ((Target) c.getDirectObject()).getUsable()
        && myUseListIO.containsKey(((Target) c.getDirectObject()).getName())) {
      String[] effects = myUseListIO.get(((Target) c.getDirectObject()).getName());
      w.println(effects[0]);
      ((Target) c.getIndirectObject()).setUsable(true);
      ((Target) c.getDirectObject()).setUsable(false);
      e.removeFromPlayerInventory(c.getDirectObject());
      ((Location) e.getPlayerLocation()).updateDescription(effects[1]);
      if (myDirectObjectCommands.containsKey("use")) {
        boolean canBe = myIndirectObjectCommands.contains(key);

        if (canBe && key.equals("examine")) {
          new ExamineStrategy().doCommand(c, e, w);
        } else if (canBe && key.equals("take")) {
          new TakeStrategy().doCommand(c, e, w);
        } else if (canBe && key.equals("drop")) {
          new DropStrategy().doCommand(c, e, w);
        } else if (canBe && key.equals("damage")) {
          new DamageStrategy().doCommand(c, e, w);
        }
      }
    } else {
      w.println("You might want to pick that up first.\n");
    }
  }
Esempio n. 2
0
  public void doCommandTo(AdventureCommand c, AdventureEngine e, AdventureWindow w)
      throws DoNotUnderstandException {
    String key = myDirectObjectCommands.get(c.getVerb());
    boolean canBe = myIndirectObjectCommands.contains(key);

    if (canBe && key.equals("examine")) {
      new ExamineStrategy().doCommand(c, e, w);
    } else if (canBe && key.equals("take")) {
      new TakeStrategy().doCommand(c, e, w);
    } else if (canBe && key.equals("drop")) {
      new DropStrategy().doCommand(c, e, w);
    } else if (canBe && key.equals("damage")) {
      new DamageStrategy().doCommand(c, e, w);
    } else if (myUseListDO.containsKey(c.getVerb())
        && ((Target) c.getDirectObject()).getVisible()) {
      String[] effects = myUseListDO.get(c.getVerb());
      w.println(effects[0]);
      ((Location) e.getPlayerLocation()).updateDescription(effects[1]);
      if (myDirectObjectCommands.containsKey("visible")) {
        String objName = myDirectObjectCommands.get("visible");
        for (AdventureTarget t : e.getPlayerLocation().getLocalTargets()) {
          if (t.canBeReferredToAs(objName)) {
            ((Target) t).setVisible(!((Target) t).getVisible());
          }
        }
      }
      if (myDirectObjectCommands.containsKey("invisible")) {
        String objName = myDirectObjectCommands.get("invisible");
        for (AdventureTarget t : e.getPlayerLocation().getLocalTargets()) {
          if (t.canBeReferredToAs(objName)) {
            ((Target) t).setVisible(false);
          }
        }
      }
    } else {
      throw new DoNotUnderstandException(c);
    }
  }