Package com.barrybecker4.game.twoplayer.blockade.board

Examples of com.barrybecker4.game.twoplayer.blockade.board.BlockadeBoardPosition


     * @param pos one of the 3 base positions
     * @return list of accumulated walls to check.
     */
    private BlockadeWallList handleDirectionCase(BlockadeBoardPosition pos, int rowOffset, int colOffset,
                                                          BlockadeWallList wallsToCheck) {
        BlockadeBoardPosition offsetPos =
                    board.getPosition(pos.getRow() + rowOffset, pos.getCol() + colOffset);
        boolean isVertical = (rowOffset != 0);

        if (offsetPos != null) {
            boolean dirOpen = isVertical? offsetPos.isEastOpen() : offsetPos.isSouthOpen();
            if (dirOpen) {
                wallsToCheck.add( new BlockadeWall(pos, offsetPos));
            }
        }
        return wallsToCheck;
View Full Code Here


    @Override
    public String getToolTipText( MouseEvent e ) {
        Location loc = getBoardRenderer().createLocation(e);
        StringBuilder sb = new StringBuilder( "<html><font=-3>" );

        BlockadeBoardPosition space = ((BlockadeBoard)controller_.getBoard()).getPosition( loc );
        if ( space != null && GameContext.getDebugMode() > 0 ) {
            sb.append(space.toString());
            sb.append(space.isVisited()?":Visited":"");
            sb.append((space.isHomeBase()?(space.isHomeBase(true)?" P1 Home":"p2 Home"):""));
        }
        sb.append( "</font></html>" );
        return sb.toString();
    }
View Full Code Here

         BlockadeMoveToken mvToken = (BlockadeMoveToken) token;

         boolean player1 = token instanceof Player1BlockadeMoveToken;
         BlockadeWall wall = null;
         if (mvToken.hasWall())
             wall = new BlockadeWall(new BlockadeBoardPosition(mvToken.getWallPoint1().y, mvToken.getWallPoint1().x),
                                                       new BlockadeBoardPosition(mvToken.getWallPoint2().y, mvToken.getWallPoint2().x));

         return BlockadeMove.createMove(new ByteLocation(mvToken.getFromY(), mvToken.getFromX()),
                 new ByteLocation(mvToken.getToY(), mvToken.getToX()),
                 0, new GamePiece(player1), wall);
    }
