Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch the bulb tile to NonPlaceable element #375

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/main/java/edu/rpi/legup/controller/ElementController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

/**
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -132,21 +134,22 @@ 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();
Point scaledPoint = new Point((int) Math.floor(point.x / (30 * this.boardView.getScale())), (int) Math.floor(point.y / (30 * this.boardView.getScale())));
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();
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/edu/rpi/legup/model/Puzzle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java
Original file line number Diff line number Diff line change
@@ -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<Integer> {
private boolean isLite;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
Expand Down