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); }
public void finishedSelectingUnits(TilePanel tilePanel, List<Unit> chosenUnits) { UnitActionDetector unitActionDetector = new UnitActionDetector(selectedPanel, selectedUnit, tilePanel, chosenUnits); if (unitActionDetector.isSelectingUnit()) { selectedPanel = tilePanel; selectedPanel.addTileStateFromKey(selectedStateKey); repaintPanels(selectedPanel); selectedUnit = getUnit(chosenUnits); selectValidMovements(selectedPanel.getTile(), selectedUnit); } else if (unitActionDetector.isDeselectingUnit()) { selectedPanel.removeTileStateFromKey(selectedStateKey); deselectValidMovements(selectedPanel.getTile(), selectedUnit); repaintPanels(selectedPanel); selectedPanel = null; selectedUnit = null; } else if (unitActionDetector.isMovingUnit()) { Position from = selectedPanel.getTile().getPosition(); Position to = tilePanel.getTile().getPosition(); if (movementStrategy.isValidMove(selectedUnit, from, to, unitMap)) { deselectValidMovements(selectedPanel.getTile(), selectedUnit); selectedPanel.removeTileStateFromKey(selectedStateKey); List<Unit> units = unitMap.get(to); if (units != null && !units.isEmpty()) { Unit defending = units.get(0); BattleStrategy strategy = battleStrategyConfiguration.getBattleStrategy( selectedUnit, defending, selectedPanel.getTile(), tilePanel.getTile()); Unit winner = strategy.getWinner(selectedUnit, defending); if (winner.equals(selectedUnit)) { units.remove(defending); } } board.move(selectedUnit, from, to); repaintPanels(selectedPanel); selectedPanel = null; selectedUnit = null; } } frame.setEnabled(true); resetPositions(); }