Package com.barrybecker4.common.concurrency

Examples of com.barrybecker4.common.concurrency.Worker


        return renderer_;
    }

    @Override
    protected int getPieceSize(int cellSize, GamePiece piece) {
        Planet planet = (Planet)piece;

        double rad = planet.getRadius();
        return (int) (cellSize * rad);
    }
View Full Code Here


        return (int) (cellSize * rad);
    }

    @Override
    protected Color getPieceColor(GamePiece piece) {
        Planet planet = (Planet)piece;
        return planet.getColor();
    }
View Full Code Here

     * @param g2 graphics context
     * @param position the position of the piece to render
     */
    @Override
    public void render( Graphics2D g2, BoardPosition position, int cellSize, int margin, Board b) {
        Planet planet = (Planet)position.getPiece();
        if (planet == null) {
            return; // nothing to render
        }

        int pieceSize = getPieceSize(cellSize, planet);
        Point pos = getPosition(position, cellSize, pieceSize, margin);
        Ellipse2D circle = new Ellipse2D.Float( pos.x, pos.y, pieceSize + 1, pieceSize + 1 );
        int hlOffset = (int) (pieceSize / 2.3 + 0.5)//spec highlight offset
        Color c = getPieceColor(planet);

        RoundGradientPaint rgp = new RoundGradientPaint(
                pos.x + hlOffset, pos.y + hlOffset, Color.white, SPEC_HIGHLIGHT_RADIUS, c );

        g2.setPaint( rgp );
        g2.fill( circle );

        if ( planet.isUnderAttack() ) {
            g2.setStroke(ATTACK_STROKE);
            g2.setColor( ATTACK_COLOR );
            g2.drawOval( pos.x, pos.y, pieceSize + 1, pieceSize + 1 );
        }

        if ( planet.isHighlighted() ) {
                g2.setStroke(HIGHLIGHT_STROKE);
                g2.setColor( HIGHLIGHT_COLOR );
                g2.drawOval( pos.x, pos.y, pieceSize + 1, pieceSize + 1 );
            }


        int offset = (pieceSize<(0.6*cellSize))? -1 : cellSize/5;
        if ( planet.getAnnotation() != null ) {
                g2.setColor( Color.black );
                g2.setFont( PLANET_FONT );
                g2.drawString( planet.getAnnotation(), pos.x + 2*offset, pos.y + 3*offset);
        }
    }
View Full Code Here

     * Open the command dialog to get the players commands
     * @param gc the galactic controller
     */
    private void showOrdersDialog(GalacticController gc) {

        GalacticPlayer currentPlayer = (GalacticPlayer)gc.getCurrentPlayer();

        OrdersDialog ordersDialog =
                new OrdersDialog(null, currentPlayer, gc.getNumberOfYearsRemaining());
        Point p = getParent().getLocationOnScreen();

        // offset the dlg so the Galaxy grid is visible as a reference
        ordersDialog.setLocation((int)(p.getX()+0.7*getParent().getWidth()), (int)(p.getY()+getParent().getHeight()/3.0));

        boolean canceled = ordersDialog.showDialog();
        if ( !canceled ) { // newGame a game with the newly defined options
            currentPlayer.setOrders( ordersDialog.getOrders() );
            gc.advanceToNextPlayer();
        }
    }
View Full Code Here

     * add a row based on a player object
     * @param player to add
     */
    @Override
    protected void addRow(Object player) {
        GalacticPlayer p = (GalacticPlayer)player;
        Object d[] = new Object[getNumColumns()];
        List planets = Galaxy.getPlanets(p);
        // sum the num ships and productions

        d[NAME_INDEX] = p.getName();
        d[COLOR_INDEX ] = p.getColor();
        d[NUM_PLANETS_INDEX] = planets.size();
        d[SHIPS_INDEX] =  p.getTotalNumShips();
        d[PRODUCTION_INDEX] = p.getTotalProductionCapacity();
        getPlayerModel().addRow(d);
    }
View Full Code Here

                 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);
View Full Code Here

            // clear background
            g2.setColor( Color.white );
            g2.fillRect( 0, 0, this.getWidth(), this.getHeight() );

            GalacticPlayer attacker = battle_.getOrder().getOwner();
            String title = "Attacker : " + attacker.getName();
            drawPlayerRep(g2, attacker, attacker.getColor(), attackers_, title,
                          LEFT_MARGIN, LEFT_IMAGE_MARGIN, ATTACKER_Y);

            GalacticPlayer defender = battle_.getPlanet().getOwner(); // null if neutral
            Color defenderColor = (defender == null) ? Planet.NEUTRAL_COLOR : defender.getColor();
            String planetName = battle_.getPlanet().getName() + "";
            title = "Defender :"+ ( defender== null ? planetName : defender.getName() + " at "+ planetName);
            drawPlayerRep(g2, defender, defenderColor, defenders_, title,
                          LEFT_MARGIN, LEFT_IMAGE_MARGIN, DEFENDER_Y);
        }
View Full Code Here

     * @return done return true if the game is over after moving
     */
    @Override
    public boolean doComputerMove(Player player) {
        assert(!player.isHuman());
        GalacticRobotPlayer robot = (GalacticRobotPlayer)player;
        GalacticController gc = (GalacticController) controller_;
        GameContext.log(1, "now doing computer move. about to make orders");

        robot.makeOrders((Galaxy)getBoard(), gc.getNumberOfYearsRemaining());

        /* // records the result on the board.
        Move lastMove = getController().getLastMove();
        GalacticTurn gmove = GalacticTurn.createMove((lastMove==null)? 0 : lastMove.moveNumber + 1);
        gc.makeMove(gmove);
View Full Code Here

     * The dialog needs the user to dismiss it when done.
     * It is not shown if all computer players.
     * @param battle  the battle to show in a separate dialog
     */
    private void showBattle(BattleSimulation battle) {
        BattleDialog bDlg = new BattleDialog(parent_, battle, this);
        //bDlg.setLocationRelativeTo(this);

        Point p = this.getParent().getLocationOnScreen();
        // offset the dlg so the Galaxy grid is visible as a reference.
        bDlg.setLocation((int) (p.getX() + getParent().getWidth()),
                         (int) (p.getY() + 0.65 * getParent().getHeight()));
        bDlg.setModal(true);
        bDlg.setVisible(true);
    }
View Full Code Here

    }

    @Override
    protected NewGameDialog createNewGameDialog(Component parent, GameViewModel viewer )
    {
        return new GalacticNewGameDialog( parent, viewer );
    }
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.