Skip to content

Commit

Permalink
Merge branch 'battleship-refactor-classes' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Chase-Grajeda committed Jun 23, 2022
2 parents 9e52ea5 + 430db21 commit 43974fb
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 96 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ An example for the Battleship puzzle demonstrates the proper format for XML file

```
<edu.rpi.legup.Legup>
<edu.rpi.legup.puzzle qualifiedClassName="edu.rpi.legup.puzzle.battleship.BattleShip">
<edu.rpi.legup.puzzle qualifiedClassName="edu.rpi.legup.puzzle.battleship.Battleship">
<board size="10">
<puzzleElement>
<puzzleElement value="1" x="2" y="0"/>
Expand Down
2 changes: 1 addition & 1 deletion bin/main/edu/rpi/legup/legup/config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Legup version="2.0">
<puzzles>
<puzzle name="BattleShip" qualifiedClassName="edu.rpi.legup.puzzle.battleship.BattleShip" fileType=".xml"/>
<puzzle name="BattleShip" qualifiedClassName="edu.rpi.legup.puzzle.battleship.Battleship" fileType=".xml"/>
<puzzle name="Fillapix" qualifiedClassName="edu.rpi.legup.puzzle.fillapix.Fillapix" fileType=".xml"/>
<puzzle name="Heyawake" qualifiedClassName="edu.rpi.legup.puzzle.heyawake.Heyawake" fileType=".xml"/>
<puzzle name="LightUp" qualifiedClassName="edu.rpi.legup.puzzle.lightup.LightUp" fileType=".xml"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.ContradictionRule;

public class BattleShip extends Puzzle {
public BattleShip() {
public class Battleship extends Puzzle {
public Battleship() {
super();

this.name = "BattleShip";
this.name = "Battleship";

this.importer = new BattleShipImporter(this);
this.exporter = new BattleShipExporter(this);
this.importer = new BattleshipImporter(this);
this.exporter = new BattleshipExporter(this);

this.factory = new BattleShipCellFactory();
this.factory = new BattleshipCellFactory();
}

/**
* Initializes the game board. Called by the invoker of the class
*/
@Override
public void initializeView() {
boardView = new BattleShipView((BattleShipBoard) currentBoard);
boardView = new BattleshipView((BattleshipBoard) currentBoard);
addBoardListener(boardView);
}

Expand All @@ -39,16 +39,16 @@ public Board generatePuzzle(int difficulty) {
*/
@Override
public boolean isBoardComplete(Board board) {
BattleShipBoard battleShipBoard = (BattleShipBoard) board;
BattleshipBoard battleShipBoard = (BattleshipBoard) board;

for (ContradictionRule rule : contradictionRules) {
if (rule.checkContradiction(battleShipBoard) == null) {
return false;
}
}
for (PuzzleElement data : battleShipBoard.getPuzzleElements()) {
BattleShipCell cell = (BattleShipCell) data;
if (cell.getType() == BattleShipType.UNKNOWN) {
BattleshipCell cell = (BattleshipCell) data;
if (cell.getType() == BattleshipType.UNKNOWN) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,18 @@
import java.util.ArrayList;
import java.util.List;

public class BattleShipBoard extends GridBoard {
public class BattleshipBoard extends GridBoard {

/**
* The column of clues on the east side of the board.
*/
private List<BattleShipClue> east;

/**
* The column of clues on the south side of the board.
*/
private List<BattleShipClue> south;
private List<BattleshipClue> east;
private List<BattleshipClue> south;

/**
* Constructor for creating a rectangular battleship board.
*
* @param width width of the board
* @param height height of the board
*/
public BattleShipBoard(int width, int height) {
public BattleshipBoard(int width, int height) {
super(width, height);

this.east = new ArrayList<>();
Expand All @@ -45,38 +38,37 @@ public BattleShipBoard(int width, int height) {
*
* @param size size of the board
*/
public BattleShipBoard(int size) {
public BattleshipBoard(int size) {
this(size, size);
}

/**
* Gets the east {@link BattleShipClue}
* Gets the east {@link BattleshipClue}
*
* @return List of <code>BattleShipClue</code> objects on the east
* side of the board
*/
public List<BattleShipClue> getEast() {
public List<BattleshipClue> getEast() {
return east;
}

/**
* Gets the east {@link BattleShipClue}
* Gets the east {@link BattleshipClue}
*
* @return east battle ship clues
*/
public List<BattleShipClue> getSouth() {
public List<BattleshipClue> getSouth() {
return south;
}

@Override
public BattleShipCell getCell(int x, int y) {
return (BattleShipCell) super.getCell(x, y);
public BattleshipCell getCell(int x, int y) {
return (BattleshipCell) super.getCell(x, y);
}

@Override
public BattleShipBoard copy() {
BattleShipBoard copy = new BattleShipBoard(dimension.width,
dimension.height);
public BattleshipBoard copy() {
BattleshipBoard copy = new BattleshipBoard(dimension.width, dimension.height);
for (int x = 0; x < this.dimension.width; x++) {
for (int y = 0; y < this.dimension.height; y++) {
copy.setCell(x, y, getCell(x, y).copy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

import java.awt.*;

public class BattleShipCell extends GridCell<BattleShipType> {
public class BattleshipCell extends GridCell<BattleshipType> {

/**
* BattleShipCell Constructor - creates a BattleShipCell from the specified value and location
*
* @param value value of the BattleShipCell
* @param location position of the BattleShipCell
*/
public BattleShipCell(BattleShipType value, Point location) {
public BattleshipCell(BattleshipType value, Point location) {
super(value, location);
}

Expand All @@ -21,7 +21,7 @@ public BattleShipCell(BattleShipType value, Point location) {
*
* @return type of BattleShipCell
*/
public BattleShipType getType() {
public BattleshipType getType() {
return data;
}

Expand All @@ -30,8 +30,8 @@ public BattleShipType getType() {
*
* @return a new copy of the BattleShipCell that is independent of this one
*/
public BattleShipCell copy() {
BattleShipCell copy = new BattleShipCell(data, (Point) location.clone());
public BattleshipCell copy() {
BattleshipCell copy = new BattleshipCell(data, (Point) location.clone());
copy.setIndex(index);
copy.setModifiable(isModifiable);
copy.setGiven(isGiven);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@

import java.awt.event.MouseEvent;

public class BattleShipCellController extends ElementController {
public class BattleshipCellController extends ElementController {
@Override
public void changeCell(MouseEvent e, PuzzleElement data) {
BattleShipCell cell = (BattleShipCell) data;
BattleshipCell cell = (BattleshipCell) data;
if (e.getButton() == MouseEvent.BUTTON1) {
if (e.isControlDown()) {
this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY());
} else {
if (cell.getData() == BattleShipType.SHIP_SEGMENT_MIDDLE) {
cell.setData(BattleShipType.UNKNOWN);
if (cell.getData() == BattleshipType.SHIP_SEGMENT_MIDDLE) {
cell.setData(BattleshipType.UNKNOWN);
} else {
cell.setData(BattleShipType.getType(cell.getData().value + 1));
cell.setData(BattleshipType.getType(cell.getData().value + 1));
}
}
} else if (e.getButton() == MouseEvent.BUTTON3) {
if (cell.getData() == BattleShipType.UNKNOWN) {
cell.setData(BattleShipType.SHIP_SEGMENT_MIDDLE);
if (cell.getData() == BattleshipType.UNKNOWN) {
cell.setData(BattleshipType.SHIP_SEGMENT_MIDDLE);
} else {
cell.setData(BattleShipType.getType(cell.getData().value - 1));
cell.setData(BattleshipType.getType(cell.getData().value - 1));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import java.awt.*;

public class BattleShipCellFactory extends ElementFactory {
public class BattleshipCellFactory extends ElementFactory {
/**
* Creates a puzzleElement based on the xml document Node and adds it to the board
*
Expand All @@ -20,9 +20,9 @@ public class BattleShipCellFactory extends ElementFactory {
* @throws InvalidFileFormatException
*/
@Override
public PuzzleElement<BattleShipType> importCell(Node node, Board board) throws InvalidFileFormatException {
public PuzzleElement<BattleshipType> importCell(Node node, Board board) throws InvalidFileFormatException {
try {
BattleShipBoard battleShipBoard = (BattleShipBoard) board;
BattleshipBoard battleShipBoard = (BattleshipBoard) board;
int width = battleShipBoard.getWidth();
int height = battleShipBoard.getHeight();
NamedNodeMap attributeList = node.getAttributes();
Expand All @@ -38,7 +38,7 @@ public PuzzleElement<BattleShipType> importCell(Node node, Board board) throws I
throw new InvalidFileFormatException("BattleShip Factory: cell unknown value");
}

BattleShipCell cell = new BattleShipCell(BattleShipType.getType(value), new Point(x, y));
BattleshipCell cell = new BattleshipCell(BattleshipType.getType(value), new Point(x, y));
cell.setIndex(y * height + x);
return cell;
} else {
Expand All @@ -61,7 +61,7 @@ public PuzzleElement<BattleShipType> importCell(Node node, Board board) throws I
public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) {
org.w3c.dom.Element cellElement = document.createElement("cell");

BattleShipCell cell = (BattleShipCell) puzzleElement;
BattleshipCell cell = (BattleshipCell) puzzleElement;
Point loc = cell.getLocation();

cellElement.setAttribute("value", String.valueOf(cell.getData()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import edu.rpi.legup.model.gameboard.PuzzleElement;

public class BattleShipClue extends PuzzleElement {
public class BattleshipClue extends PuzzleElement {

private BattleShipType type;
private BattleshipType type;

public BattleShipClue(int value, int index, BattleShipType type) {
public BattleshipClue(int value, int index, BattleshipType type) {
super(value);
this.index = index;
this.type = type;
Expand Down Expand Up @@ -42,15 +42,15 @@ public Integer getData() {
return (Integer) super.getData();
}

public BattleShipType getType() {
public BattleshipType getType() {
return type;
}

public void setType(BattleShipType type) {
public void setType(BattleshipType type) {
this.type = type;
}

public BattleShipClue copy() {
public BattleshipClue copy() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import java.awt.*;

public class BattleShipClueView extends ElementView {
public class BattleshipClueView extends ElementView {

private static final Font FONT = new Font("TimesRoman", Font.BOLD, 16);
private static final Color FONT_COLOR = Color.BLACK;

public BattleShipClueView(BattleShipClue clue) {
public BattleshipClueView(BattleshipClue clue) {
super(clue);
}

Expand All @@ -19,8 +19,8 @@ public BattleShipClueView(BattleShipClue clue) {
* @return PuzzleElement associated with this view
*/
@Override
public BattleShipClue getPuzzleElement() {
return (BattleShipClue) super.getPuzzleElement();
public BattleshipClue getPuzzleElement() {
return (BattleshipClue) super.getPuzzleElement();
}

@Override
Expand All @@ -30,7 +30,7 @@ public void draw(Graphics2D graphics2D) {
FontMetrics metrics = graphics2D.getFontMetrics(FONT);
String value;

BattleShipClue clue = getPuzzleElement();
BattleshipClue clue = getPuzzleElement();
switch (clue.getType()) {
case CLUE_NORTH:
value = String.valueOf(clue.getData() + 1);
Expand All @@ -42,7 +42,7 @@ public void draw(Graphics2D graphics2D) {
value = String.valueOf(clue.getData());
break;
case CLUE_WEST:
value = BattleShipClue.colNumToString(clue.getData() + 1);
value = BattleshipClue.colNumToString(clue.getData() + 1);
break;
default:
value = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.awt.*;

public class BattleShipElementView extends GridElementView {
public class BattleshipElementView extends GridElementView {
private static final Stroke OUTLINE_STROKE = new BasicStroke(1);
private static final Color OUTLINE_COLOR = new Color(0x212121);

Expand All @@ -15,14 +15,14 @@ public class BattleShipElementView extends GridElementView {
private static final Font FONT = new Font("TimesRoman", Font.BOLD, 10);
private static final Color FONT_COLOR = new Color(0xFFEB3B);

public BattleShipElementView(BattleShipCell cell) {
public BattleshipElementView(BattleshipCell cell) {
super(cell);
}

@Override
public void drawElement(Graphics2D graphics2D) {
BattleShipCell cell = (BattleShipCell) puzzleElement;
BattleShipType type = cell.getType();
BattleshipCell cell = (BattleshipCell) puzzleElement;
BattleshipType type = cell.getType();

switch (type) {
case UNKNOWN:
Expand Down
Loading

0 comments on commit 43974fb

Please sign in to comment.