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 treetent puzzle editor #692

Merged
merged 4 commits into from
Dec 1, 2023
Merged
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
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
Loading