Example #1
0
 public void setGame(Game game) {
     this.game = game;
     Object clientProxy = Proxy.newProxyInstance(Client.class.getClassLoader(),
             new Class[] { UserInterface.class, GameEventListener.class }, new InvokeInSwingUiAdapter(controller));
     game.addUserInterface((UserInterface) clientProxy);
     game.addGameListener((GameEventListener) clientProxy);
 }
Example #2
0
 public ScorePhase(Game game) {
   super(game);
   barnCap = game.getCapability(BarnCapability.class);
   builderCap = game.getCapability(BuilderCapability.class);
   tunnelCap = game.getCapability(TunnelCapability.class);
   castleCap = game.getCapability(CastleCapability.class);
 }
Example #3
0
 public DrawPhase(Game game, GameController controller) {
   super(game, controller);
   DebugConfig debugConfig = getDebugConfig();
   if (debugConfig != null) {
     debugTiles = debugConfig.getDraw();
   }
   bazaarCap = game.getCapability(BazaarCapability.class);
   abbeyCap = game.getCapability(AbbeyCapability.class);
 }
Example #4
0
 protected void controllMessageReceived(ControllMessage msg) {
   game = createGame(msg);
   CreateGamePhase phase;
   if (msg.getSnapshot() == null) {
     phase = new CreateGamePhase(game, getServerProxy());
   } else {
     phase = new LoadGamePhase(game, msg.getSnapshot(), getServerProxy());
   }
   phase.setSlots(msg.getSlots());
   game.getPhases().put(phase.getClass(), phase);
   game.setPhase(phase);
 }
Example #5
0
 public Color getPlayerColor() {
     Player player = game.getActivePlayer();
     if (player == null) { //awt thread is not synced
         return Color.BLACK;
     } else {
         return playerColors[player.getSlot().getNumber()];
     }
 }
Example #6
0
 public void placeBridge(Location bridgeLoc) {
   assert bridge == null && bridgeLoc != null; // TODO AI support - remove bridge from tile
   Location normalizedLoc = bridgeLoc.rotateCCW(rotation);
   bridge = new Bridge();
   bridge.setId(game.idSequnceNextVal());
   bridge.setTile(this);
   bridge.setLocation(normalizedLoc);
   features.add(bridge);
   edgePattern = edgePattern.getBridgePattern(normalizedLoc);
 }
Example #7
0
 protected void callMessageReceived(CallMessage msg) {
   try {
     Phase phase = game.getPhase();
     logger.debug("Delegating {} on phase {}", msg.getMethod(), phase.getClass().getSimpleName());
     msg.call(phase, ClientIF.class);
     phase = game.getPhase(); // new phase can differ from the phase in prev msg.call !!!
     while (phase != null && !phase.isEntered()) {
       logger.debug("Entering phase {}", phase.getClass().getSimpleName());
       phase.setEntered(true);
       phase.enter();
       phase = game.getPhase();
       game.fireGameEvent().phaseEntered(phase);
     }
   } catch (InvocationTargetException ie) {
     logger.error(ie.getMessage(), ie.getCause());
   } catch (Exception e) {
     logger.error(e.getMessage(), e);
   }
 }
