diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java index 4cd09b254..1919c7e94 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java @@ -198,40 +198,48 @@ public void printBoard() { } /** + * * @param x position of cell * @param y position of cell * @param e Element to be placed (null if nothing selected) - * @param m MouseEvent Increases clue values if in editor mode. Currently allows for presetting - * tile values, though they will not be saved. + * @param m MouseEvent + * Increases clue values if in editor mode. Currently allows for + * presetting tile values, though they will not be saved. */ @Override public void setCell(int x, int y, Element e, MouseEvent m) { SkyscrapersClue clue = this.getClue(x, y); if (e == null) return; if (clue != null) { - if (!e.getElementID().equals("SKYS-UNPL-0003")) { + if (!e.getElementID().equals("SKYS-UNPL-0003")) return; - } if (m.getButton() == MouseEvent.BUTTON1) { if (clue.getData() < dimension.height) { clue.setData(clue.getData() + 1); - } else { + } + else { clue.setData(0); } - } else { + } + else { if (clue.getData() > 0) { clue.setData(clue.getData() - 1); - } else { + } + else { clue.setData(dimension.height); } } } else { super.setCell(x - 1, y - 1, e, m); } + else { + super.setCell(x - 1, y - 1, e, m); + } } /** + * * @param x position of element on boardView * @param y position of element on boardView * @return The clue at the given position @@ -239,13 +247,16 @@ public void setCell(int x, int y, Element e, MouseEvent m) { public SkyscrapersClue getClue(int x, int y) { int viewIndex = getSize() + 1; if (x == 0 && y > 0 && y < viewIndex) { - return westClues.get(y - 1); - } else if (x == viewIndex && y > 0 && y < viewIndex) { - return eastClues.get(y - 1); - } else if (y == 0 && x > 0 && x < viewIndex) { - return northClues.get(x - 1); - } else if (y == viewIndex && x > 0 && x < viewIndex) { - return southClues.get(x - 1); + return westClues.get(y-1); + } + else if (x == viewIndex && y > 0 && y < viewIndex) { + return eastClues.get(y-1); + } + else if (y == 0 && x > 0 && x < viewIndex) { + return northClues.get(x-1); + } + else if (y == viewIndex && x > 0 && x < viewIndex) { + return southClues.get(x-1); } return null; } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java index 1cf9a357b..cbb6e8820 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java @@ -1,11 +1,13 @@ package edu.rpi.legup.puzzle.skyscrapers; -import static edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType.convertToSkyType; +import edu.rpi.legup.model.elements.Element; +import edu.rpi.legup.model.gameboard.GridCell; import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.GridCell; import java.awt.*; import java.awt.event.MouseEvent; +import static edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType.convertToSkyType; public class SkyscrapersCell extends GridCell { private int max; @@ -26,23 +28,25 @@ public SkyscrapersType getType() { @Override public void setType(Element e, MouseEvent m) { - switch (e.getElementID()) { + switch (e.getElementID()){ case "SKYS-UNPL-0001": this.data = 0; break; case "SKYS-UNPL-0002": - switch (m.getButton()) { + switch (m.getButton()){ case MouseEvent.BUTTON1: if (this.data <= 0 || this.data >= this.max) { this.data = 1; - } else { + } + else { this.data = this.data + 1; } break; case MouseEvent.BUTTON3: if (this.data > 1) { this.data = this.data - 1; - } else { + } + else { this.data = this.max; } break; diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java index 03572b816..7e2209658 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java @@ -22,8 +22,7 @@ public class SkyscrapersCellFactory extends ElementFactory { public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("cell")) { - throw new InvalidFileFormatException( - "Skyscrapers Factory: unknown puzzleElement puzzleElement"); + throw new InvalidFileFormatException("Skyscrapers Factory: unknown puzzleElement puzzleElement"); } SkyscrapersBoard skyscrapersBoard = (SkyscrapersBoard) board; @@ -34,8 +33,7 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat int x = Integer.valueOf(attributeList.getNamedItem("x").getNodeValue()); int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue()); if (x >= size || y >= size) { - throw new InvalidFileFormatException( - "Skyscrapers Factory: cell location out of bounds"); + throw new InvalidFileFormatException("Skyscrapers Factory: cell location out of bounds"); } if (value < 0 || value > size) { throw new InvalidFileFormatException("Skyscrapers Factory: cell unknown value"); @@ -45,12 +43,12 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat cell.setIndex(y * size + x); return cell; - } catch (NumberFormatException e) { - throw new InvalidFileFormatException( - "Skyscrapers Factory: unknown value where integer expected"); - } catch (NullPointerException e) { - throw new InvalidFileFormatException( - "Skyscrapers Factory: could not find attribute(s)"); + } + catch (NumberFormatException e) { + throw new InvalidFileFormatException("Skyscrapers Factory: unknown value where integer expected"); + } + catch (NullPointerException e) { + throw new InvalidFileFormatException("Skyscrapers Factory: could not find attribute(s)"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java index f78774e35..1002edd59 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java @@ -20,7 +20,11 @@ public void changeCell(MouseEvent e, PuzzleElement element) { } else { cell.setData(SkyscrapersType.UNKNOWN.toValue()); } - } else { + else { + cell.setData(SkyscrapersType.UNKNOWN.toValue()); + } + } + else { if (e.getButton() == MouseEvent.BUTTON3) { if (cell.getData() > 0) { int num = cell.getData() - 1; diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java index 75d2bd04f..b471b08cd 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.skyscrapers; import edu.rpi.legup.model.PuzzleExporter; -import edu.rpi.legup.model.gameboard.PuzzleElement; import org.w3c.dom.Document; public class SkyscrapersExporter extends PuzzleExporter { @@ -22,17 +21,6 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("size", String.valueOf(board.getWidth())); - org.w3c.dom.Element cellsElement = newDocument.createElement("cells"); - for (PuzzleElement puzzleElement : board.getPuzzleElements()) { - SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; - if (cell.getData() != 0) { - org.w3c.dom.Element cellElement = - puzzle.getFactory().exportCell(newDocument, puzzleElement); - cellsElement.appendChild(cellElement); - } - } - boardElement.appendChild(cellsElement); - org.w3c.dom.Element axisEast = newDocument.createElement("axis"); axisEast.setAttribute("side", "east"); for (int i = 0; i < board.getWidth(); i++) { @@ -56,12 +44,6 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { axisSouth.appendChild(clueElement); } boardElement.appendChild(axisSouth); - - org.w3c.dom.Element flagsElement = newDocument.createElement("flags"); - flagsElement.setAttribute("dupe", String.valueOf(board.getDupeFlag())); - flagsElement.setAttribute("view", String.valueOf(board.getViewFlag())); - boardElement.appendChild(flagsElement); - return boardElement; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java index 0fc7e6c39..37492a734 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java @@ -31,15 +31,12 @@ public boolean acceptsTextInput() { */ @Override public void initializeBoard(int rows, int columns) { - // assert(rows == columns); int size = rows; SkyscrapersBoard skyscrapersBoard = new SkyscrapersBoard(size); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { - SkyscrapersCell cell = - new SkyscrapersCell( - SkyscrapersType.UNKNOWN.toValue(), new Point(x, y), size); + SkyscrapersCell cell = new SkyscrapersCell(SkyscrapersType.UNKNOWN.toValue(), new Point(x, y), size); cell.setIndex(y * size + x); cell.setModifiable(true); skyscrapersBoard.setCell(x, y, cell); @@ -47,23 +44,14 @@ public void initializeBoard(int rows, int columns) { } for (int i = 0; i < size; i++) { - skyscrapersBoard - .getWestClues() - .set(/*index - 1*/ i, new SkyscrapersClue(0, i, SkyscrapersType.CLUE_WEST)); - skyscrapersBoard - .getEastClues() - .set(/*index - 1*/ i, new SkyscrapersClue(0, i, SkyscrapersType.CLUE_EAST)); + skyscrapersBoard.getWestClues().set(/*index - 1*/i, new SkyscrapersClue(0, i, SkyscrapersType.CLUE_WEST)); + skyscrapersBoard.getEastClues().set(/*index - 1*/i, new SkyscrapersClue(0, i, SkyscrapersType.CLUE_EAST)); } for (int i = 0; i < size; i++) { - skyscrapersBoard - .getNorthClues() - .set(/*index - 1*/ i, new SkyscrapersClue(0, i, SkyscrapersType.CLUE_NORTH)); - skyscrapersBoard - .getSouthClues() - .set(/*index - 1*/ i, new SkyscrapersClue(0, i, SkyscrapersType.CLUE_SOUTH)); + skyscrapersBoard.getNorthClues().set(/*index - 1*/i, new SkyscrapersClue(0, i, SkyscrapersType.CLUE_NORTH)); + skyscrapersBoard.getSouthClues().set(/*index - 1*/i, new SkyscrapersClue(0, i, SkyscrapersType.CLUE_SOUTH)); } - puzzle.setCurrentBoard(skyscrapersBoard); } @@ -100,22 +88,6 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0); NodeList elementDataList = dataElement.getElementsByTagName("cell"); - - int size = skyscrapersBoard.getSize(); - - for (int i = 0; i < elementDataList.getLength(); i++) { - SkyscrapersCell cell = - (SkyscrapersCell) - puzzle.getFactory() - .importCell(elementDataList.item(i), skyscrapersBoard); - Point loc = cell.getLocation(); - if (cell.getData() != 0) { - cell.setModifiable(false); - cell.setGiven(true); - } - skyscrapersBoard.setCell(loc.x, loc.y, cell); - } - for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { if (skyscrapersBoard.getCell(x, y) == null) { @@ -187,27 +159,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { int value = Integer.valueOf(clue.getAttribute("value")); int index = Integer.valueOf(clue.getAttribute("index")); - skyscrapersBoard - .getNorthClues() - .set( - /*index - 1*/ i, - new SkyscrapersClue(index, i, SkyscrapersType.CLUE_NORTH)); - skyscrapersBoard - .getSouthClues() - .set( - /*index - 1*/ i, - new SkyscrapersClue(value, i, SkyscrapersType.CLUE_SOUTH)); - } - NodeList flagList = boardElement.getElementsByTagName("flags"); - if (flagList.getLength() == 1) { - Element flags = (Element) flagList.item(0); - if (flags.hasAttribute("dupe")) { - skyscrapersBoard.setDupeFlag(Boolean.parseBoolean(flags.getAttribute("dupe"))); - } - if (flags.hasAttribute("view")) { - skyscrapersBoard.setViewFlag(Boolean.parseBoolean(flags.getAttribute("view"))); - } + skyscrapersBoard.getNorthClues().set(/*index - 1*/i, new SkyscrapersClue(index, i, SkyscrapersType.CLUE_NORTH)); + skyscrapersBoard.getSouthClues().set(/*index - 1*/i, new SkyscrapersClue(value, i, SkyscrapersType.CLUE_SOUTH)); } puzzle.setCurrentBoard(skyscrapersBoard); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersView.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersView.java index edd2cdbf5..9232cb463 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersView.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersView.java @@ -6,6 +6,8 @@ import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.ui.boardview.ElementView; import edu.rpi.legup.ui.boardview.GridBoardView; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.awt.*; import java.util.ArrayList; import org.apache.logging.log4j.LogManager; diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/ClueTile.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/ClueTile.java index 64c9033e6..8505de523 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/ClueTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/ClueTile.java @@ -5,10 +5,6 @@ public class ClueTile extends NonPlaceableElement { public ClueTile() { - super( - "SKYS-UNPL-0003", - "Clue Tile", - "Clue Updater", - "edu/rpi/legup/images/skyscrapers/tiles/ClueTile.png"); + super("SKYS-UNPL-0003", "Clue Tile", "Clue Updater", "edu/rpi/legup/images/skyscrapers/tiles/ClueTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/NumberTile.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/NumberTile.java index 4d6b37c9a..8f78fb1cf 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/NumberTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/NumberTile.java @@ -4,10 +4,6 @@ public class NumberTile extends NonPlaceableElement { public NumberTile() { - super( - "SKYS-UNPL-0002", - "Number Tile", - "A numbered tile", - "edu/rpi/legup/images/skyscrapers/tiles/ClueTile.png"); + super("SKYS-UNPL-0002", "Number Tile", "A numbered tile", "edu/rpi/legup/images/skyscrapers/tiles/ClueTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/UnknownTile.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/UnknownTile.java index 2fb21193a..3559dc332 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/UnknownTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/UnknownTile.java @@ -4,10 +4,6 @@ public class UnknownTile extends NonPlaceableElement { public UnknownTile() { - super( - "SKYS-UNPL-0001", - "Unknown", - "A blank tile", - "edu/rpi/legup/images/skyscrapers/tiles/UnknownTile.png"); + super("SKYS-UNPL-0001", "Unknown", "A blank tile", "edu/rpi/legup/images/skyscrapers/tiles/UnknownTile.png"); } }