Skip to content

Commit

Permalink
Issue #139: Made Tree Tent use TreeTentType (#464)
Browse files Browse the repository at this point in the history
* Changes to `TreeTent`.

* Changes to `TreeTent`.

---------

Co-authored-by: Ivan Ho <[email protected]>
  • Loading branch information
pitbull51067 and Corppet authored Feb 24, 2023
1 parent 76fb8f9 commit 9d9e3ac
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/main/java/edu/rpi/legup/puzzle/treetent/ClueCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void executeCommand() {

for (TreeTentCell cell : tempList) {
cell = (TreeTentCell) board.getPuzzleElement(cell);
cell.setData(TreeTentType.GRASS.value);
cell.setData(TreeTentType.GRASS);
board.addModifiedData(cell);
finalTran.propagateChange(cell);

Expand Down Expand Up @@ -170,7 +170,7 @@ public void undoCommand() {

for (TreeTentCell cell : tempList) {
cell = (TreeTentCell) board.getPuzzleElement(cell);
cell.setData(TreeTentType.UNKNOWN.value);
cell.setData(TreeTentType.UNKNOWN);
board.removeModifiedData(cell);

final TreeTentCell finalCell = cell;
Expand Down
45 changes: 13 additions & 32 deletions src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,27 @@
import java.awt.*;
import java.awt.event.MouseEvent;

public class TreeTentCell extends GridCell<Integer> {
public class TreeTentCell extends GridCell<TreeTentType> {

public TreeTentCell(int valueInt, Point location) {
super(valueInt, location);
public TreeTentCell(TreeTentType value, Point location) {
super(value, location);
}

public TreeTentType getType() {
switch (data) {
case 0:
return TreeTentType.UNKNOWN;
case 1:
return TreeTentType.TREE;
case 2:
return TreeTentType.GRASS;
case 3:
return TreeTentType.TENT;
default:
return null;
}
return data;
}

@Override
public void setType(Element e, MouseEvent m) {
if (e.getElementName().equals("Unknown Tile")) {
this.data = 0;
}
else {
if (e.getElementName().equals("Tree Tile")) {
this.data = 1;
}
else {
if (e.getElementName().equals("Grass Tile")) {
this.data = 2;
}
else {
if (e.getElementName().equals("Tent Tile")) {
this.data = 3;
}
}
}
switch (e.getElementName()) {
case "Unknown Tile":
this.data = TreeTentType.UNKNOWN;
case "Tree Tile":
this.data = TreeTentType.TREE;
case "Grass Tile":
this.data = TreeTentType.GRASS;
case "Tent Tile":
this.data = TreeTentType.TENT;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat
throw new InvalidFileFormatException("TreeTent Factory: cell unknown value");
}

TreeTentCell cell = new TreeTentCell(value, new Point(x, y));
TreeTentCell cell = new TreeTentCell(TreeTentType.valueOf(value), new Point(x, y));
cell.setIndex(y * height + x);
return cell;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ public TreeTentController() {
public void changeCell(MouseEvent e, PuzzleElement element) {
TreeTentCell cell = (TreeTentCell) element;
if (e.getButton() == MouseEvent.BUTTON1) {
if (cell.getData() == 0) {
if (cell.getData() == TreeTentType.UNKNOWN) {
element.setData(2);
}
else {
if (cell.getData() == 2) {
if (cell.getData() == TreeTentType.GRASS) {
element.setData(3);
}
else {
Expand All @@ -125,11 +125,11 @@ public void changeCell(MouseEvent e, PuzzleElement element) {
}
else {
if (e.getButton() == MouseEvent.BUTTON3) {
if (cell.getData() == 0) {
if (cell.getData() == TreeTentType.UNKNOWN) {
element.setData(3);
}
else {
if (cell.getData() == 2) {
if (cell.getData() == TreeTentType.GRASS) {
element.setData(0);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
org.w3c.dom.Element cellsElement = newDocument.createElement("cells");
for (PuzzleElement puzzleElement : board.getPuzzleElements()) {
TreeTentCell cell = (TreeTentCell) puzzleElement;
if (cell.getData() != 0) {
if (cell.getData() != TreeTentType.UNKNOWN) {
org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement);
cellsElement.appendChild(cellElement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void initializeBoard(int rows, int columns) {
for (int y = 0; y < rows; y++) {
for (int x = 0; x < columns; x++) {
if (treeTentBoard.getCell(x, y) == null) {
TreeTentCell cell = new TreeTentCell(0, new Point(x, y));
TreeTentCell cell = new TreeTentCell(TreeTentType.UNKNOWN, new Point(x, y));
cell.setIndex(y * columns + x);
cell.setModifiable(true);
treeTentBoard.setCell(x, y, cell);
Expand Down Expand Up @@ -88,7 +88,7 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
for (int i = 0; i < elementDataList.getLength(); i++) {
TreeTentCell cell = (TreeTentCell) puzzle.getFactory().importCell(elementDataList.item(i), treeTentBoard);
Point loc = cell.getLocation();
if (cell.getData() != 0) {
if (cell.getData() != TreeTentType.UNKNOWN) {
cell.setModifiable(false);
cell.setGiven(true);
}
Expand All @@ -98,7 +98,7 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (treeTentBoard.getCell(x, y) == null) {
TreeTentCell cell = new TreeTentCell(0, new Point(x, y));
TreeTentCell cell = new TreeTentCell(TreeTentType.UNKNOWN, new Point(x, y));
cell.setIndex(y * height + x);
cell.setModifiable(true);
treeTentBoard.setCell(x, y, cell);
Expand Down
21 changes: 15 additions & 6 deletions src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentType.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package edu.rpi.legup.puzzle.treetent;

public enum TreeTentType {
UNKNOWN(0), TREE(1), GRASS(2), TENT(3),
CLUE_NORTH(-1), CLUE_EAST(-2), CLUE_SOUTH(-3), CLUE_WEST(-4);
import edu.rpi.legup.puzzle.masyu.MasyuType;

public int value;
public enum TreeTentType {
UNKNOWN, TREE, GRASS, TENT,
CLUE_NORTH, CLUE_EAST, CLUE_SOUTH, CLUE_WEST;

TreeTentType(int value) {
this.value = value;
public static TreeTentType valueOf(int num) {
switch (num) {
case 1:
return TREE;
case 2:
return GRASS;
case 3:
return TENT;
default:
return UNKNOWN;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Board getDefaultBoard(TreeNode node) {
for (PuzzleElement element : treeTentBoard.getPuzzleElements()) {
TreeTentCell cell = (TreeTentCell) element;
if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) {
cell.setData(TreeTentType.GRASS.value);
cell.setData(TreeTentType.GRASS);
treeTentBoard.addModifiedData(cell);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ private ArrayList<Board> genCombRecursive(TreeTentBoard iBoard, List<TreeTentCel
for (TreeTentCell c : original) {
if (selected.contains(c)) {
PuzzleElement change = temp.getPuzzleElement(c);
change.setData(TreeTentType.TENT.value);
change.setData(TreeTentType.TENT);
temp.addModifiedData(change);
}
else {
PuzzleElement change = temp.getPuzzleElement(c);
change.setData(TreeTentType.GRASS.value);
change.setData(TreeTentType.GRASS);
temp.addModifiedData(change);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Board getDefaultBoard(TreeNode node) {
for (PuzzleElement element : treeTentBoard.getPuzzleElements()) {
TreeTentCell cell = (TreeTentCell) element;
if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) {
cell.setData(TreeTentType.GRASS.value);
cell.setData(TreeTentType.GRASS);
treeTentBoard.addModifiedData(cell);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Board getDefaultBoard(TreeNode node) {
for (PuzzleElement element : treeTentBoard.getPuzzleElements()) {
TreeTentCell cell = (TreeTentCell) element;
if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) {
cell.setData(TreeTentType.TENT.value);
cell.setData(TreeTentType.TENT);
treeTentBoard.addModifiedData(cell);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Board getDefaultBoard(TreeNode node) {
for (PuzzleElement element : treeTentBoard.getPuzzleElements()) {
TreeTentCell cell = (TreeTentCell) element;
if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) {
cell.setData(TreeTentType.TENT.value);
cell.setData(TreeTentType.TENT);
treeTentBoard.addModifiedData(cell);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Board getDefaultBoard(TreeNode node) {
for (PuzzleElement element : treeTentBoard.getPuzzleElements()) {
TreeTentCell cell = (TreeTentCell) element;
if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) {
cell.setData(TreeTentType.GRASS.value);
cell.setData(TreeTentType.GRASS);
treeTentBoard.addModifiedData(cell);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public ArrayList<Board> getCases(Board board, PuzzleElement puzzleElement) {
ArrayList<Board> cases = new ArrayList<>();
Board case1 = board.copy();
PuzzleElement data1 = case1.getPuzzleElement(puzzleElement);
data1.setData(TreeTentType.TENT.value);
data1.setData(TreeTentType.TENT);
case1.addModifiedData(data1);
cases.add(case1);

Board case2 = board.copy();
PuzzleElement data2 = case2.getPuzzleElement(puzzleElement);
data2.setData(TreeTentType.GRASS.value);
data2.setData(TreeTentType.GRASS);
case2.addModifiedData(data2);
cases.add(case2);

Expand Down

0 comments on commit 9d9e3ac

Please sign in to comment.