From 4b7463777dfda515f21afd735ad16b1043e8355a Mon Sep 17 00:00:00 2001 From: Weijun Li <83390795+wei-jun7@users.noreply.github.com> Date: Sat, 12 Nov 2022 21:46:31 -0500 Subject: [PATCH 1/2] switch the bulb tile to NonPlaceable element --- src/main/java/edu/rpi/legup/model/Puzzle.java | 4 +++- .../java/edu/rpi/legup/puzzle/lightup/elements/BulbTile.java | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/rpi/legup/model/Puzzle.java b/src/main/java/edu/rpi/legup/model/Puzzle.java index 2a98f9d46..80a665453 100644 --- a/src/main/java/edu/rpi/legup/model/Puzzle.java +++ b/src/main/java/edu/rpi/legup/model/Puzzle.java @@ -79,6 +79,7 @@ public Puzzle() { private void registerPuzzleElements() { String packageName = this.getClass().getPackage().toString().replace("package ", ""); + System.out.println(packageName); try { Class[] possElements = LegupUtils.getClasses(packageName); @@ -96,10 +97,11 @@ private void registerPuzzleElements() { Constructor cons = c.getConstructor(); try { Element element = (Element) cons.newInstance(); - + System.out.println("this is a type " + element.getElementType()); switch (element.getElementType()) { case PLACEABLE: this.addPlaceableElement((PlaceableElement) element); + break; case NONPLACEABLE: this.addNonPlaceableElement((NonPlaceableElement) element); diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BulbTile.java b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BulbTile.java index 5fc4a334f..3ed4bdb39 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BulbTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BulbTile.java @@ -1,8 +1,8 @@ package edu.rpi.legup.puzzle.lightup.elements; -import edu.rpi.legup.model.elements.PlaceableElement; +import edu.rpi.legup.model.elements.NonPlaceableElement; -public class BulbTile extends PlaceableElement { +public class BulbTile extends NonPlaceableElement { public BulbTile() { super("LTUP-PLAC-0001", "Bulb Tile", "The bulb tile", "edu/rpi/legup/images/lightup/light.png"); } From 76042682ec6ccb4f6d1eeeacdd01b6ff887b25da Mon Sep 17 00:00:00 2001 From: Weijun Li <83390795+wei-jun7@users.noreply.github.com> Date: Sat, 12 Nov 2022 23:05:11 -0500 Subject: [PATCH 2/2] it is finished the put the element in the light up puzzle base on the rule we have. Also, the number of tile have the truouble with the constructuror which maybe it is not be implement . which it is not show it on the rule panel. --- .../legup/controller/EditorElementController.java | 3 ++- .../rpi/legup/controller/ElementController.java | 13 ++++++++----- .../edu/rpi/legup/model/gameboard/GridBoard.java | 5 +++++ .../edu/rpi/legup/puzzle/lightup/LightUpCell.java | 14 ++++++++++++++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/java/edu/rpi/legup/controller/EditorElementController.java b/src/main/java/edu/rpi/legup/controller/EditorElementController.java index 80e7dd35a..03e488d07 100644 --- a/src/main/java/edu/rpi/legup/controller/EditorElementController.java +++ b/src/main/java/edu/rpi/legup/controller/EditorElementController.java @@ -45,9 +45,10 @@ public void setElementController(ElementController elementController) { public void buttonPressed(Element element) { // TODO: implement what happens when element is pressed - System.out.printf("%s button pressed!\n", element.getElementName()); + //System.out.printf("%s button pressed!\n", element.getElementName()); if (elementController != null) { elementController.setSelectedElement(element); + System.out.printf("%s button pressed!\n", element.getElementName()); } } diff --git a/src/main/java/edu/rpi/legup/controller/ElementController.java b/src/main/java/edu/rpi/legup/controller/ElementController.java index 50fa7d1b9..9dcce9931 100644 --- a/src/main/java/edu/rpi/legup/controller/ElementController.java +++ b/src/main/java/edu/rpi/legup/controller/ElementController.java @@ -70,7 +70,7 @@ public void mouseClicked(MouseEvent e) { */ @Override public void mousePressed(MouseEvent e) { - + System.out.println("Get in to the Mouse Pressed event."); } /** @@ -80,6 +80,7 @@ public void mousePressed(MouseEvent e) { */ @Override public void mouseReleased(MouseEvent e) { + System.out.println("Get in to the Mouse released event."); TreePanel treePanel = GameBoardFacade.getInstance().getLegupUI().getTreePanel(); TreeView treeView = null; if (treePanel != null) { @@ -90,6 +91,7 @@ public void mouseReleased(MouseEvent e) { if (boardView == null) { boardView = getInstance().getLegupUI().getEditorBoardView(); } + Board board = boardView.getBoard(); ElementView elementView = boardView.getElement(e.getPoint()); TreeViewSelection selection = null; @@ -132,6 +134,7 @@ public void mouseReleased(MouseEvent e) { } } } + System.out.println("The selected Eelement is " + this.selectedElement.getElementName()); // if (selectedElement != null) { GridBoard b = (GridBoard) this.boardView.getBoard(); Point point = e.getPoint(); @@ -139,14 +142,14 @@ public void mouseReleased(MouseEvent e) { if (this.boardView.getBoard() instanceof TreeTentBoard) { scaledPoint.setLocation(scaledPoint.getX() - 1, scaledPoint.getY() - 1); } - System.out.printf("selected Element is NOT null, attempting to change board at (%d, %d)\n", scaledPoint.x, scaledPoint.y); -// System.out.println("Before: " + b.getCell(scaledPoint.x, scaledPoint.y).getData()); + System.out.printf("selected Element( %s )is NOT null, attempting to change board at (%d, %d)\n", this.selectedElement.getElementName() , scaledPoint.x, scaledPoint.y); + System.out.println("Before: " + b.getCell(scaledPoint.x, scaledPoint.y).getData()); b.setCell(scaledPoint.x, scaledPoint.y, this.selectedElement, e); -// System.out.println("After: " + b.getCell(scaledPoint.x, scaledPoint.y).getData()); + System.out.println("After: " + b.getCell(scaledPoint.x, scaledPoint.y).getData()); // } else { // System.out.println("selected Element is null!"); // } - boardView.repaint(); + this.boardView.repaint(); } /** diff --git a/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java b/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java index 3e94c57ad..c0808c4d9 100644 --- a/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java +++ b/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java @@ -68,7 +68,9 @@ public void setCell(int x, int y, GridCell cell) { } public void setCell(int x, int y, Element e, MouseEvent m) { + System.out.println("This come to the set cell function."); if (this instanceof TreeTentBoard && ((y == dimension.height && 0 <= x && x < dimension.width) || (x == dimension.width && 0 <= y && y < dimension.height))) { + System.out.println("The choice one"); TreeTentBoard treeTentBoard = ((TreeTentBoard) this); TreeTentClue clue = treeTentBoard.getClue(x, y); if (y == dimension.height && clue.getData() < dimension.width) { @@ -84,12 +86,15 @@ public void setCell(int x, int y, Element e, MouseEvent m) { } } else { + System.out.println("The choice two"); if (e != null && y * dimension.width + x >= puzzleElements.size() || x >= dimension.width || y >= dimension.height || x < 0 || y < 0) { + System.out.println("The choice two 1 not change "); return; } else { if (e != null) { + System.out.println("The choice two 2 change"); puzzleElements.get(y * dimension.width + x).setType(e, m); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java index 3189eff7a..48283048a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java @@ -1,8 +1,10 @@ package edu.rpi.legup.puzzle.lightup; +import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.GridCell; import java.awt.*; +import java.awt.event.MouseEvent; public class LightUpCell extends GridCell { private boolean isLite; @@ -29,6 +31,18 @@ public LightUpCellType getType() { } return null; } + @Override + public void setType(Element e, MouseEvent m) { + if (e.getElementName().equals("Black Tile")) { + this.data = -1; + } + else { + if (e.getElementName().equals("Bulb Tile")) { + this.data = -4; + } + } + + } public boolean isLite() { return isLite;