Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jadeandtea authored Sep 26, 2024
2 parents 4257dd0 + d76bab4 commit 315208a
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,54 +198,65 @@ 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
*/
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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Integer> {
private int max;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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)");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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++) {
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,27 @@ 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);
}
}

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);
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit 315208a

Please sign in to comment.