Skip to content

Commit

Permalink
Merge branch 'dev' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
charlestian23 authored Dec 13, 2023
2 parents ec7b4a7 + a16ae5a commit 33ffd6a
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 80 deletions.
152 changes: 76 additions & 76 deletions src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,83 +29,83 @@ public TreeTentController() {
this.lastCellPressed = null;
}

// @Override
// public void mousePressed(MouseEvent e) {
// if (e.getButton() != MouseEvent.BUTTON2) {
// BoardView boardView = getInstance().getLegupUI().getBoardView();
// dragStart = boardView.getElement(e.getPoint());
// lastCellPressed = boardView.getElement(e.getPoint());
// }
// }
@Override
public void mousePressed(MouseEvent e) {
if (e.getButton() != MouseEvent.BUTTON2) {
BoardView boardView = getInstance().getLegupUI().getBoardView();
dragStart = boardView.getElement(e.getPoint());
lastCellPressed = boardView.getElement(e.getPoint());
}
}

@Override
public void mouseReleased(MouseEvent e) {
if (GameBoardFacade.getInstance().getLegupUI().getTreePanel() != null && e.getButton() != MouseEvent.BUTTON2) {
TreePanel treePanel = GameBoardFacade.getInstance().getLegupUI().getTreePanel();
TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView();
BoardView boardView = getInstance().getLegupUI().getBoardView();
lastCellPressed = boardView.getElement(e.getPoint());
Board board = boardView.getBoard();
TreeViewSelection selection = treeView.getSelection();

// @Override
// public void mouseReleased(MouseEvent e) {
// if (GameBoardFacade.getInstance().getLegupUI().getTreePanel() != null && e.getButton() != MouseEvent.BUTTON2) {
// TreePanel treePanel = GameBoardFacade.getInstance().getLegupUI().getTreePanel();
// TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView();
// BoardView boardView = getInstance().getLegupUI().getBoardView();
// lastCellPressed = boardView.getElement(e.getPoint());
// Board board = boardView.getBoard();
// TreeViewSelection selection = treeView.getSelection();
//
// if (dragStart != null) {
// if (board instanceof CaseBoard) {
// CaseBoard caseBoard = (CaseBoard) board;
// AutoCaseRuleCommand autoCaseRuleCommand = new AutoCaseRuleCommand(dragStart, selection, caseBoard.getCaseRule(), caseBoard, e);
// if (autoCaseRuleCommand.canExecute()) {
// autoCaseRuleCommand.execute();
// getInstance().getHistory().pushChange(autoCaseRuleCommand);
// treePanel.updateError("");
// }
// else {
// treePanel.updateError(autoCaseRuleCommand.getError());
// }
// }
// else {
// if (dragStart == lastCellPressed) {
// if (dragStart.getPuzzleElement().getIndex() >= 0) {
// ICommand edit = new EditDataCommand(lastCellPressed, selection, e);
// if (edit.canExecute()) {
// edit.execute();
// getInstance().getHistory().pushChange(edit);
// treePanel.updateError("");
// }
// else {
// treePanel.updateError(edit.getError());
// }
// }
// else {
// ClueCommand edit = new ClueCommand(selection, (TreeTentClueView) dragStart);
// if (edit.canExecute()) {
// edit.execute();
// getInstance().getHistory().pushChange(edit);
// treePanel.updateError("");
// }
// else {
// treePanel.updateError(edit.getError());
// }
// }
// }
// else {
// if (lastCellPressed != null) {
// if (dragStart instanceof TreeTentElementView) {
// ICommand editLine = new EditLineCommand(selection, (TreeTentElementView) dragStart, lastCellPressed);
// if (editLine.canExecute()) {
// editLine.execute();
// getInstance().getHistory().pushChange(editLine);
// }
// else {
// treePanel.updateError(editLine.getError());
// }
// }
// }
// }
// }
// }
// dragStart = null;
// lastCellPressed = null;
// }
// }
if (dragStart != null) {
if (board instanceof CaseBoard) {
CaseBoard caseBoard = (CaseBoard) board;
AutoCaseRuleCommand autoCaseRuleCommand = new AutoCaseRuleCommand(dragStart, selection, caseBoard.getCaseRule(), caseBoard, e);
if (autoCaseRuleCommand.canExecute()) {
autoCaseRuleCommand.execute();
getInstance().getHistory().pushChange(autoCaseRuleCommand);
treePanel.updateError("");
}
else {
treePanel.updateError(autoCaseRuleCommand.getError());
}
}
else {
if (dragStart == lastCellPressed) {
if (dragStart.getPuzzleElement().getIndex() >= 0) {
ICommand edit = new EditDataCommand(lastCellPressed, selection, e);
if (edit.canExecute()) {
edit.execute();
getInstance().getHistory().pushChange(edit);
treePanel.updateError("");
}
else {
treePanel.updateError(edit.getError());
}
}
else {
ClueCommand edit = new ClueCommand(selection, (TreeTentClueView) dragStart);
if (edit.canExecute()) {
edit.execute();
getInstance().getHistory().pushChange(edit);
treePanel.updateError("");
}
else {
treePanel.updateError(edit.getError());
}
}
}
else {
if (lastCellPressed != null) {
if (dragStart instanceof TreeTentElementView) {
ICommand editLine = new EditLineCommand(selection, (TreeTentElementView) dragStart, lastCellPressed);
if (editLine.canExecute()) {
editLine.execute();
getInstance().getHistory().pushChange(editLine);
}
else {
treePanel.updateError(editLine.getError());
}
}
}
}
}
}
dragStart = null;
lastCellPressed = null;
}
}

@Override
public void changeCell(MouseEvent e, PuzzleElement element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,33 @@ public void EmptyCellinLightDirectRule() throws InvalidFileFormatException{
cell7.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell7);

LightUpCell cell8 = board.getCell(3,0);
cell8.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell8);

LightUpCell cell9 = board.getCell(3,2);
cell9.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell9);

LightUpCell cell10 = board.getCell(2,3);
cell10.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell10);

LightUpCell cell11 = board.getCell(0,3);
cell11.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell11);

//confirm there is a logical following of the EmptyCellinLight rule
Assert.assertNull(RULE.checkRule(transition));

//cells (0,0) and (2,2) are not empty because they have lightbulbs, and (1,1)
//because it is a black tile. Confirm the rest are empty
//cells (0,0) and (2,2) are not empty because they have lightbulbs, (1,1)
//because it is a black tile, and (1,3),(3,1),(3,3) because they are not lit. Confirm the rest are empty
LightUpCell c;
for (int i = 0; i < board.getHeight(); i++) {
for (int j = 0; j < board.getWidth(); j++) {
c = board.getCell(j, i);
if ((i == 0 && j == 0) || (i == 2 && j == 2) || (i == 1 && j == 1)){
if ((i == 0 && j == 0) || (i == 2 && j == 2) || (i == 1 && j == 1) || (i == 1 && j == 3) || (i == 3 && j == 1)
|| (i==3 && j==3)){
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Legup>
<puzzle name="LightUp">
<board width="3" height="3">
<board width="4" height="4">
<cells>
<cell value="0" x="1" y="1"/>
<cell value="-4" x="0" y="0"/>
Expand Down

0 comments on commit 33ffd6a

Please sign in to comment.