Skip to content

Commit

Permalink
Added Jetbrains notation to StarBattle
Browse files Browse the repository at this point in the history
  • Loading branch information
TreeSnowFence committed Jul 26, 2024
1 parent 5f52703 commit 4ddaaaf
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 19 deletions.
9 changes: 7 additions & 2 deletions src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.ContradictionRule;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class Nurikabe extends Puzzle {
public Nurikabe() {
Expand All @@ -20,6 +21,7 @@ public Nurikabe() {

/** Initializes the game board. Called by the invoker of the class */
@Override
@Contract(pure = false)
public void initializeView() {
boardView = new NurikabeView((NurikabeBoard) currentBoard);
boardView.setBoard(currentBoard);
Expand All @@ -33,6 +35,7 @@ public void initializeView() {
* @return board of the random edu.rpi.legup.puzzle
*/
@Override
@Contract("_ -> null")
public Board generatePuzzle(int difficulty) {
return null;
}
Expand All @@ -57,7 +60,8 @@ public boolean isValidDimensions(int rows, int columns) {
* @return true if board is valid, false otherwise
*/
@Override
public boolean isBoardComplete(Board board) {
@Contract(pure = true)
public boolean isBoardComplete(@NotNull Board board) {
NurikabeBoard nurikabeBoard = (NurikabeBoard) board;

for (ContradictionRule rule : contradictionRules) {
Expand All @@ -80,5 +84,6 @@ public boolean isBoardComplete(Board board) {
* @param board the board that has changed
*/
@Override
public void onBoardChange(Board board) {}
@Contract(pure = true)
public void onBoardChange(@NotNull Board board) {}
}
5 changes: 3 additions & 2 deletions src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.awt.*;
import java.awt.event.MouseEvent;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class NurikabeCell extends GridCell<Integer> {

Expand All @@ -14,7 +15,7 @@ public class NurikabeCell extends GridCell<Integer> {
* @param value value of the NurikabeCell
* @param location position of the NurikabeCell
*/
public NurikabeCell(int value, Point location) {
public NurikabeCell(int value, @NotNull Point location) {
super(value, location);
}

Expand Down Expand Up @@ -45,7 +46,7 @@ public NurikabeType getType() {
* @param e element to set the type of this nurikabe cell to
*/
@Override
public void setType(Element e, MouseEvent m) {
public void setType(@NotNull Element e, @NotNull MouseEvent m) {
switch (e.getElementID()) {
case "NURI-PLAC-0001":
this.data = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.gameboard.Board;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class StarBattle extends Puzzle {
public StarBattle() {
Expand All @@ -15,12 +17,14 @@ public StarBattle() {
}

@Override
@Contract(pure = false)
public void initializeView() {
boardView = new StarBattleView((StarBattleBoard) currentBoard);
addBoardListener(boardView);
}

@Override
@Contract("_ -> null")
public Board generatePuzzle(int difficulty) {
return null;
}
Expand All @@ -31,5 +35,6 @@ public boolean isBoardComplete(Board board) {
}

@Override
public void onBoardChange(Board board) {}
@Contract(pure = true)
public void onBoardChange(@NotNull Board board) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import edu.rpi.legup.model.elements.Element;
import edu.rpi.legup.model.gameboard.GridCell;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.awt.event.MouseEvent;

Expand All @@ -17,7 +20,7 @@ public class StarBattleCell extends GridCell<Integer> {
* @param groupIndex indicates what group # the cell is in.
* @param size size of the star battle cell
*/
public StarBattleCell(int value, Point location, int groupIndex, int size) {
public StarBattleCell(int value, @NotNull Point location, int groupIndex, int size) {
super(value, location);
this.groupIndex = groupIndex;
this.max = size;
Expand All @@ -28,7 +31,7 @@ public int getGroupIndex() {
}

@Override
public void setType(Element e, MouseEvent m) {
public void setType(@NotNull Element e, @NotNull MouseEvent m) {
switch (e.getElementID()) {
case "STBL-PLAC-0001":
this.data = -3;
Expand Down Expand Up @@ -77,6 +80,7 @@ public StarBattleCellType getType() {
return null;
}

@Contract(pure = true)
public StarBattleCell copy() {
StarBattleCell copy = new StarBattleCell(data, (Point) location.clone(), groupIndex, max);
copy.setIndex(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class StarBattleCellFactory extends ElementFactory {
@Override
public StarBattleCell importCell(Node node, Board board) throws InvalidFileFormatException {
@Contract(pure = false)
public StarBattleCell importCell(@NotNull Node node, @NotNull Board board) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("cell")) {
throw new InvalidFileFormatException(
Expand Down Expand Up @@ -50,8 +53,8 @@ public StarBattleCell importCell(Node node, Board board) throws InvalidFileForma
throw new InvalidFileFormatException("starbattle Factory: could not find attribute(s)");
}
}

public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) {
@Contract(pure = false)
public org.w3c.dom.Element exportCell(@NotNull Document document, @NotNull PuzzleElement puzzleElement) {
org.w3c.dom.Element cellElement = document.createElement("cell");

StarBattleCell cell = (StarBattleCell) puzzleElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import edu.rpi.legup.controller.ElementController;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.awt.event.MouseEvent;

public class StarBattleController extends ElementController {
@Override
public void changeCell(MouseEvent e, PuzzleElement data) {
@Contract(pure = false)
public void changeCell(@NotNull MouseEvent e, @NotNull PuzzleElement data) {
StarBattleCell cell = (StarBattleCell) data;
if (e.getButton() == MouseEvent.BUTTON1) {
if (e.isControlDown()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

import edu.rpi.legup.ui.boardview.GridElementView;
import java.awt.*;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class StarBattleElementView extends GridElementView {

public StarBattleElementView(StarBattleCell cell) {
public StarBattleElementView(@NotNull StarBattleCell cell) {
super(cell);
}

@Override
public StarBattleCell getPuzzleElement() {
public @NotNull StarBattleCell getPuzzleElement() {
return (StarBattleCell) super.getPuzzleElement();
}

@Override
public void drawElement(Graphics2D graphics2D) {
@Contract(pure = true)
public void drawElement(@NotNull Graphics2D graphics2D) {
StarBattleCell cell = (StarBattleCell) puzzleElement;
StarBattleCellType type = cell.getType();
if (type == StarBattleCellType.STAR) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import edu.rpi.legup.model.PuzzleExporter;
import org.w3c.dom.Document;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class StarBattleExporter extends PuzzleExporter {
public StarBattleExporter(StarBattle starbattle) {
public StarBattleExporter(@NotNull StarBattle starbattle) {
super(starbattle);
}

@Override
protected org.w3c.dom.Element createBoardElement(Document newDocument) {
@Contract(pure = true)
protected @NotNull org.w3c.dom.Element createBoardElement(@NotNull Document newDocument) {
StarBattleBoard board = (StarBattleBoard) puzzle.getTree().getRootNode().getBoard();
org.w3c.dom.Element boardElement = newDocument.createElement("board");
boardElement.setAttribute("size", String.valueOf(board.getSize()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class StarBattleImporter extends PuzzleImporter {

public StarBattleImporter(StarBattle starbattle) {
public StarBattleImporter(@NotNull StarBattle starbattle) {
super(starbattle);
}

/** Puzzle setting to support row and column inputs */
@Override
@Contract(pure = true, value = "-> true")
public boolean acceptsRowsAndColumnsInput() {
return true;
}

/** Puzzle setting to disable support for text input */
@Override
@Contract(pure = true, value = "-> false")
public boolean acceptsTextInput() {
return false;
}
Expand All @@ -44,6 +48,7 @@ public void initializeBoard(int rows, int columns) {
* @throws InvalidFileFormatException if file is invalid
*/
@Override
@Contract(pure = false)
public void initializeBoard(Node node) throws InvalidFileFormatException {
Element puzzleElement = (Element) node;
int puzzle_num = Integer.parseInt(puzzleElement.getAttribute("puzzle_num"));
Expand Down Expand Up @@ -92,7 +97,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
* @throws UnsupportedOperationException since StarBattle does not support text input
*/
@Override
public void initializeBoard(String[] statements) throws UnsupportedOperationException {
@Contract(value = "_ -> fail", pure = false)
public void initializeBoard(@NotNull String[] statements) throws UnsupportedOperationException {
throw new UnsupportedOperationException("Star Battle does not accept text input");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.awt.*;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.jetbrains.annotations.NotNull;

public class StarBattleView extends GridBoardView {
static Image STAR;
Expand All @@ -21,7 +22,7 @@ public class StarBattleView extends GridBoardView {
}
}

public StarBattleView(StarBattleBoard board) {
public StarBattleView(@NotNull StarBattleBoard board) {
super(new BoardController(), new StarBattleController(), board.getDimension());

for (PuzzleElement puzzleElement : board.getPuzzleElements()) {
Expand Down

0 comments on commit 4ddaaaf

Please sign in to comment.