예제 #1
0
  private void initEngine() {
    Context.getInstance().setPlayer(new Player());
    Context.getInstance().setReceiver(new SwingReceiver(frame.inputField));
    Context.getInstance().setSender(new SwingSender(frame.outputArea, true));

    world.addWorldListener(
        new WorldListener() {
          @Override
          public void onScene(World world, Scene scene) {
            Context.getInstance()
                .getSender()
                .send("Se cambio la escena a: " + scene.getName() + "\n");
          }

          @Override
          public void onAction(World world, Action action, String verb, ParamHolder holder) {
            Context.getInstance().getSender().send("Se ejecuto la accion: " + verb + "\n");
          }

          @Override
          public void onBeforeAction(World world, Action action, String verb, ParamHolder holder) {
            Context.getInstance().getSender().clear();
          }

          @Override
          public void onAfterAction(
              World world, Action action, String verb, ParamHolder holder, boolean executed) {
            if (!executed) {
              Context.getInstance()
                  .getSender()
                  .send("Ocurrio un error al ejecutar la accion: " + verb + "\n");
            }
          }
        });

    world.addAction(new ExampleAction());
    world.addAction(new AvailableItemsAction());
    world.addAction(new PickAction());
    world.addAction(new HelpAction());
    world.addAction(new GoBackAction());
    world.addAction(new GoToAction());
    world.addAction(new RoutesAction());
    world.addAction(new DropAction());
    world.addAction(new ItemAction());
    world.addAction(new ExitAction());

    RoomScene roomScene = new RoomScene();
    CleanRoomScene cleanRoomScene = new CleanRoomScene();

    world.addScene(roomScene);
    world.addScene(cleanRoomScene);

    world.addConnector(new Connector(roomScene, cleanRoomScene, false));

    world.setCurrentScene("Cuarto");
  }
예제 #2
0
  public Test() {
    frame.setVisible(true);
    initEngine();
    while (true) {
      String action = Context.getInstance().getReceiver().read(String.class);

      if (!world.execute(action)) {
        Context.getInstance().getSender().clear();
        Context.getInstance().getSender().send("Accion invalida!!\n");
      }
    }
  }