Package com.barrybecker4.game.multiplayer.galactic

Examples of com.barrybecker4.game.multiplayer.galactic.Order


     * 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


        // now create the orders that will send numShipsToSend/numAttacks ships to each of these planets
        int attackFleetSize = numShipsToSend/numAttacks;
        it = closestEnemies.iterator();
        while (it.hasNext()) {
            Planet target = (Planet)it.next();
            Order order = new Order(origin, target, attackFleetSize);

            // only add the order if there is enough time remaining to reach that planet.
            if (order.getTimeNeeded() < numYearsRemaining)  {
                origin.deductShips(attackFleetSize);
                orders.add(order);
            }
        }
View Full Code Here

    }

    private void executeOrders(GalacticTurn gmove, List orders) {
        Iterator orderIt = orders.iterator();
        while (orderIt.hasNext()) {
            Order order = (Order) orderIt.next();
            executeOrder(gmove, orderIt, order);
        }
    }
View Full Code Here

        for (int i=0; i<nRows; i++) {
            String origin = model.getValueAt(i,ORIGIN_INDEX).toString();
            String dest = model.getValueAt(i,DESTINATION_INDEX).toString();
            int numShips = ((Integer)model.getValueAt(i, NUM_SHIPS_INDEX));

            Order o;
            Planet originPlanet = Galaxy.getPlanet(origin.charAt(0));
            Planet destPlanet = Galaxy.getPlanet(dest.charAt(0));

            if (i < numOldOrders) {
                Point2D currLoc = (lastOrders_.get(i)).getCurrentLocation();
                o = new Order(originPlanet, destPlanet, numShips, currLoc);
            }
            else {
                o = new Order(Galaxy.getPlanet(origin.charAt(0)), destPlanet, numShips);
                originPlanet.deductShips(numShips);
            }

            orders.add( o );
        }
View Full Code Here

     * add a row based on a player object
     * @param order to add
     */
    @Override
    public void addRow(Object order) {
        Order o = (Order)order;
        Object d[] = new Object[NUM_COLS];
        d[ORIGIN_INDEX] = o.getOrigin().getName();
        d[DESTINATION_INDEX ] = o.getDestination().getName();
        d[NUM_SHIPS_INDEX] = o.getFleetSize();
        d[DISTANCE_INDEX] = new Float(o.getTimeRemaining());

        getPlayerModel().addRow(d);
    }
View Full Code Here


        boolean canceled = orderDialog.showDialog();

        if ( !canceled ) { // newGame a game with the newly defined options
            Order order = orderDialog.getOrder();
            if (order != null)
                ordersTable_.addRow(order);
        }
    }
View Full Code Here

    public void actionPerformed( ActionEvent e ) {

        Object source = e.getSource();
        if (source == okButton) {
            // if there is not enough time to reach the planet, warn the user, and don't close the dlg.
            Order order = getOrder();
            // the order may be null if it was not valid
            if (order == null) {
                return;
            }
            double timeNeeded = order.getTimeNeeded();
            if (timeNeeded > numYearsRemaining_) {
                JOptionPane.showMessageDialog(this,
                       "There are not enough years left (" + numYearsRemaining_ + ") in the game to reach that planet",
                       "Information", JOptionPane.INFORMATION_MESSAGE);
            } else {
View Full Code Here

        int fleetSize = getFleetSize();
        if (fleetSize > (origin.getNumShips() - getOutgoingShips(origin))) {
            JOptionPane.showMessageDialog(this, GameContext.getLabel("CANT_SEND_MORE_THAN_YOU_HAVE"));
            return null;
        }
        return new Order(origin, destination, fleetSize);
    }
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.game.multiplayer.galactic.Order

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.