Example #8
0
    public boolean closeGame(boolean force) {
        boolean isGameRunning = getJMenuBar().isGameRunning();
        if (config.getConfirm().getGame_close() && isGameRunning && !(game.getPhase() instanceof GameOverPhase)) {
            if (localServer != null) {
                String options[] = {_("Close game"), _("Cancel") };
                int result = JOptionPane.showOptionDialog(this,
                        _("Game is running. Do you really want to quit game and also disconnect all other players?"),
                        _("Close game"),
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
                if (JOptionPane.OK_OPTION != result) return false;
            } else {
                String options[] = {_("Close game"), _("Cancel") };
                int result = JOptionPane.showOptionDialog(this,
                        _("Game is running. Do you really want to leave it?"),
                        _("Close game"),
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
                if (JOptionPane.OK_OPTION != result) return false;
            }
        }

        setTitle(BASE_TITLE);
        resetWindowIcon();
        if (localServer != null) {
            localServer.stop();
            localServer = null;
        } else if (server != null) {
             getClientStub().stop();
        }
        server = null;
        activePlayer = null;
        getJMenuBar().setIsGameRunning(false);
        if (controlPanel != null) {
            controlPanel.closeGame();
            mainPanel.closeGame();
        }
        if (discardedTilesDialog != null) {
            discardedTilesDialog.dispose();
            discardedTilesDialog = null;
            getJMenuBar().setShowDiscardedEnabled(false);
        }
        return true;
    }
  private void scaleImages(Game game) {
    for (Player player : game.getAllPlayers()) {
      Color color = player.getColors().getMeepleColor();
      scaleFigureImages(player, color, player.getFollowers());
      scaleFigureImages(player, color, player.getSpecialMeeples());
      if (game.hasCapability(TunnelCapability.class)) {
        Image tunnelA =
            rm.getLayeredImage(
                new LayeredImageDescriptor(
                    "player-meeples/tunnel", player.getColors().getMeepleColor()));
        Image tunnelB =
            rm.getLayeredImage(
                new LayeredImageDescriptor(
                    "player-meeples/tunnel", player.getColors().getTunnelBColor()));

        scaledImages.put(player.getIndex() + "tunnelA", scaleImage(tunnelA));
        scaledImages.put(player.getIndex() + "tunnelB", scaleImage(tunnelB));
      }
    }
    if (game.hasCapability(TowerCapability.class)) {
      scaledImages.put("towerpiece", scaleImage(rm.getImage("neutral/towerpiece")));
    }
    if (game.hasCapability(KingAndRobberBaronCapability.class)) {
      scaledImages.put("king", scaleImage(rm.getImage("neutral/king")));
      scaledImages.put("robber", scaleImage(rm.getImage("neutral/robber")));
    }
    if (game.hasCapability(BazaarCapability.class)) {
      scaledImages.put("bridge", scaleImage(rm.getImage("neutral/bridge")));
      scaledImages.put("castle", scaleImage(rm.getImage("neutral/castle")));
    }
    if (game.hasCapability(ClothWineGrainCapability.class)) {
      scaledImages.put("cloth", rm.getImage("neutral/cloth"));
      scaledImages.put("grain", rm.getImage("neutral/grain"));
      scaledImages.put("wine", rm.getImage("neutral/wine"));
    }
    if (game.hasCapability(BarnCapability.class)) {
      scaledImages.put("abbey", scaleImage(rm.getAbbeyImage(Rotation.R0).getImage()));
    }
    if (game.hasCapability(LittleBuildingsCapability.class)) {
      scaledImages.put("lb-tower", scaleImage(rm.getImage("neutral/lb-tower")));
      scaledImages.put("lb-house", scaleImage(rm.getImage("neutral/lb-house")));
      scaledImages.put("lb-shed", scaleImage(rm.getImage("neutral/lb-shed")));
    }
    if (game.hasCapability(GoldminesCapability.class)) {
      scaledImages.put("gold", scaleImage(rm.getImage("neutral/gold")));
    }
    if (game.hasCapability(DragonCapability.class)) {
      Image scaled =
          new ImageIcon(rm.getImage("neutral/dragon").getScaledInstance(42, 42, Image.SCALE_SMOOTH))
              .getImage();
      scaledImages.put("dragon", scaled);
    }
    if (game.hasCapability(FairyCapability.class)) {
      scaledImages.put("fairy", scaleImage(rm.getImage("neutral/fairy")));
    }
    if (game.hasCapability(MageAndWitchCapability.class)) {
      scaledImages.put("mage", scaleImage(rm.getImage("neutral/mage")));
      scaledImages.put("witch", scaleImage(rm.getImage("neutral/witch")));
    }
  }