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

Fix for LightUp and TreeTent Puzzle Creators #530

Closed
wants to merge 14 commits into from
46 changes: 46 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 Down Expand Up @@ -30,6 +32,50 @@ public LightUpCellType getType() {
return null;
}

/**
* Sets the type of this LightUpCell
*
* @param e element to set the type of this LightUp cell to
* @param m mouse event being processed
*/
@Override
public void setType(Element e, MouseEvent m) {
switch(e.getElementName()) {
case "Black Tile":
this.data = -1;
break;
case "Bulb Tile":
this.data = -4;
break;
case "Number Tile":
if (m.getButton() == MouseEvent.BUTTON1) {
// Place a number tile if not a number tile
if (this.data < 0 || this.data >= 9) {
this.data = 1;
}
else {
// Increase number
this.data++;
}
}
else {
if (m.getButton() == MouseEvent.BUTTON3) {
// Decrease number value (down to 1) if pressing number tile
if (this.data > 1 && this.data <= 8) {
this.data--;
}
else {
this.data = 1;
}
}
}
break;
default:
this.data = -3;
break;
}
}

public boolean isLite() {
return isLite;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ public LightUpExporter(LightUp lightUp) {

@Override
protected org.w3c.dom.Element createBoardElement(Document newDocument) {
LightUpBoard board = (LightUpBoard) puzzle.getTree().getRootNode().getBoard();
LightUpBoard board;
if (puzzle.getTree() != null) {
board = (LightUpBoard) puzzle.getTree().getRootNode().getBoard();
}
else {
board = (LightUpBoard) puzzle.getBoardView().getBoard();
}

org.w3c.dom.Element boardElement = newDocument.createElement("board");
boardElement.setAttribute("width", String.valueOf(board.getWidth()));
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 BlackTile extends PlaceableElement {
public class BlackTile extends NonPlaceableElement {
public BlackTile() {
super("LTUP-PLAC-0002", "Black Tile", "The black tile", "edu/rpi/legup/images/lightup/black.gif");
}
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not have Nurikabe IDs and images be used for Light Up puzzles. You should make a brand new ID and image for the Light Up unknown tile.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package edu.rpi.legup.puzzle.lightup.elements;

import edu.rpi.legup.model.elements.NonPlaceableElement;

public class UnknownTile extends NonPlaceableElement {
public UnknownTile() {
// This is the same tile as found in Nurikabe, but under LightUp to make it appear in the panel
super("NURI-UNPL-0002", "Unknown Tile", "A blank tile", "edu/rpi/legup/images/nurikabe/tiles/UnknownTile.png");
}
}
4 changes: 4 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ public void setType(Element e, MouseEvent m) {
switch (e.getElementName()) {
case "Unknown Tile":
this.data = TreeTentType.UNKNOWN;
break;
case "Tree Tile":
this.data = TreeTentType.TREE;
break;
case "Grass Tile":
this.data = TreeTentType.GRASS;
break;
case "Tent Tile":
this.data = TreeTentType.TENT;
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat
NamedNodeMap attributeList = node.getAttributes();
if (node.getNodeName().equalsIgnoreCase("cell")) {

int value = Integer.valueOf(attributeList.getNamedItem("value").getNodeValue());
int value = TreeTentType.valueToInt(attributeList.getNamedItem("value").getNodeValue());
int x = Integer.valueOf(attributeList.getNamedItem("x").getNodeValue());
int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue());
if (x >= width || y >= height) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,17 @@ public static TreeTentType valueOf(int num) {
return UNKNOWN;
}
}

public static int valueToInt(String value) {
switch(value) {
case "TREE":
return 1;
case "GRASS":
return 2;
case "TENT":
return 3;
default:
return 0;
}
}
}