Skip to content

Commit

Permalink
LightUp creator fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rspacerr committed Apr 15, 2023
1 parent 4b88a8a commit 63e7f98
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/lightup/LightUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public LightUp() {
@Override
public void initializeView() {
boardView = new LightUpView((LightUpBoard) currentBoard);
boardView.setBoard(currentBoard);
addBoardListener(boardView);
}

/**
Expand Down
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
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");
}
}

0 comments on commit 63e7f98

Please sign in to comment.