Skip to content

Commit

Permalink
Fix treetent puzzle editor (#692)
Browse files Browse the repository at this point in the history
* fix treetent puzzle editor (add breaks for switch) (exporter exports
  same data that importer expects)

* allow for treetent clue to go up/down

* comply with checkstyles

---------

Co-authored-by: Jacob Long <longj6@rpi.edu>
Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 1, 2023
1 parent e858844 commit ca9fef9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
37 changes: 31 additions & 6 deletions src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,40 @@ public void setCell(int x, int y, Element e, MouseEvent m) {
if (this instanceof TreeTentBoard && ((y == dimension.height && 0 <= x && x < dimension.width) || (x == dimension.width && 0 <= y && y < dimension.height))) {
TreeTentBoard treeTentBoard = ((TreeTentBoard) this);
TreeTentClue clue = treeTentBoard.getClue(x, y);
if (y == dimension.height && clue.getData() < dimension.width) {
clue.setData(clue.getData() + 1);
if (y == dimension.height) {
if (m.getButton() == MouseEvent.BUTTON1) {
if (clue.getData() < dimension.height) {
clue.setData(clue.getData() + 1);
}
else {
clue.setData(0);
}
}
else {
if (clue.getData() > 0) {
clue.setData(clue.getData() - 1);
}
else {
clue.setData(dimension.height);
}
}
}
else {
if (x == dimension.width && clue.getData() < dimension.height) {
clue.setData(clue.getData() + 1);
else { //x == dimension.width
if (m.getButton() == MouseEvent.BUTTON1) {
if (clue.getData() < dimension.width) {
clue.setData(clue.getData() + 1);
}
else {
clue.setData(0);
}
}
else {
clue.setData(0);
if (clue.getData() > 0) {
clue.setData(clue.getData() - 1);
}
else {
clue.setData(dimension.width);
}
}
}
}
Expand Down
16 changes: 16 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 @@ -16,15 +16,31 @@ public TreeTentType getType() {
return data;
}

public int getValue() {
switch (data) {
case TREE:
return 1;
case GRASS:
return 2;
case TENT:
return 3;
default:
return 0;
}
}

@Override
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleEle
TreeTentCell cell = (TreeTentCell) puzzleElement;
Point loc = cell.getLocation();

cellElement.setAttribute("value", String.valueOf(cell.getData()));
cellElement.setAttribute("value", String.valueOf(cell.getValue()));
cellElement.setAttribute("x", String.valueOf(loc.x));
cellElement.setAttribute("y", String.valueOf(loc.y));

Expand Down

0 comments on commit ca9fef9

Please sign in to comment.