Ejemplo n.º 1
0
  public MapView(Map mapModel) {

    this.mapModel = mapModel;
    mapModel.addObserver(this);
    List<Spot> spotModels = mapModel.getSpots();

    setLayout(new GridLayout(10, 10, 1, 1));

    // Populate the spots:
    for (Iterator i = spotModels.iterator(); i.hasNext(); ) {
      Spot currentSpot = (Spot) i.next();
      SpotView sv = new SpotView(40, 40, currentSpot);
      add(sv);
      spotViews.add(sv);
    }

    // At the beginning, the player's map will be open for placing ships,
    // while the enemy's map is closed
    if (mapModel == BattleSystem.INSTANCE.playerMap) {
      chooseSpotViewMouseListener(Map.LISTENER_PLACE_SHIP);
    } else if (mapModel == BattleSystem.INSTANCE.enemyMap) {
      chooseSpotViewMouseListener(Map.LISTENER_NONE);
    }
  }
Ejemplo n.º 2
0
 @Override
 public void update(Observable o, Object arg) {
   Map map = (Map) o;
   chooseSpotViewMouseListener(map.getListenerMode());
 }