Ejemplo n.º 1
0
 /**
  * handles all events
  *
  * @param e the event to handle
  */
 @Override
 public void handleModelChangeEvent(ModelChangeEvent e) {
   displayMessage(e.getMessage());
   drawList = e.getDrawable();
   for (Drawable2D drawable : drawList) {
     if (drawable.getClass().equals(Player2D.class)) {
       player = (Player2D) drawable;
     }
     if (drawable.getClass().equals(Room2D.class)) {
       mapArea.setCurrentRoom((Room) drawable);
     }
     if (drawable.getClass().equals(Item2D.class)) {
       if (player.collidesWith(drawable)) {
         collidingWithObject = drawable;
       }
     }
   }
   drawArea.updateDrawable(drawList);
 }
Ejemplo n.º 2
0
  /**
   * Constructor for the 2D view, creates JPanel within a frame and initializes the list of
   * listeners (input and drawable)
   */
  public View2D() {
    super();

    drawList = new ArrayList<Drawable2D>();

    mainWindow = new JFrame("World of the Nameless");
    mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // mainWindow.setBounds(100, 100, 730, 480);
    mainWindow.setResizable(false);
    mainWindow.setLayout(new BorderLayout());
    mainWindow.setVisible(true);

    drawArea = new Drawable2DArea();
    drawArea.addMouseListener(this);
    mapArea = new MapPanel();

    JPanel buttonPanel = new JPanel(new GridLayout(2, 4));

    inventoryButton = new JButton("Inventory");
    inventoryButton.addActionListener(this);

    characterButton = new JButton("Character");
    characterButton.addActionListener(this);

    helpButton = new JButton("Help");
    helpButton.addActionListener(this);

    quitButton = new JButton("Quit");
    quitButton.addActionListener(this);

    undoButton = new JButton("Undo");
    undoButton.addActionListener(this);

    redoButton = new JButton("Redo");
    redoButton.addActionListener(this);

    saveButton = new JButton("Save");
    saveButton.addActionListener(this);

    buttonPanel.add(inventoryButton);
    buttonPanel.add(characterButton);
    buttonPanel.add(undoButton);
    buttonPanel.add(redoButton);
    buttonPanel.add(helpButton);
    buttonPanel.add(quitButton);
    buttonPanel.add(saveButton);

    textAreaPanel = new JPanel(new BorderLayout());

    textArea = new JTextArea();
    textArea.setEditable(false);
    textArea.setToolTipText("What is happening to me");

    // JScrollPane scrollPane = new JScrollPane(textArea);

    JPanel inputFieldPane = new JPanel(new BorderLayout());

    inputField = new JTextField();
    inputField.addActionListener(this);
    inputField.setToolTipText("Input Text commands here");

    JLabel inputLabel = new JLabel(" >");

    inputFieldPane.add(inputLabel, BorderLayout.WEST);
    inputFieldPane.add(inputField, BorderLayout.CENTER);

    textAreaPanel.add(textArea, BorderLayout.CENTER);
    textAreaPanel.add(inputFieldPane, BorderLayout.SOUTH);

    JPanel infoPanel = new JPanel(new GridLayout(2, 1));

    infoPanel.add(mapArea);
    infoPanel.add(textAreaPanel);

    JPanel gameContent = new JPanel(new GridLayout(1, 2));

    gameContent.add(drawArea);
    gameContent.add(infoPanel);
    gameContent.setToolTipText("Game Visuals");

    mainWindow.add(gameContent, BorderLayout.CENTER);
    mainWindow.add(buttonPanel, BorderLayout.SOUTH);
    mainWindow.pack();
  }