Search in sources :

Example 11 with SOCCity

use of soc.game.SOCCity in project JSettlers2 by jdmonin.

the class SOCPlayerInterface method updateAtPutPiece.

/**
 * Handle updates after putting a piece on the board,
 * or moving a ship that was already placed.
 * Place or move the piece within our {@link SOCGame}
 * and visually on our {@link SOCBoardPanel}.
 *
 * @param mesPn  The piece's player number
 * @param coord  The piece's coordinate.  If <tt>isMove</tt>, the coordinate to move <em>from</em>.
 * @param pieceType  Piece type, like {@link SOCPlayingPiece#CITY}
 * @param isMove   If true, it's a move, not a new placement; valid only for ships.
 * @param moveToCoord  If <tt>isMove</tt>, the coordinate to move <em>to</em>.  Otherwise ignored.
 *
 * @see #updateAtPiecesChanged()
 * @since 2.0.00
 */
public void updateAtPutPiece(final int mesPn, final int coord, final int pieceType, final boolean isMove, final int moveToCoord) {
    // TODO consider more effic way for flushBoardLayoutAndRepaint, without the =null
    final SOCPlayer pl = (pieceType != SOCPlayingPiece.VILLAGE) ? game.getPlayer(mesPn) : null;
    final SOCPlayer oldLongestRoadPlayer = game.getPlayerWithLongestRoad();
    final SOCHandPanel mesHp = (pieceType != SOCPlayingPiece.VILLAGE) ? getPlayerHandPanel(mesPn) : null;
    final boolean[] debugShowPotentials = boardPanel.debugShowPotentials;
    final SOCPlayingPiece pp;
    switch(pieceType) {
        case SOCPlayingPiece.ROAD:
            pp = new SOCRoad(pl, coord, null);
            game.putPiece(pp);
            mesHp.updateValue(PlayerClientListener.UpdateType.Road);
            if (debugShowPotentials[4] || debugShowPotentials[5] || debugShowPotentials[7])
                boardPanel.flushBoardLayoutAndRepaint();
            break;
        case SOCPlayingPiece.SETTLEMENT:
            pp = new SOCSettlement(pl, coord, null);
            game.putPiece(pp);
            mesHp.updateValue(PlayerClientListener.UpdateType.Settlement);
            /**
             * if this is the second initial settlement, then update the resource display
             */
            mesHp.updateValue(PlayerClientListener.UpdateType.ResourceTotalAndDetails);
            if (debugShowPotentials[4] || debugShowPotentials[5] || debugShowPotentials[7] || debugShowPotentials[6])
                boardPanel.flushBoardLayoutAndRepaint();
            break;
        case SOCPlayingPiece.CITY:
            pp = new SOCCity(pl, coord, null);
            game.putPiece(pp);
            mesHp.updateValue(PlayerClientListener.UpdateType.Settlement);
            mesHp.updateValue(PlayerClientListener.UpdateType.City);
            if (debugShowPotentials[4] || debugShowPotentials[5] || debugShowPotentials[7] || debugShowPotentials[6])
                boardPanel.flushBoardLayoutAndRepaint();
            break;
        case SOCPlayingPiece.SHIP:
            pp = new SOCShip(pl, coord, null);
            if (!isMove) {
                game.putPiece(pp);
                mesHp.updateValue(PlayerClientListener.UpdateType.Ship);
            } else {
                game.moveShip((SOCShip) pp, moveToCoord);
                if (mesHp == clientHand)
                    // just in case; it probably wasn't enabled
                    mesHp.disableBankUndoButton();
            }
            if (debugShowPotentials[4] || debugShowPotentials[5] || debugShowPotentials[7])
                boardPanel.flushBoardLayoutAndRepaint();
            break;
        case SOCPlayingPiece.VILLAGE:
            // no need to refresh boardPanel after receiving each village
            pp = new SOCVillage(coord, game.getBoard());
            game.putPiece(pp);
            // <--- Early return: Piece is part of board initial layout, not player info ---
            return;
        case SOCPlayingPiece.FORTRESS:
            pp = new SOCFortress(pl, coord, game.getBoard());
            game.putPiece(pp);
            // <--- Early return: Piece is part of board initial layout, not added during game ---
            return;
        default:
            chatPrintDebug("* Unknown piece type " + pieceType + " at coord 0x" + Integer.toHexString(coord));
            // <--- Early return ---
            return;
    }
    mesHp.updateValue(PlayerClientListener.UpdateType.VictoryPoints);
    boardPanel.repaint();
    buildingPanel.updateButtonStatus();
    if (game.isDebugFreePlacement() && game.isInitialPlacement())
        // update here, since gamestate doesn't change to trigger update
        boardPanel.updateMode();
    if (hasCalledBegan && (game.getGameState() >= SOCGame.START1A))
        playSound(SOUND_PUT_PIECE);
    /**
     * Check for and announce change in longest road; update all players' victory points.
     */
    SOCPlayer newLongestRoadPlayer = game.getPlayerWithLongestRoad();
    if (newLongestRoadPlayer != oldLongestRoadPlayer) {
        updateLongestLargest(true, oldLongestRoadPlayer, newLongestRoadPlayer);
    }
}
Also used : SOCSettlement(soc.game.SOCSettlement) SOCVillage(soc.game.SOCVillage) SOCCity(soc.game.SOCCity) SOCPlayingPiece(soc.game.SOCPlayingPiece) SOCShip(soc.game.SOCShip) SOCPlayer(soc.game.SOCPlayer) SOCFortress(soc.game.SOCFortress) SOCRoad(soc.game.SOCRoad)

