Пример #1
0
  public static void main(String[] args) {

    Game game = new StubGame1();

    DrawingEditor editor =
        new MiniDrawApplication("Click to see city graphics update...", new HotCivFactory3(game));
    editor.open();
    CityStub city = new CityStub();

    CityFigure cf =
        new CityFigure(
            city, new Point(GfxConstants.getXFromColumn(4), GfxConstants.getYFromRow(7)));
    editor.drawing().add(cf);
    editor.setTool(new ChangeCityTool(city, cf));
  }
  @Override
  public void mouseDown(MouseEvent e, int x, int y) {
    Position unitPosition = GfxConstants.getPositionFromXY(x, y);

    if (e.isShiftDown() && game.getUnitAt(unitPosition) != null) {
      game.performUnitActionAt(unitPosition);
    }
  }
Пример #3
0
 @Override
 public void mouseUp(MouseEvent e, int x, int y) {
   // If holding a unit then try to release it.
   if (unitOnTile && isDragging) {
     isDragging = false;
     to = GfxConstants.getPositionFromXY(x, y); // Get to position.
     game.moveUnit(from, to);
     editor.showStatus("Moved unit from " + from.toString() + " to " + to.toString());
   }
 }
Пример #4
0
 @Override
 public void mouseDown(MouseEvent e, int x, int y) {
   // Check if a unit has been selected.
   from = GfxConstants.getPositionFromXY(x, y); // Get from position.
   if (game.getUnitAt(from) != null && game.getUnitAt(from).getOwner() == game.getPlayerInTurn()) {
     unitOnTile = true;
     isDragging = true; // her tjekkes der ikke for, om der dragges. Dvs. hvis man
     // blot klikker på et unit og slipper igen på samme tile, kaldes moveUnit også
   }
   editor.showStatus("Mouse pressed at: " + from.toString());
 }
Пример #5
0
 @Override
 public void mouseDown(MouseEvent e, int x, int y) {
   game.setTileFocus(GfxConstants.getPositionFromXY(x, y));
 }