Class LadderGameBoardStackPane
java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
javafx.scene.layout.Pane
javafx.scene.layout.StackPane
edu.ntnu.idi.idatt.view.common.BoardStackPane
edu.ntnu.idi.idatt.view.laddergame.LadderGameBoardStackPane
- All Implemented Interfaces:
javafx.css.Styleable
,javafx.event.EventTarget
LadderGameBoardStackPane.
This class extends BoardStackPane
to provide a specialized view for displaying
LadderGameBoard
s. It handles the visual representation of the game board, including its
background, grid, placed components (ladders, slides, portals), and tile numbering.
Key functionalities include:
- Initialization with a
LadderGameBoard
and background image. - Management of board patterns (e.g., checkers).
- Loading and displaying
TileActionComponent
s based on the board state. - Dynamically updating the grid when rows or columns change.
- Handling drag-and-drop events for placing components onto grid cells.
- Applying visual styles to cells based on placed components or patterns.
- Converting board coordinates to screen coordinates for component placement.
- See Also:
-
Property Summary
Properties inherited from class javafx.scene.layout.StackPane
alignment
Properties inherited from class javafx.scene.layout.Region
background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width
Properties inherited from class javafx.scene.Parent
needsLayout
Properties inherited from class javafx.scene.Node
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, focusVisible, focusWithin, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
-
Field Summary
Fields inherited from class edu.ntnu.idi.idatt.view.common.BoardStackPane
backgroundImageView, board, boardDimensions, cellToCoordinatesMap, components, componentsPane, gridContainer, logger, onComponentDropped, onRemoveComponentsOutsideGrid
Fields inherited from class javafx.scene.layout.Region
USE_COMPUTED_SIZE, USE_PREF_SIZE
Fields inherited from class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addComponent
(String componentIdentifier, TileCoordinates coordinates) Adds a new visual component to the board at the specified coordinates, based on the provided component identifier.void
Applies the currently selected visual pattern (e.g., "Blue checker") to the grid cells.javafx.scene.layout.StackPane
createRowCell
(double cellWidth, double cellHeight, int row, int col) Creates a single visual cell (aStackPane
) for the grid display.protected String
getImagePath
(String componentIdentifier) Constructs the image file path for a given component identifier.Gets the current visual pattern applied to the board (e.g., "Blue checker").void
initialize
(Board board, String backgroundImagePath) Initializes the board stack pane with the givenBoard
(expected to be aLadderGameBoard
) and the path to its background image.protected void
LoadsTileActionComponent
s onto the board based on theTileAction
s associated with eachLadderGameTile
in the currentLadderGameBoard
.void
setPattern
(String pattern) Sets the visual pattern for the board and applies it to the grid display.void
Updates the visual representation of all components (ladders, slides, portals) on the board.void
Updates the visual grid display of the board.Methods inherited from class edu.ntnu.idi.idatt.view.common.BoardStackPane
findCellByCoordinates, getBackgroundImageView, getBoard, getBoardDimensions, getCellToCoordinatesMap, getComponents, getComponentsPane, getGridContainer, removeComponent, reset, setBackground, setBoard, setBoardDimensions, setNodeListeners, setOnComponentDropped, setOnRemoveComponentsOutsideGrid
Methods inherited from class javafx.scene.layout.StackPane
alignmentProperty, clearConstraints, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, getAlignment, getAlignment, getClassCssMetaData, getContentBias, getCssMetaData, getMargin, layoutChildren, requestLayout, setAlignment, setAlignment, setMargin
Methods inherited from class javafx.scene.layout.Pane
getChildren
Methods inherited from class javafx.scene.layout.Region
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, computeMaxHeight, computeMaxWidth, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isResizable, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty
Methods inherited from class javafx.scene.Parent
getBaselineOffset, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, queryAccessibleAttribute, requestParentLayout, setNeedsLayout, updateBounds
Methods inherited from class javafx.scene.Node
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, focusVisibleProperty, focusWithinProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInitialFocusTraversable, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isFocusVisible, isFocusWithin, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface javafx.css.Styleable
getStyleableNode
-
Constructor Details
-
LadderGameBoardStackPane
public LadderGameBoardStackPane()Constructs a newLadderGameBoardStackPane
. Calls the superclass constructor.
-
-
Method Details
-
initialize
Initializes the board stack pane with the givenBoard
(expected to be aLadderGameBoard
) and the path to its background image. This method calls the superclass initialization and then, on the JavaFX application thread, sets the board pattern, updates the grid display, and loads any existing components from the board model.- Overrides:
initialize
in classBoardStackPane
- Parameters:
board
- TheBoard
instance (must be aLadderGameBoard
).backgroundImagePath
- The file path to the background image for the board.
-
getPattern
Gets the current visual pattern applied to the board (e.g., "Blue checker").- Returns:
- The string representation of the current pattern.
-
setPattern
Sets the visual pattern for the board and applies it to the grid display.- Parameters:
pattern
- The name of the pattern to apply (e.g., "Blue checker", "None").
-
loadComponents
protected void loadComponents()LoadsTileActionComponent
s onto the board based on theTileAction
s associated with eachLadderGameTile
in the currentLadderGameBoard
. For each tile with a land action, it creates a corresponding visual component (e.g., ladder, slide, portal image) and places it on the board. Portal components may also have a color number set based on their identifier. After loading, it updates the overall board visuals.- Specified by:
loadComponents
in classBoardStackPane
-
getImagePath
Constructs the image file path for a given component identifier. The path is built assuming a structure like.- Specified by:
getImagePath
in classBoardStackPane
- Parameters:
componentIdentifier
- The unique identifier of the component.- Returns:
- The full string path to the component's image file.
-
addComponent
Adds a new visual component to the board at the specified coordinates, based on the provided component identifier. It calculates the destination tile for components like ladders and slides, or a random valid destination for portals. It also checks for tile occupancy to prevent overlapping placements. If the placement is valid, aTileActionComponent
is created and added to the internal collection of components, and the board visuals are updated.- Specified by:
addComponent
in classBoardStackPane
- Parameters:
componentIdentifier
- The string identifier of the component to add.coordinates
- TheTileCoordinates
(row, column) where the component originates.- Throws:
IllegalArgumentException
- if the target tile or destination tile is already occupied.
-
updateGrid
public void updateGrid()Updates the visual grid display of the board. This involves clearing the existing grid, removing any components that are now outside the grid boundaries (if dimensions changed), and then recreating the grid cells based on the current number of rows and columns in theLadderGameBoard
. Each cell is created with a label showing its tile ID and is configured for drag-and-drop operations. After recreating the grid, the current pattern and component visuals are reapplied.- Specified by:
updateGrid
in classBoardStackPane
-
createRowCell
public javafx.scene.layout.StackPane createRowCell(double cellWidth, double cellHeight, int row, int col) Creates a single visual cell (aStackPane
) for the grid display. Each cell consists of aRectangle
for its visual appearance and aLabel
displaying its tile ID. The cell is also mapped to its board coordinates and set up to handle drag-and-drop events for component placement.- Specified by:
createRowCell
in classBoardStackPane
- Parameters:
cellWidth
- The width of the cell in pixels.cellHeight
- The height of the cell in pixels.row
- The zero-indexed row number of the cell on the board.col
- The zero-indexed column number of the cell on the board.- Returns:
- A
StackPane
representing the created grid cell.
-
applyPattern
public void applyPattern()Applies the currently selected visual pattern (e.g., "Blue checker") to the grid cells. It iterates through each cell in the grid. If a cell corresponds to an even-numbered tile ID and is not occupied by a non-portal component (origin or destination), the appropriate CSS style class for the pattern is added to the cell'sRectangle
.- Specified by:
applyPattern
in classBoardStackPane
-
updateBoardVisuals
public void updateBoardVisuals()Updates the visual representation of all components (ladders, slides, portals) on the board. This method first clears any existing visual components from thecomponentsPane
. It then reapplies the board pattern. For eachTileActionComponent
stored:- It finds the origin and destination
Rectangle
cells on the grid. - Calculates the screen coordinates for the component based on its origin cell.
- Updates the component's size and position.
- Applies specific CSS style classes to the origin and destination cells based on the component type (e.g., "grid-cell-has-ladder", "grid-cell-ladder-destination").
- Adds the updated visual component to the
componentsPane
.
- Specified by:
updateBoardVisuals
in classBoardStackPane
- It finds the origin and destination
-