Package com.barrybecker4.game.twoplayer.common

Examples of com.barrybecker4.game.twoplayer.common.TwoPlayerController


     * display a dialog at the end of the game showing who won and other relevant
     * game specific information.
     */
    @Override
    public void showWinnerDialog() {
        GalacticTallyDialog tallyDialog = new GalacticTallyDialog(parent_, (GalacticController)controller_);
        tallyDialog.showDialog();
    }
View Full Code Here


     */
    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

     * start over with a new game using the current options.
     */
    @Override
    public void startNewGame() {
        reset();
        TwoPlayerController controller = get2PlayerController();
        if (get2PlayerController().getTwoPlayerOptions().isAutoOptimize())  {
            runOptimization();
        }
        if (controller.getPlayers().allPlayersComputer() ) {
            controller.computerMovesFirst();
            doComputerMove( false );
        }
        else if ( controller.doesComputerMoveFirst() ) {
            // computer vs human opponent
            controller.computerMovesFirst();
            refresh();
        }
        // for all other cases a human moves first
        // see the mouseClicked callback method for details
    }
View Full Code Here

     * @param move the move to make.
     * @return true if the game is over now.
     */
    private boolean manMoves( TwoPlayerMove move) {

        TwoPlayerController c = get2PlayerController();
        if ( GameContext.getUseSound() ) {
            GameContext.getMusicMaker().playNote( c.getTwoPlayerOptions().getPreferredTone(), 45, 0, 200, 1000 );
        }
        // need to clear the cache, otherwise we may render a stale board.
        cachedGameBoard_ = null;
        c.manMoves(move);

        // need to refresh here to show man moves in human only game
        if (c.getPlayers().allPlayersHuman())  {
            refresh();
        }

        // Second arg was true, but then we did final update twice.
        boolean done = c.getSearchable().done(move, false);
        sendGameChangedEvent(move);
        return done;
    }
View Full Code Here

     * Called when the game has changed in some way
     * @param evt change event
     */
    @Override
    public void gameChanged(GameChangedEvent evt) {
        TwoPlayerController c = get2PlayerController();
        assert c == evt.getController();

        // note: we don't show the winner dialog if we are having the computer play against itself.
        if (c.getSearchable().done((TwoPlayerMove)evt.getMove(), true)
                && c.getTwoPlayerOptions().getShowGameOverDialog()) {
            showWinnerDialog();
            //c.reset();
        }
        else {
            if (get2PlayerController().getPlayers().allPlayersComputer() && evt.getMove() != null) {
View Full Code Here

     * @param move the current move (it must not be null)
     * @return false if the game is at an end, otherwise return true
     */
     public final boolean continuePlay( TwoPlayerMove move ) {
         boolean done;
         TwoPlayerController controller = get2PlayerController();
         if (controller.getPlayers().allPlayersComputer()) {
             refresh();
             done = doComputerMove(!move.isPlayer1());
         }
         else {
             if ( controller.isPlayer1sTurn() ) {
                 assert !controller.isProcessing();
                 done = manMoves( move );
                 if ( !controller.getPlayers().getPlayer2().isHuman() && !done )  {
                     done = doComputerMove( false );
                 }
             }
             else { // player 2s turn
                 done = manMoves( move );
                 if ( !controller.getPlayers().getPlayer1().isHuman() && !done )  {
                     done = doComputerMove( true );
                 }
             }
         }
         return !done;
View Full Code Here

    /**
     * return the game to its state before the last human move.
     */
    public void undoLastManMove()  {
        TwoPlayerController c = get2PlayerController();
        PlayerList players = c.getPlayers();
        if ( players.allPlayersComputer() )
            return;
        Move move = c.undoLastMove();
        if ( move != null ) {
            undoneMoves_.add( move );
            if ( !players.allPlayersHuman() ) {
                undoneMoves_.add( c.undoLastMove() );
            }
            refresh();
        }
        else
            JOptionPane.showMessageDialog( this,
View Full Code Here

    /**
     * redo the last human player's move.
     */
    public void redoLastManMove()  {
        TwoPlayerController c = get2PlayerController();
        PlayerList players = c.getPlayers();
        if ( undoneMoves_.isEmpty() ) {
            JOptionPane.showMessageDialog( null,
                    GameContext.getLabel("NO_MOVES_TO_REDO"),
                    GameContext.getLabel("WARNING"),
                    JOptionPane.WARNING_MESSAGE );
            return;
        }
        if ( players.allPlayersComputer() )
            return;
        c.makeMove(undoneMoves_.removeLast());
        if ( !players.allPlayersHuman() ) {
            c.makeMove(undoneMoves_.removeLast());
        }
        refresh();
    }
View Full Code Here

    /**
     * @return the cached game board if we are in the middle of processing.
     */
    @Override
    public Board getBoard() {
       TwoPlayerController c = get2PlayerController();

       if (cachedGameBoard_ == null) {
           cachedGameBoard_ = (Board)c.getBoard().copy();
       }
       if (c.isProcessing() && !c.getTwoPlayerOptions().isAutoOptimize()) {
           return cachedGameBoard_;
       }
       else {
           return (Board)c.getBoard();
       }
    }
View Full Code Here

    /**
     *  Display all the relevant info for the moused over move.
     */
    public void setText(AbstractTwoPlayerBoardViewer viewer, TwoPlayerMove m, SearchTreeNode lastNode) {
        TwoPlayerPieceRenderer renderer = (TwoPlayerPieceRenderer)viewer.getPieceRenderer();
        TwoPlayerController controller = (TwoPlayerController)viewer.getController();
        String passSuffix = m.isPassingMove() ? " (Pass)" : "";
        String entity = "Human's move";
        int numKids = lastNode.getChildMoves()==null? 0 : lastNode.getChildMoves().length;

        Color c = renderer.getPlayer2Color();
        if ( m.isPlayer1() )
            c = renderer.getPlayer1Color();
        PlayerList players = controller.getPlayers();
        if ( (m.isPlayer1() && !players.getPlayer1().isHuman()) ||
             (!m.isPlayer1() && !players.getPlayer2().isHuman()) )
            entity = "Computer's move";

        StringBuilder sBuf = new StringBuilder("<html>");
View Full Code Here

TOP

Related Classes of com.barrybecker4.game.twoplayer.common.TwoPlayerController

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.