From 9dd38190cc76064976a657288af3bec52d0aa438 Mon Sep 17 00:00:00 2001 From: Matthew Sweet <98288154+mattsweet417@users.noreply.github.com> Date: Tue, 19 Jul 2022 15:17:19 -0400 Subject: [PATCH] Nurikabe empty puzzles are now implemented --- .../java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java | 3 +-- .../rpi/legup/puzzle/nurikabe/NurikabeImporter.java | 10 ++++++++++ src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java index fbd0d3d88..ff585e493 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java @@ -46,8 +46,7 @@ public Board generatePuzzle(int difficulty) { * @return true if the given dimensions are valid for Nurikabe, false otherwise */ public boolean isValidDimensions(int rows, int columns) { - // This is a placeholder, this method needs to be implemented - throw new UnsupportedOperationException(); + return rows > 0 && columns > 0; } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java index f9dfb98f5..6a192789c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java @@ -22,7 +22,17 @@ public NurikabeImporter(Nurikabe nurikabe) { */ @Override public void initializeBoard(int rows, int columns) { + NurikabeBoard nurikabeBoard = new NurikabeBoard(columns, rows); + for (int y = 0; y < rows; y++) { + for (int x = 0; x < columns; x++) { + NurikabeCell cell = new NurikabeCell(NurikabeType.UNKNOWN.toValue(), new Point(x, y)); + cell.setIndex(y * columns + x); + cell.setModifiable(true); + nurikabeBoard.setCell(x, y, cell); + } + } + puzzle.setCurrentBoard(nurikabeBoard); } /** diff --git a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java index 92dd83df9..ad1d4f9dc 100644 --- a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java @@ -192,6 +192,7 @@ public void loadPuzzleFromHome(String game, int rows, int columns) throws Illega throw new IllegalArgumentException(exception.getMessage()); } catch (RuntimeException e){ + e.printStackTrace(); LOGGER.error(e.getMessage()); } }