Beispiel #1
0
 public BoardPanel(
     final JFrame frame,
     Game game,
     UnitTypeConfiguration unitTypeConfiguration,
     TileTypeConfiguration tileTypeConfiguration,
     TileStateConfiguration tileStateConfiguration,
     ChessMovementStrategy movementStrategy,
     UnitSelectorMode unitSelectorMode,
     BattleStrategyConfiguration battleStrategyConfiguration) {
   this.frame = frame;
   this.battleStrategyConfiguration = battleStrategyConfiguration;
   thisPanel = this;
   this.game = game;
   game.addGameObserver(this);
   this.board = game.getBoard();
   this.movementStrategy = movementStrategy;
   int rows = board.getDimension().getHeight();
   int columns = board.getDimension().getWidth();
   setLayout(new GridLayout(rows, columns));
   for (Tile tile : board.getTiles()) {
     final TilePanel tilePanel =
         new TilePanel(tileTypeConfiguration, unitTypeConfiguration, tileStateConfiguration, tile);
     if (UnitSelectorMode.MULTIPLE.equals(unitSelectorMode)) {
       tilePanel.addMouseListener(
           new MultipleUnitSelectorMouseListener(tilePanel, frame, thisPanel));
     }
     if (UnitSelectorMode.SINGLE.equals(unitSelectorMode)) {
       tilePanel.addMouseListener(
           new SingleUnitSelectorMouseListener(tilePanel, frame, thisPanel));
     }
     map.put(tile, tilePanel);
     add(tilePanel);
   }
   resetPositions();
 }
Beispiel #2
0
 private void repaintPanels(Iterable<TilePanel> panels) {
   long start = System.currentTimeMillis();
   for (TilePanel panel : panels) {
     game.notifyGameObservers(panel.getTile().getPosition());
   }
   long stop = System.currentTimeMillis();
   Logger.getLogger(BoardPanel.class).debug("Repaint time: " + (stop - start) / 1000.0);
 }