View Full Code Here

        }

        BlockadeController controller = (BlockadeController)viewer_.getController();
        BlockadeBoard board = (BlockadeBoard) controller.getBoard();
        // get the original position.
        BlockadeBoardPosition position =
                board.getPosition(getRenderer().getDraggedPiece().getLocation());

        // valid or not, don't show the dragged piece after releasing the mouse.
        getRenderer().setDraggedPiece(null);

        BlockadeMove m = checkAndGetValidMove(position, loc);
        if (m == null) {
            return false;
        }

        // make sure that the piece shows while we decide where to place the wall.
        currentMove = m;
        GameContext.log(1, "legal human move :" + m.toString());
        position.getPiece().setTransparency((short) 0);
        boolean isPlayer1 = position.getPiece().isOwnedByPlayer1();
        BlockadeBoardPosition newPosition =
                board.getPosition(currentMove.getToRow(), currentMove.getToCol());
        newPosition.setPiece(position.getPiece());
        position.setPiece(null);
        viewer_.refresh();

        if (newPosition.isHomeBase( !isPlayer1 )) {
            hasWon = true;
            assert(isPlayer1 == (controller.getCurrentPlayer() == controller.getPlayers().getFirstPlayer()));
            controller.getCurrentPlayer().setWon(true);
        }
        else {
View Full Code Here

    private BlockadeMove checkAndGetValidMove(BlockadeBoardPosition origPosition, Location placedLocation) {
        BlockadeController controller = (BlockadeController)viewer_.getController();
        BlockadeBoard board = (BlockadeBoard) controller.getBoard();
        List<BlockadeMove> possibleMoveList = controller.getPossibleMoveList(origPosition);

        BlockadeBoardPosition destpos = board.getPosition( placedLocation );
        if (customCheckFails(destpos)) {
            JOptionPane.showMessageDialog( viewer_, GameContext.getLabel("ILLEGAL_MOVE"));
            return null;
        }
        // verify that the move is valid before allowing it to be made.
        Iterator it = possibleMoveList.iterator();
        boolean found = false;

        BlockadeMove m = null;
        while ( it.hasNext() && !found ) {
            m = (BlockadeMove) it.next();
            if ( (m.getToRow() == destpos.getRow()) && (m.getToCol() == destpos.getCol()) )
                found = true;
        }

        if ( !found ) {
            return null; // it was not valid
View Full Code Here

        boolean blocked = false;

        int fromRow = move.getFromRow();
        int fromCol = move.getFromCol();
        BlockadeBoardPosition start = board.getPosition(fromRow, fromCol);
        BlockadeBoardPosition west = start.getNeighbor(Direction.WEST, board);
        BlockadeBoardPosition north = start.getNeighbor(Direction.NORTH, board);
        BlockadeBoardPosition south, east;

        switch (move.getDirection()) {
            case NORTH_NORTH :
                BlockadeBoardPosition northNorth = start.getNeighbor(Direction.NORTH_NORTH, board);
                if (northNorth.isSouthBlocked()) blocked = true;
            case NORTH :
                if (north.isSouthBlocked()) blocked = true;
                break;
            case WEST_WEST :
                BlockadeBoardPosition westWest = start.getNeighbor(Direction.WEST_WEST, board);
                if (westWest.isEastBlocked()) blocked = true;
            case WEST :
                if (west.isEastBlocked()) blocked = true;
                break;
            case EAST_EAST :
                east = start.getNeighbor(Direction.EAST, board);
                if (east.isEastBlocked()) blocked = true;
            case EAST :
                if (start.isEastBlocked()) blocked = true;
                break;
            case SOUTH_SOUTH :
                south = start.getNeighbor(Direction.SOUTH, board);
                if (south.isSouthBlocked()) blocked = true;
            case SOUTH :
                if (start.isSouthBlocked()) blocked = true;
                break;
            case NORTH_WEST :
                BlockadeBoardPosition northWest = start.getNeighbor(Direction.NORTH_WEST, board);
                if (!((west.isEastOpen() && northWest.isSouthOpen()) ||
                     (north.isSouthOpen() && northWest.isEastOpen()) ) )  {
                    blocked = true;
                }
                break;
            case NORTH_EAST :
                BlockadeBoardPosition northEast = start.getNeighbor(Direction.NORTH_EAST, board);
                if (!((start.isEastOpen() && northEast.isSouthOpen()) ||
                     (north.isSouthOpen() && north.isEastOpen()) ) )  {
                    blocked = true;
                }
                break;
            case SOUTH_WEST :
                BlockadeBoardPosition southWest = start.getNeighbor(Direction.SOUTH_WEST, board);
                if (!((west.isEastOpen() && west.isSouthOpen()) ||
                     (start.isSouthOpen() && southWest.isEastOpen()) ) )  {
                    blocked = true;
                }
                break;
            case SOUTH_EAST :
                south = start.getNeighbor(Direction.SOUTH, board);
View Full Code Here

        // make the move
        board.makeMove(firstStep);

        // after making the first move, the shortest paths may have changed somewhat.
        // unfortunately, I think we need to recalculate them.
        BlockadeBoardPosition newPos =
                board.getPosition(firstStep.getToRow(), firstStep.getToCol());
        PathList ourPaths = board.findShortestPaths(newPos);

        List<BlockadeMove> wallMoves = wallFinder.findWallPlacementsForMove(firstStep, ourPaths);
        GameContext.log(2, "num wall placements for Move = " + wallMoves.size());
View Full Code Here

    public String getConstructorString() {

        String wallCreator ="null";
        if ( getWall() != null) {
            Iterator<BlockadeBoardPosition> it = getWall().getPositions().iterator();
            BlockadeBoardPosition p1 = it.next();
            BlockadeBoardPosition p2 = it.next();
            wallCreator = "new BlockadeWall(new BlockadeBoardPosition(" + p1.getRow()  +", "+ p1.getCol() "), "
                                                             + "new BlockadeBoardPosition(" + p2.getRow()  +", "+ p2.getCol() +"))";
        }
        String pieceCreator = "null";
        if (getPiece() != null) {
            pieceCreator = "new GamePiece(" + getPiece().isOwnedByPlayer1() + ")";
        }
View Full Code Here

        if (hasWallOverlap(wall)) {
            sError = GameContext.getLabel("CANT_OVERLAP_WALLS");
        }

        BlockadeBoardPosition pos = board.getPosition(location);
        if (sError == null && hasWallIntersection(wall)) {
             sError = GameContext.getLabel("CANT_INTERSECT_WALLS");
        }
        else if (sError == null && pos == null) {
            sError = GameContext.getLabel("INVALID_WALL_PLACEMENT");
View Full Code Here

     * @return error message if the new wall intersects an old one.
     */
    private boolean hasWallIntersection(BlockadeWall wall) {
         boolean vertical = wall.isVertical();
         // you cannot intersect one wall with another
         BlockadeBoardPosition pos = wall.getFirstPosition();

         BlockadeBoardPosition secondPos =
                    (vertical? board.getPosition(pos.getRow(), pos.getCol()+1) :
                               board.getPosition(pos.getRow()+1, pos.getCol()));
        return (vertical && pos.isSouthBlocked() && secondPos.isSouthBlocked())
                || (!vertical && pos.isEastBlocked()) && secondPos.isEastBlocked();
    }
View Full Code Here

TOP

Related Classes of com.barrybecker4.game.twoplayer.blockade.board.BlockadeBoardPosition

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.