Package com.barrybecker4.common.concurrency

Examples of com.barrybecker4.common.concurrency.Worker


    private OnlineGameTable(String name, Player owner, Player[] initialPlayers, GameOptions options) {
        name_ = name;
        owner_ = owner;
        newestHumanPlayer_ = owner;
        players_ = new PlayerList();
        gameOptions_ = options;
        players_.addAll(Arrays.asList(initialPlayers));
    }
View Full Code Here


    @Override
    public PlayerList getPlayers() {

        TableModel model = table_.getModel();
        int nRows = model.getRowCount();
        PlayerList players = new PlayerList();
        for (int i=0; i<nRows; i++) {
            char planetName = (Character) model.getValueAt(i, HOME_PLANET_INDEX);
            Planet planet = Galaxy.getPlanet(planetName);
            planet.setProductionCapacity((Integer) model.getValueAt(i, PRODUCTION_INDEX));
            planet.setNumShips((Integer) (model.getValueAt(i, NUM_SHIPS_INDEX)));
            ImageIcon icon = (ImageIcon) (model.getValueAt(i, ICON_INDEX));
            players.add(GalacticPlayer.createGalacticPlayer(
                                    (String) model.getValueAt(i, NAME_INDEX),
                                    planet,
                                    (Color) model.getValueAt(i, COLOR_INDEX),
                                    ((Boolean) model.getValueAt(i, HUMAN_INDEX)), icon));
        }
View Full Code Here

     * Factory method to create the game controller via reflection.
     * The server should not have a ui component.
     */
    private void createController(String gameName) {

        GamePlugin plugin = PluginManager.getInstance().getPlugin(gameName);
        GameContext.loadResources(gameName);

        // for now, also create a corresponding viewer. The server should really not have knowledge of a UI component.
        // fix this by doing plugin.getModelInstance, then getting the controller from that.
        GamePanel panel  = plugin.getPanelInstance();
        panel.init(null);
        GameBoardViewer viewer = panel.getViewer();

        controller_ = viewer.getController();
    }
View Full Code Here

        GamePlugin plugin = PluginManager.getInstance().getPlugin(gameName);
        GameContext.loadResources(gameName);

        // for now, also create a corresponding viewer. The server should really not have knowledge of a UI component.
        // fix this by doing plugin.getModelInstance, then getting the controller from that.
        GamePanel panel  = plugin.getPanelInstance();
        panel.init(null);
        GameBoardViewer viewer = panel.getViewer();

        controller_ = viewer.getController();
    }
View Full Code Here

     * Should split this out into a separate PlayerCommandPanel class.
     */
    @Override
    protected JPanel createCustomInfoPanel() {

        commandPanel_ = new SectionPanel();

        //setCommandPanelTitle(Player player)

        JPanel bp = createPanel();
        bp.setBorder(createMarginBorder());
View Full Code Here

        // for now, also create a corresponding viewer. The server should really not have knowledge of a UI component.
        // fix this by doing plugin.getModelInstance, then getting the controller from that.
        GamePanel panel  = plugin.getPanelInstance();
        panel.init(null);
        GameBoardViewer viewer = panel.getViewer();

        controller_ = viewer.getController();
    }
View Full Code Here

    void ok() {
        GameContext.setDebugMode( dbgLevelField_.getIntValue() );
        GameContext.setProfiling( profileCheckbox_.isSelected() );
        GameContext.getLogger().setDestination( logDestination_ );

        GameBoardViewer v = ((GameBoardViewer)controller_.getViewer());
        v.setBackground( boardColorButton_.getBackground() );
        v.setGridColor( gridColorButton_.getBackground() );

        LocaleType[] locales = LocaleType.values();
        GameContext.setLocale(locales[localeComboBox_.getSelectedIndex()]);

        // game specific options
View Full Code Here

     * The Orders button was pressed.
     * open the Orders dialog to get the players commands
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        GalacticController gc = (GalacticController)controller_;
        gameChanged(null); // update the current player in the label

        if (e.getSource() == commandButton_) {

            // if the current player does not own any planets, then advance to the next player
            if (Galaxy.getPlanets((GalacticPlayer) gc.getCurrentPlayer()).size() == 0)  {
                gc.advanceToNextPlayer();
            }

            showOrdersDialog(gc);
        }
        else if (e.getSource() == passButton_) {
           gc.advanceToNextPlayer();
        }
    }
View Full Code Here

        viewerPanel.add( infoLabel_, BorderLayout.SOUTH);

        JPanel buttonsPanel = createButtonsPanel();

        Planet defendingPlanet =  battle_.getPlanet();
        String text = "There is a battle at "+defendingPlanet.getName()+".\n";

        descriptionLabel_.setEditable(false);
        //descriptionLabel_.setLineWrap(true);
        descriptionLabel_.setContentType("text/html");
        descriptionLabel_.setText(text);
View Full Code Here

            this.paint(this.getGraphics());
        }

        @Override
        public void run() {
             Planet destPlanet = battle_.getPlanet();
             int numAttackShips = battle_.getOrder().getFleetSize();
             int numDefendShips = destPlanet.getNumShips();
             //String defender = (destPlanet.getOwner()==null)? "Neutral" : destPlanet.getOwner().getName();

             // play back the move sequence
             List sequence = battle_.getHitSequence();
             if (sequence.isEmpty()) {
                 // reinforced!
                 GameContext.getMusicMaker().playNote( Instruments.APPLAUSE, 45, 0, 200, 1000 );
                 GameContext.getMusicMaker().playNote(70, 50, 900);
                 GameContext.getMusicMaker().playNote(90, 40, 1000);
                 descriptionLabel_.setText("Planet "+destPlanet.getName()+" has been reinforced.");
             }
             else {
                 boolean useSound = GameContext.getUseSound();
                 Iterator it = sequence.iterator();
                 if (useSound)
                     GameContext.getMusicMaker().playNote( Instruments.GUNSHOT, 45, 0, 200, 1000 );

                 while (it.hasNext()) {
                     GalacticPlayer p = (GalacticPlayer)it.next();
                     int total = numAttackShips + numDefendShips;
                     int time = 1 + BATTLE_SPEED / (1+total);
                     if (p == battle_.getOrder().getOwner()) {
                         if (useSound)
                             GameContext.getMusicMaker().playNote(100, time, 800);
                         numAttackShips--;
                     }
                     else {
                         if (useSound)
                             GameContext.getMusicMaker().playNote(80, time, 800);
                         numDefendShips--;
                     }

                     refresh(numAttackShips, numDefendShips);
                     ThreadUtil.sleep(time);
                 }
                 assert(numAttackShips == 0 || numDefendShips == 0):
                         "numAttackShips="+numAttackShips+" numDefendShips="+numDefendShips;
                 String winMessage;
                 if (numAttackShips==0)
                     winMessage = "Planet "+destPlanet.getName()+" has successfully defended itself.";
                 else
                     winMessage = battle_.getOrder().getOwner().getName()+ " has conquered planet "+destPlanet.getName();

                 descriptionLabel_.setText( "<html>"+ descriptionLabel_.getText()+ "<b>"+ winMessage +"/b></html>");
             }

             viewer_.showPlanetUnderAttack(battle_.getPlanet(), false)// battle is done
View Full Code Here

TOP

Related Classes of com.barrybecker4.common.concurrency.Worker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.