Skip to content

Commit

Permalink
Merge branch 'dev' into native-binary-windows
Browse files Browse the repository at this point in the history
  • Loading branch information
charlestian23 authored Aug 17, 2022
2 parents d90782d + 86c64c4 commit f31f5ab
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public BattleshipCell getCell(int x, int y) {
}

@Override
/**
* Creates a copy of the current board
*
* @return the copy of the board
*/
public BattleshipBoard copy() {
BattleshipBoard copy = new BattleshipBoard(dimension.width, dimension.height);
for (int x = 0; x < this.dimension.width; x++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
import java.awt.event.MouseEvent;

public class BattleshipCellController extends ElementController {
/**
* Controller class for the Battleship puzzle -
* receives user mouse input and changes what's shown on the GUI
* @param data the PuzzleElement to be changed
* @param e the user mouse input
*/
@Override
public void changeCell(MouseEvent e, PuzzleElement data) {
BattleshipCell cell = (BattleshipCell) data;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipClue.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public BattleshipClue(int value, int index, BattleshipType type) {
this.type = type;
}

/**
* Returns the column number as a string
* @param col the column number that is to be converted and returned
* @return int value
*/
public static String colNumToString(int col) {
final StringBuilder sb = new StringBuilder();
col--;
Expand All @@ -23,6 +28,11 @@ public static String colNumToString(int col) {
return sb.reverse().toString();
}

/**
* Returns the column string as an integer
* @param col the column number as a string that is to be converted and returned
* @return string value
*/
public static int colStringToColNum(String col) {
int result = 0;
for (int i = 0; i < col.length(); i++) {
Expand All @@ -42,10 +52,18 @@ public Integer getData() {
return (Integer) super.getData();
}

/**
* Returns the type of the battleship object (ship or clue)
* @return BattleshipType type
*/
public BattleshipType getType() {
return type;
}

/**
* Sets the type of the battleship object (ship or clue) to the given type
* @param type given Battleship type
*/
public void setType(BattleshipType type) {
this.type = type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public BattleshipClue getPuzzleElement() {
}

@Override
/**
* Draws the clue from the PuzzleElement associated with this view on the given frame
* @param graphics2D the frame the clue is to be drawn on
*/
public void draw(Graphics2D graphics2D) {
graphics2D.setColor(FONT_COLOR);
graphics2D.setFont(FONT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public BattleshipElementView(BattleshipCell cell) {
}

@Override
/**
* Draws on the given frame based on the type of the cell of the current puzzleElement
* @param graphics2D the frame to be drawn on
*/
public void drawElement(Graphics2D graphics2D) {
BattleshipCell cell = (BattleshipCell) puzzleElement;
BattleshipType type = cell.getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public BattleshipExporter(Battleship battleShip) {
super(battleShip);
}

/**
* Creates and returns a new board element in the XML document specified
* @param newDocument the XML document to append to
* @return the new board element
*/
@Override
protected org.w3c.dom.Element createBoardElement(Document newDocument) {
BattleshipBoard board = (BattleshipBoard) puzzle.getTree().getRootNode().getBoard();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.awt.*;

public class BattleshipView extends GridBoardView {

public BattleshipView(BattleshipBoard board) {
super(new BoardController(), new BattleshipCellController(), board.getDimension());

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/lightup/LightUpBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public LightUpBoard(int size) {
super(size, size);
}

/**
* Sets cells in board to lite depending on whether there is a bulb cell in the current row or column
*/
public void fillWithLight() {
for (int y = 0; y < this.dimension.height; y++) {
for (int x = 0; x < this.dimension.width; x++) {
Expand Down Expand Up @@ -61,6 +64,11 @@ public void fillWithLight() {
}
}

/**
* Gets adjancent cells to the specified cell
* @param cell LightUpCell
* @return Set of adjacent LightUpCells
*/
public Set<LightUpCell> getAdj(LightUpCell cell) {
Set<LightUpCell> adjCells = new HashSet<>();
cell = (LightUpCell) getPuzzleElement(cell);
Expand All @@ -85,6 +93,12 @@ public Set<LightUpCell> getAdj(LightUpCell cell) {
return adjCells;
}

/**
* Gets the number of adjacent cells of the specified type
* @param cell base cell
* @param type specified type
* @return the number of adjacent cells
*/
public int getNumAdj(LightUpCell cell, LightUpCellType type) {
int num = 0;
Set<LightUpCell> adjCells = getAdj(cell);
Expand All @@ -96,6 +110,11 @@ public int getNumAdj(LightUpCell cell, LightUpCellType type) {
return num;
}

/**
* Gets the number of adjacent cells
* @param cell LightUpCell
* @return number of adjacent cells
*/
public int getNumAdjLite(LightUpCell cell) {
int num = 0;
Set<LightUpCell> adjCells = getAdj(cell);
Expand All @@ -107,6 +126,11 @@ public int getNumAdjLite(LightUpCell cell) {
return num;
}

/**
* Gets the number of adjacent cells that are placable
* @param cell specified cell
* @return number of adjacent cells that are placable
*/
public int getNumPlacble(LightUpCell cell) {
int num = 0;
Set<LightUpCell> adjCells = getAdj(cell);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/lightup/LightUpView.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public void onTreeElementChanged(TreeElement treeElement) {
repaint();
}

/**
* Returns a DataSelectionView popup menu
*/
public DataSelectionView getSelectionPopupMenu() {
DataSelectionView selectionView = new DataSelectionView(elementController);
GridLayout layout = new GridLayout(3, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be a bulb";
}

/**
* Determines whether the specified cell is forced to be a bulb or not
* @param board the entire board
* @param cell specified cell
* @return whether cell is forced to be a bulb or not
*/
private boolean isForced(LightUpBoard board, LightUpCell cell) {
Set<LightUpCell> adjCells = board.getAdj(cell);
adjCells.removeIf(c -> c.getType() != LightUpCellType.NUMBER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,25 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
return super.getInvalidUseOfRuleMessage() + ": Empty is not forced";
}

/**
* Checks whether a certain cell is forced to not be a bulb
* @param board specified board
* @param location location of cell to check
* @return boolean value based on whether a certain cell has an adjacent cell that has the required amount of adjacent bulbs
*/
private boolean isForced(LightUpBoard board, Point location) {
return isForcedEmpty(board, new Point(location.x + 1, location.y)) ||
isForcedEmpty(board, new Point(location.x, location.y + 1)) ||
isForcedEmpty(board, new Point(location.x - 1, location.y)) ||
isForcedEmpty(board, new Point(location.x, location.y - 1));
}

/**
* Checks whether a certain cell has the required amount of adjacent bulbs
* @param board specified board
* @param loc location of cell to check
* @return boolean value based on whether a certain cell has the required amount of adjacent bulbs
*/
private boolean isForcedEmpty(LightUpBoard board, Point loc) {
LightUpCell cell = board.getCell(loc.x, loc.y);
if (cell == null || cell.getType() != LightUpCellType.NUMBER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
return null;
}

/**
* Gets all cells in the TreeTransition board that are adjacent to all modified cells
* @param transition TreeTransition object
* @return list of cells that are adjacent to all modified cells, returns null if the number of modified cells is =0 || >4
*/
private List<LightUpCell> getPossibleSpots(TreeTransition transition) {
LightUpBoard board = (LightUpBoard) transition.getBoard();
Set<PuzzleElement> modCells = transition.getBoard().getModifiedData();
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ public List<TreeTentCell> getAdjacent(TreeTentCell cell, TreeTentType type) {
return adj;
}

/**
* Gets all cells of a specified type that are diagonals of a specified cell
* @param cell the base cell
* @param type the type to look for
* @return a list of TreeTentCells that are diagonals of the given TreeTentCell and are of the given TreeTentType
*/
public List<TreeTentCell> getDiagonals(TreeTentCell cell, TreeTentType type) {
List<TreeTentCell> dia = new ArrayList<>();
Point loc = cell.getLocation();
Expand All @@ -165,6 +171,13 @@ public List<TreeTentCell> getDiagonals(TreeTentCell cell, TreeTentType type) {
return dia;
}

/**
* Creates and returns a list of TreeTentCells that match the given TreeTentType
* @param index the row or column number
* @param type type of TreeTent element
* @param isRow boolean value beased on whether a row of column is being checked
* @return List of TreeTentCells that match the given TreeTentType
*/
public List<TreeTentCell> getRowCol(int index, TreeTentType type, boolean isRow) {
List<TreeTentCell> list = new ArrayList<>();
if (isRow) {
Expand Down Expand Up @@ -209,6 +222,10 @@ public boolean equalsBoard(Board board) {
return super.equalsBoard(treeTentBoard);
}

/**
* Performs a deep copy of the TreeTentBoard
* @return a TreeTentBoard object that is a deep copy of the current TreeTentBoard
*/
@Override
public TreeTentBoard copy() {
TreeTentBoard copy = new TreeTentBoard(dimension.width, dimension.height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public TreeTentElementView(TreeTentCell cell) {
super(cell);
}

/**
* Draws on the given frame based on the type of the cell of the current puzzleElement
* @param graphics2D the frame to be drawn on
*/
@Override
public void drawElement(Graphics2D graphics2D) {
TreeTentCell cell = (TreeTentCell) puzzleElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public TreeTentExporter(TreeTent treeTent) {
super(treeTent);
}

/**
* Creates and returns a new board element in the XML document specified
* @param newDocument the XML document to append to
* @return the new board element
*/
@Override
protected org.w3c.dom.Element createBoardElement(Document newDocument) {
TreeTentBoard board;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
}
}

/**
* Returns a boolean value based on whether the specified cell has adjacent cells (true - no adjacent, false - has adjacent)
* @param board the TreeTent board
* @param cell the specified TreeTent cell
* @return true - no adjacent, false - has adjacent
*/
private boolean isForced(TreeTentBoard board, TreeTentCell cell) {
List<TreeTentCell> adjCells = board.getAdjacent(cell, TreeTentType.TREE);
return adjCells.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public FillinRowCaseRule() {
"edu/rpi/legup/images/treetent/case_rowcount.png");
}

/**
* Gets the case board that indicates where this case rule can be applied on the given Board.
* @param board the given board
* @return the case board object
*/
@Override
public CaseBoard getCaseBoard(Board board) {
TreeTentBoard treeTentBoard = (TreeTentBoard) board.copy();
Expand Down

0 comments on commit f31f5ab

Please sign in to comment.