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

Thermometer first rule and changes to ThermometerController #725

Merged
merged 1 commit into from
Feb 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,21 @@ public void changeCell(MouseEvent e, PuzzleElement data) {
if (e.isControlDown()) {
this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY());
} else {
if (cell.getData() == 0) {
data.setData(1);
} else if (cell.getData() == 1) {
data.setData(2);
} else if (cell.getData() == 2){
data.setData(0);
if (cell.getData() == ThermometerFill.EMPTY.ordinal()) {
data.setData(ThermometerFill.FILLED.ordinal());
} else if (cell.getData() == ThermometerFill.FILLED.ordinal()) {
data.setData(ThermometerFill.BLOCKED.ordinal());
} else {
data.setData(1);
data.setData(ThermometerFill.EMPTY.ordinal());
}
}
} else if (e.getButton() == MouseEvent.BUTTON3) {
if (cell.getData() == 1) {
data.setData(2);
} else if (cell.getData() == 2) {
data.setData(3);
} else if(cell.getData() == 3){
data.setData(1);
} else if (e.getButton() == MouseEvent.BUTTON2) {
if (cell.getData() == ThermometerFill.EMPTY.ordinal()) {
data.setData(ThermometerFill.BLOCKED.ordinal());
} else if (cell.getData() == ThermometerFill.BLOCKED.ordinal()) {
data.setData(ThermometerFill.FILLED.ordinal());
} else {
data.setData(1);
data.setData(ThermometerFill.EMPTY.ordinal());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package edu.rpi.legup.puzzle.thermometer;

public enum ThermometerFill{
UNKNOWN, FILLED, EMPTY, BLOCKED;
UNKNOWN, EMPTY, FILLED, BLOCKED;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package edu.rpi.legup.puzzle.thermometer.rules;

import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.CaseBoard;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.CaseRule;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.thermometer.*;

import java.util.ArrayList;
import java.util.List;

public class MercuryOrBlockedCaseRule extends CaseRule {
public MercuryOrBlockedCaseRule() {
super("MOB",
"Mercury or Blocked",
"Each unassigned tile must be filled with mercury or blocked.",
"edu/rpi/legup/images/thermometers/cases/MercuryOrBlocked.png");
}

@Override
public String checkRuleRaw(TreeTransition transition) {
List<TreeTransition> childTransitions = transition.getParents().get(0).getChildren();
if (childTransitions.size() != 2) {
return super.getInvalidUseOfRuleMessage() + ": This case rule must have 2 children.";
}

TreeTransition case1 = childTransitions.get(0);
TreeTransition case2 = childTransitions.get(1);
if (case1.getBoard().getModifiedData().size() != 1 ||
case2.getBoard().getModifiedData().size() != 1) {
return super.getInvalidUseOfRuleMessage() + ": This case rule must have 1 modified cell for each case.";
}

ThermometerCell mod1 = (ThermometerCell) case1.getBoard().getModifiedData().iterator().next();
ThermometerCell mod2 = (ThermometerCell) case2.getBoard().getModifiedData().iterator().next();
if (!mod1.getLocation().equals(mod2.getLocation())) {
return super.getInvalidUseOfRuleMessage() + ": This case rule must modify the same cell for each case.";
}

if (!((mod1.getFill() == ThermometerFill.BLOCKED && mod2.getFill() == ThermometerFill.FILLED) ||
(mod2.getFill() == ThermometerFill.BLOCKED && mod1.getFill() == ThermometerFill.FILLED))) {
return super.getInvalidUseOfRuleMessage() + ": This case rule must have a filled or blocked cell.";
}

return null;
}

@Override
public CaseBoard getCaseBoard(Board board) {
ThermometerBoard thermometerBoard = (ThermometerBoard) board.copy();
CaseBoard caseBoard = new CaseBoard(thermometerBoard, this);
thermometerBoard.setModifiable(false);
for (PuzzleElement element : thermometerBoard.getPuzzleElements()) {
if (((ThermometerCell) element).getFill() == ThermometerFill.UNKNOWN) {
caseBoard.addPickableElement(element);
}
}
return caseBoard;
}

@Override
public ArrayList<Board> getCases(Board board, PuzzleElement puzzleElement) {
ArrayList<Board> cases = new ArrayList<>();
Board case1 = board.copy();
PuzzleElement data1 = case1.getPuzzleElement(puzzleElement);
data1.setData(ThermometerType.HEAD);
case1.addModifiedData(data1);
cases.add(case1);

Board case2 = board.copy();
PuzzleElement data2 = case2.getPuzzleElement(puzzleElement);
data2.setData(ThermometerFill.BLOCKED);
case2.addModifiedData(data2);
cases.add(case2);

return cases;
}

@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
return null;
}
}
Loading