Example 12 with SOCCity

use of soc.game.SOCCity in project JSettlers2 by jdmonin.

the class SOCDisplaylessPlayerClient method handlePUTPIECE.

/**
 * handle the "put piece" message
 *<P>
 * This method is public static for access by
 * {@code SOCRobotBrain.handlePUTPIECE_updateGameData(SOCPutPiece)}.
 * @param mes  the message
 * @param ga  Message's game from {@link SOCPutPiece#getGame()}; if {@code null}, message is ignored
 */
public static void handlePUTPIECE(final SOCPutPiece mes, SOCGame ga) {
    if (ga != null) {
        final int pieceType = mes.getPieceType();
        final int coord = mes.getCoordinates();
        final SOCPlayer pl = (pieceType != SOCPlayingPiece.VILLAGE) ? ga.getPlayer(mes.getPlayerNumber()) : null;
        switch(pieceType) {
            case SOCPlayingPiece.ROAD:
                ga.putPiece(new SOCRoad(pl, coord, null));
                break;
            case SOCPlayingPiece.SETTLEMENT:
                ga.putPiece(new SOCSettlement(pl, coord, null));
                break;
            case SOCPlayingPiece.CITY:
                ga.putPiece(new SOCCity(pl, coord, null));
                break;
            case SOCPlayingPiece.SHIP:
                ga.putPiece(new SOCShip(pl, coord, null));
                break;
            case SOCPlayingPiece.FORTRESS:
                ga.putPiece(new SOCFortress(pl, coord, ga.getBoard()));
                break;
            case SOCPlayingPiece.VILLAGE:
                ga.putPiece(new SOCVillage(coord, ga.getBoard()));
                break;
            default:
                System.err.println("Displayless.handlePUTPIECE: game " + ga.getName() + ": Unknown pieceType " + pieceType);
        }
    }
}
Also used : SOCSettlement(soc.game.SOCSettlement) SOCVillage(soc.game.SOCVillage) SOCCity(soc.game.SOCCity) SOCShip(soc.game.SOCShip) SOCPlayer(soc.game.SOCPlayer) SOCFortress(soc.game.SOCFortress) SOCRoad(soc.game.SOCRoad)

Aggregations

SOCCity (soc.game.SOCCity)12 SOCRoad (soc.game.SOCRoad)10 SOCSettlement (soc.game.SOCSettlement)10 SOCShip (soc.game.SOCShip)10 SOCPlayer (soc.game.SOCPlayer)7 SOCBoardLarge (soc.game.SOCBoardLarge)3 SOCFortress (soc.game.SOCFortress)3 SOCPlayingPiece (soc.game.SOCPlayingPiece)3 SOCVillage (soc.game.SOCVillage)2 Graphics2D (java.awt.Graphics2D)1 Image (java.awt.Image)1 BufferedImage (java.awt.image.BufferedImage)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Vector (java.util.Vector)1 SOCBoard (soc.game.SOCBoard)1 SOCLRPathData (soc.game.SOCLRPathData)1 SOCPlayerNumbers (soc.game.SOCPlayerNumbers)1