Skip to content

Commit

Permalink
Thermometer (#801)
Browse files Browse the repository at this point in the history
* Found bug in name of ThermometerTooLarge.png which was throwing errors and not showing up in LEGUP.

* Added documentation comments to rules

* Updated controller to have correct mouse buttons as well as added debug info with middle mouse. Cleaned up a few methods in TheremomterCell as well.

* Fixed ThermomterExporter to allow saving to write correctly to file.
  • Loading branch information
Fuzzabee authored Apr 12, 2024
1 parent cfd5a7f commit bf4dcaa
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,15 @@ public void setType(ThermometerType t){
}

public ThermometerType getType() {
return switch (type.ordinal()) {
case 0 -> ThermometerType.UNKNOWN;
case 1 -> ThermometerType.HEAD;
case 2 -> ThermometerType.SHAFT;
case 3 -> ThermometerType.TIP;
default -> null;
};
return type;
}

public void setFill(ThermometerFill f){
fill = f;
}

public ThermometerFill getFill() {
return switch (fill.ordinal()) {
case 0 -> ThermometerFill.UNKNOWN;
case 1 -> ThermometerFill.EMPTY;
case 2 -> ThermometerFill.FILLED;
case 3 -> ThermometerFill.BLOCKED;
default -> null;
};
return fill;
}

public void setRotation(int r) {rotation = r;}
Expand All @@ -56,4 +44,9 @@ public ThermometerCell copy() {
copy.setGiven(isGiven);
return copy;
}

@Override
public String toString() {
return "(" + location.getX() + ", " + location.getY() + ") TYPE = " + getType() + " FILL = " + getFill();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ThermometerController extends ElementController {
public void changeCell(MouseEvent e, PuzzleElement data) {
ThermometerCell cell = (ThermometerCell) data;

System.out.println("Sanity Check");
// System.out.println("Sanity Check");

if (e.getButton() == MouseEvent.BUTTON1) {
if (e.isControlDown()) {
Expand All @@ -29,7 +29,7 @@ else if (cell.getFill() == ThermometerFill.FILLED) {
}
}
}
else if (e.getButton() == MouseEvent.BUTTON2) {
else if (e.getButton() == MouseEvent.BUTTON3) {
if (cell.getFill() == ThermometerFill.EMPTY) {
cell.setFill(ThermometerFill.BLOCKED);
}
Expand All @@ -40,5 +40,8 @@ else if (cell.getFill() == ThermometerFill.BLOCKED) {
cell.setFill(ThermometerFill.EMPTY);
}
}
else if(e.getButton() == MouseEvent.BUTTON2) {
System.out.println("[DEBUG] " + cell);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,29 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {

// Creating the XML section for the board
org.w3c.dom.Element boardElement = newDocument.createElement("board");
boardElement.setAttribute("width", String.valueOf(board.getWidth()));
boardElement.setAttribute("height", String.valueOf(board.getHeight()));
boardElement.setAttribute("width", String.valueOf(board.getWidth() - 1));
boardElement.setAttribute("height", String.valueOf(board.getHeight() - 1));

// Creating the XML section for the vials and appending to the board
org.w3c.dom.Element vialsElement = newDocument.createElement("vials");
ArrayList<ThermometerVial> vials = board.getVials();
for (ThermometerVial vial : vials) {
org.w3c.dom.Element vialElement = newDocument.createElement("vial");
// Temp for now, waiting on final implementation of vial
// vialElement.setAttribute("headx", vial.getHeadX());
// vialElement.setAttribute("heady", vial.getHeadY());
// vialElement.setAttribute("tailx", vial.getTailX());
// vialElement.setAttribute("taily", vial.getTailY());
vialElement.setAttribute("headx", String.valueOf((int) vial.getHead().getLocation().getX()));
vialElement.setAttribute("heady", String.valueOf((int) vial.getHead().getLocation().getY()));
vialElement.setAttribute("tailx", String.valueOf((int) vial.getTail().getLocation().getX()));
vialElement.setAttribute("taily", String.valueOf((int) vial.getTail().getLocation().getY()));
vialsElement.appendChild(vialElement);
}
boardElement.appendChild(vialsElement);

// Creating the XML section for the row numbers and appending to the board
org.w3c.dom.Element rowNumbersElement = newDocument.createElement("rowNumbers");
//when time available change to expect arraylist of gridcells
ArrayList<Integer> rowNumbers = null; //board.getRowNumbers();
for (int number : rowNumbers) {
ArrayList<ThermometerCell> rowNumbers = board.getRowNumbers();
for (ThermometerCell cell : rowNumbers) {
int number = cell.getRotation();
org.w3c.dom.Element rowNumberElement = newDocument.createElement("row");
rowNumberElement.setAttribute("value", String.valueOf(number));
rowNumbersElement.appendChild(rowNumberElement);
Expand All @@ -49,8 +50,9 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
// Creating the XML section for the col numbers and appending ot the board
org.w3c.dom.Element colNumbersElement = newDocument.createElement("colNumbers");
//when time available change to expect arraylist of gridcells
ArrayList<Integer> colNumbers = null; //board.getColNumbers();
for (int number : colNumbers) {
ArrayList<ThermometerCell> colNumbers = board.getColNumbers();
for (ThermometerCell cell : colNumbers) {
int number = cell.getRotation();
org.w3c.dom.Element colNumberElement = newDocument.createElement("col");
colNumberElement.setAttribute("value", String.valueOf(number));
colNumbersElement.appendChild(colNumberElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public DiscontinuousMercuryContradictionRule() {
}


/**
* Checks whether the transition has a contradiction at the specific puzzleElement index using
* this rule
*
* @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
* otherwise error message
*/
//User can click on any cell in a vial with a discontinuous flow
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,25 @@ public FinishWithBlockedDirectRule() {
"edu/rpi/legup/images/thermometer/FinishWithBlocked.png");
}

/**
* Checks whether the child node logically follows from the parent node at the specific
* puzzleElement index using this rule
*
* @param transition transition to check
* @param puzzleElement equivalent puzzleElement
* @return null if the child node logically follow from the parent node at the specified
* puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {return null;}

/**
* Creates a transition {@link Board} that has this rule applied to it using the {@link
* TreeNode}.
*
* @param node tree node used to create default transition board
* @return default board or null if this rule cannot be applied to this tree node
*/
@Override
public Board getDefaultBoard(TreeNode node) {return null;}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,25 @@ public FinishWithMercuryDirectRule() {
"edu/rpi/legup/images/thermometer/FinishWithMercury.png");
}

/**
* Checks whether the child node logically follows from the parent node at the specific
* puzzleElement index using this rule
*
* @param transition transition to check
* @param puzzleElement equivalent puzzleElement
* @return null if the child node logically follow from the parent node at the specified
* puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {return null;}

/**
* Creates a transition {@link Board} that has this rule applied to it using the {@link
* TreeNode}.
*
* @param node tree node used to create default transition board
* @return default board or null if this rule cannot be applied to this tree node
*/
@Override
public Board getDefaultBoard(TreeNode node) {return null;}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public MercuryOrBlockedCaseRule() {
"edu/rpi/legup/images/thermometer/MercOrBlocked.png");
}

/**
* Checks whether the transition logically follows from the parent node using this rule
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
*/
@Override
public String checkRuleRaw(TreeTransition transition) {
List<TreeTransition> childTransitions = transition.getParents().get(0).getChildren();
Expand Down Expand Up @@ -46,11 +52,21 @@ public String checkRuleRaw(TreeTransition transition) {
return null;
}

/**
* Checks whether the child node logically follows from the parent node at the specific
* puzzleElement index using this rule
*
* @param transition transition to check
* @param puzzleElement equivalent puzzleElement
* @return null if the child node logically follow from the parent node at the specified
* puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
return null;
}


@Override
public CaseBoard getCaseBoard(Board board) {
ThermometerBoard thermometerBoard = (ThermometerBoard) board.copy();
Expand All @@ -64,6 +80,13 @@ public CaseBoard getCaseBoard(Board board) {
return caseBoard;
}

/**
* Gets the possible cases at a specific location based on this case rule
*
* @param board the current board state
* @param puzzleElement equivalent puzzleElement
* @return a list of elements the specified could be
*/
@Override
public ArrayList<Board> getCases(Board board, PuzzleElement puzzleElement) {
ArrayList<Board> cases = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,25 @@ public MinimumFillDirectRule() {
"edu/rpi/legup/images/thermometer/MinimumFill.png");
}

/**
* Checks whether the child node logically follows from the parent node at the specific
* puzzleElement index using this rule
*
* @param transition transition to check
* @param puzzleElement equivalent puzzleElement
* @return null if the child node logically follow from the parent node at the specified
* puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {return null;}

/**
* Creates a transition {@link Board} that has this rule applied to it using the {@link
* TreeNode}.
*
* @param node tree node used to create default transition board
* @return default board or null if this rule cannot be applied to this tree node
*/
@Override
public Board getDefaultBoard(TreeNode node) {return null;}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
return super.getInvalidUseOfRuleMessage() + "Something went wrong - 3";
}

/**
* Creates a transition {@link Board} that has this rule applied to it using the {@link
* TreeNode}.
*
* @param node tree node used to create default transition board
* @return default board or null if this rule cannot be applied to this tree node
*/
@Override
public Board getDefaultBoard(TreeNode node) {return null;}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,36 @@ public SatisfyMercuryCaseRule() {
"edu/rpi/legup/images/thermometer/SatisfyMercury.png");
}

/**
* Checks whether the transition logically follows from the parent node using this rule
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
*/
@Override
public String checkRuleRaw(TreeTransition transition) {return null;}

/**
* Checks whether the child node logically follows from the parent node at the specific
* puzzleElement index using this rule
*
* @param transition transition to check
* @param puzzleElement equivalent puzzleElement
* @return null if the child node logically follow from the parent node at the specified
* puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
return null;
}

/**
* Gets the possible cases at a specific location based on this case rule
*
* @param board the current board state
* @param puzzleElement equivalent puzzleElement
* @return a list of elements the specified could be
*/
@Override
public ArrayList<Board> getCases(Board board, PuzzleElement puzzleElement) {return null;}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,25 @@ public ThermometerTooLargeDirectRule() {
"edu/rpi/legup/images/thermometer/ThermometerTooLarge.png");
}

/**
* Checks whether the child node logically follows from the parent node at the specific
* puzzleElement index using this rule
*
* @param transition transition to check
* @param puzzleElement equivalent puzzleElement
* @return null if the child node logically follow from the parent node at the specified
* puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {return null;}

/**
* Creates a transition {@link Board} that has this rule applied to it using the {@link
* TreeNode}.
*
* @param node tree node used to create default transition board
* @return default board or null if this rule cannot be applied to this tree node
*/
@Override
public Board getDefaultBoard(TreeNode node) {return null;}
}

0 comments on commit bf4dcaa

Please sign in to comment.