Skip to content

Commit

Permalink
Merge pull request #831 from zachbonagura/binary
Browse files Browse the repository at this point in the history
Binary
  • Loading branch information
zacharybonagura authored Jun 28, 2024
2 parents 1ab5eb2 + dfadd67 commit cb6ad78
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 92 deletions.
67 changes: 35 additions & 32 deletions src/main/java/edu/rpi/legup/app/GameBoardFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,44 +175,47 @@ public boolean validateTextInput(String game, String[] statements) throws Runtim
* @param columns the number of columns on the board
*/
public void loadPuzzle(String game, int rows, int columns) throws RuntimeException {
String qualifiedClassName = config.getPuzzleClassForName(game);
LOGGER.debug("Loading " + qualifiedClassName);
if (!game.equals("")) {
String qualifiedClassName = config.getPuzzleClassForName(game);
LOGGER.debug("Loading " + qualifiedClassName);

try {
Class<?> c = Class.forName(qualifiedClassName);
Constructor<?> cons = c.getConstructor();
Puzzle puzzle = (Puzzle) cons.newInstance();
try {
Class<?> c = Class.forName(qualifiedClassName);
Constructor<?> cons = c.getConstructor();
Puzzle puzzle = (Puzzle) cons.newInstance();

PuzzleImporter importer = puzzle.getImporter();
if (importer == null) {
LOGGER.error("Puzzle importer is null");
throw new RuntimeException("Puzzle importer null");
}
PuzzleImporter importer = puzzle.getImporter();
if (importer == null) {
LOGGER.error("Puzzle importer is null");
throw new RuntimeException("Puzzle importer null");
}

// Theoretically, this exception should never be thrown, since LEGUP should not be
// allowing the user to give row/column input for a puzzle that doesn't support it
if (!importer.acceptsRowsAndColumnsInput()) {
throw new IllegalArgumentException(
puzzle.getName() + " does not accept rows and columns input");
}
// Theoretically, this exception should never be thrown, since LEGUP should not be
// allowing the user to give row/column input for a puzzle that doesn't support it
if (!importer.acceptsRowsAndColumnsInput()) {
throw new IllegalArgumentException(
puzzle.getName() + " does not accept rows and columns input");
}

setWindowTitle(puzzle.getName(), "New " + puzzle.getName() + " Puzzle");
importer.initializePuzzle(rows, columns);
setWindowTitle(puzzle.getName(), "New " + puzzle.getName() + " Puzzle");
importer.initializePuzzle(rows, columns);

puzzle.initializeView();
//
// puzzle.getBoardView().onTreeElementChanged(puzzle.getTree().getRootNode());
setPuzzleEditor(puzzle);
} catch (IllegalArgumentException exception) {
throw new IllegalArgumentException(exception.getMessage());
} catch (ClassNotFoundException
| NoSuchMethodException
| InvocationTargetException
| IllegalAccessException
| InstantiationException e) {
LOGGER.error(e);
throw new RuntimeException("Puzzle creation error");
puzzle.initializeView();
//
// puzzle.getBoardView().onTreeElementChanged(puzzle.getTree().getRootNode());
setPuzzleEditor(puzzle);
} catch (IllegalArgumentException exception) {
throw new IllegalArgumentException(exception.getMessage());
} catch (ClassNotFoundException
| NoSuchMethodException
| InvocationTargetException
| IllegalAccessException
| InstantiationException e) {
LOGGER.error(e);
throw new RuntimeException("Puzzle creation error");
}
}

}

public void loadPuzzle(String game, String[] statements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class EliminateTheImpossibleDirectRule extends DirectRule {

public EliminateTheImpossibleDirectRule() {
super(
"BINA-BASC-0003",
"BINA-BASC-0004",
"Eliminate The Impossible",
"If three adjacent empty cells are open, prevents a trio of numbers to exist",
"edu/rpi/legup/images/binary/rules/OneTileGapDirectRule.png");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
BINA-BASC-0001 : SurroundPairDirectRule
BINA-BASC-0002 : OneTileGapDirectRule
BINA-BASC-0003 : CompleteRowColumnDirectRule
BINA-BASC-0004 : EliminateTheImpossibleDirectRule

BINA-CONT-0001 : ThreeAdjacentContradictionRule
BINA-CONT-0002 : UnbalancedRowOrColumnContradictionRule
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/rpi/legup/puzzle/lightup/LightUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Board generatePuzzle(int difficulty) {
* @return true if the given dimensions are valid for Light Up, false otherwise
*/
public boolean isValidDimensions(int rows, int columns) {
return rows > 0 && columns > 0;
return rows >= 0 && columns >= 0;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/edu/rpi/legup/ui/CreatePuzzleDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public void actionPerformed(ActionEvent ae) {
Config.convertDisplayNameToClassName(
(String) gameBox.getSelectedItem());

if (game.equals("OpeningPuzzleEditor")) {

}
// Check if all 3 TextFields are filled
if (game.equals("ShortTruthTable") && textArea.getText().isEmpty()) {
System.out.println("Unfilled fields");
Expand Down
67 changes: 48 additions & 19 deletions src/main/java/edu/rpi/legup/ui/HomePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,25 @@ private void initButtons() {
this.buttons[0].setVerticalTextPosition(AbstractButton.BOTTOM);
this.buttons[0].addActionListener(CursorController.createListener(this, openProofListener));

// this.buttons[1] =
// new JButton("Create Puzzle") {
// {
// setSize(buttonSize, buttonSize);
// setMaximumSize(getSize());
// }
// };
// URL button1IconLocation =
// ClassLoader.getSystemClassLoader()
// .getResource("edu/rpi/legup/images/Legup/homepanel/new_puzzle_file.png");
// ImageIcon button1Icon = new ImageIcon(button1IconLocation);
// this.buttons[1].setFocusPainted(false);
// this.buttons[1].setIcon(resizeButtonIcon(button1Icon, this.buttonSize, this.buttonSize));
// this.buttons[1].setHorizontalTextPosition(AbstractButton.CENTER);
// this.buttons[1].setVerticalTextPosition(AbstractButton.BOTTOM);
// this.buttons[1].addActionListener(l -> this.openNewPuzzleDialog());

this.buttons[1] =
new JButton("Create Puzzle") {
new JButton("Puzzle Editor") {
{
setSize(buttonSize, buttonSize);
setMaximumSize(getSize());
Expand All @@ -151,7 +168,8 @@ private void initButtons() {
this.buttons[1].setIcon(resizeButtonIcon(button1Icon, this.buttonSize, this.buttonSize));
this.buttons[1].setHorizontalTextPosition(AbstractButton.CENTER);
this.buttons[1].setVerticalTextPosition(AbstractButton.BOTTOM);
this.buttons[1].addActionListener(l -> this.openNewPuzzleDialog());
this.buttons[1].addActionListener(l -> this.openPuzzleEditorDialog());
//this.buttons[1].addActionListener(l -> this.openNewPuzzleDialog());

this.buttons[2] =
new JButton("Edit Existing Puzzle") {
Expand Down Expand Up @@ -534,6 +552,10 @@ private void openNewPuzzleDialog() {
cpd.setVisible(true);
}

private void openPuzzleEditorDialog() {
PuzzleEditorDialog ped = new PuzzleEditorDialog(this);
}

private void checkProofAll() {
/*
* Select dir to grade; recursively grade sub-dirs using traverseDir()
Expand Down Expand Up @@ -631,27 +653,34 @@ private void traverseDir(File folder, BufferedWriter writer, String path) throws

public void openEditorWithNewPuzzle(String game, int rows, int columns)
throws IllegalArgumentException {
// Validate the dimensions
GameBoardFacade facade = GameBoardFacade.getInstance();
boolean isValidDimensions = facade.validateDimensions(game, rows, columns);
if (!isValidDimensions) {
JOptionPane.showMessageDialog(
null,
"The dimensions you entered are invalid. Please double check \n"
+ "the number of rows and columns and try again.",
"ERROR: Invalid Dimensions",
JOptionPane.ERROR_MESSAGE);
throw new IllegalArgumentException("ERROR: Invalid dimensions given");
if (game.equals("")) {
this.legupUI.displayPanel(2);
this.legupUI.getPuzzleEditor().loadPuzzleFromHome(game, rows, columns);
}
else {
// Validate the dimensions
GameBoardFacade facade = GameBoardFacade.getInstance();
boolean isValidDimensions = facade.validateDimensions(game, rows, columns);
if (!isValidDimensions) {
JOptionPane.showMessageDialog(
null,
"The dimensions you entered are invalid. Please double check \n"
+ "the number of rows and columns and try again.",
"ERROR: Invalid Dimensions",
JOptionPane.ERROR_MESSAGE);
throw new IllegalArgumentException("ERROR: Invalid dimensions given");
}

if (this.legupUI == null) {
System.err.println("Error: legupUI is null in HomePanel");
return;
if (this.legupUI == null) {
System.err.println("Error: legupUI is null in HomePanel");
return;
}

// Set game type on the puzzle editor
this.legupUI.displayPanel(2);
this.legupUI.getPuzzleEditor().loadPuzzleFromHome(game, rows, columns);
}

// Set game type on the puzzle editor
this.legupUI.displayPanel(2);
this.legupUI.getPuzzleEditor().loadPuzzleFromHome(game, rows, columns);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/edu/rpi/legup/ui/PuzzleEditorDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package edu.rpi.legup.ui;

import javax.swing.*;

public class PuzzleEditorDialog {

public PuzzleEditorDialog(HomePanel homePanel) {
String game = "";
int r = 0;
int c = 0;

try {
homePanel.openEditorWithNewPuzzle(game, r, c);
} catch (IllegalArgumentException e) {
System.out.println("Failed to open editor with new puzzle");
e.printStackTrace(System.out);
}
}

}
Loading

0 comments on commit cb6ad78

Please sign in to comment.