Skip to content

Commit

Permalink
Automated Java code formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram28 committed Apr 16, 2024
1 parent fe7f2f8 commit e258634
Show file tree
Hide file tree
Showing 90 changed files with 976 additions and 820 deletions.
16 changes: 9 additions & 7 deletions src/main/java/edu/rpi/legup/model/gameboard/GridRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
import java.util.List;

public abstract class GridRegion<T> {

protected List<T> regionCells;

/**
* Region Constructor
*/

/** Region Constructor */
public GridRegion() {
this.regionCells = new ArrayList<>();
}

/**
* Adds the cell to the region
*
* @param cell cell to be added to the region
*/
public void addCell(T cell) {
Expand All @@ -24,6 +23,7 @@ public void addCell(T cell) {

/**
* Removes the cell from the region
*
* @param cell cell to be remove from the region
*/
public void removeCell(T cell) {
Expand All @@ -32,6 +32,7 @@ public void removeCell(T cell) {

/**
* Returns the list of cells in the region
*
* @return list of cells in region
*/
public List<T> getCells() {
Expand All @@ -40,14 +41,15 @@ public List<T> getCells() {

/**
* Returns the number of cells in the region
*
* @return number of cells in the region
*/
public int getSize(){
public int getSize() {
return regionCells.size();
}

/*
public void colorRegion(){}
*/

}
4 changes: 2 additions & 2 deletions src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattle.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package edu.rpi.legup.puzzle.starbattle;

import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.gameboard.Board;

Expand Down Expand Up @@ -30,6 +31,5 @@ public boolean isBoardComplete(Board board) {
}

@Override
public void onBoardChange(Board board) {
}
public void onBoardChange(Board board) {}
}
20 changes: 10 additions & 10 deletions src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBoard.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package edu.rpi.legup.puzzle.starbattle;

import java.util.*;

import edu.rpi.legup.model.gameboard.GridBoard;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import java.util.*;

public class StarBattleBoard extends GridBoard {

private int size;
private int puzzleNum;
protected List<StarBattleRegion> regions;
//private ArrayList<Integer> groupSizes;

// private ArrayList<Integer> groupSizes;

public StarBattleBoard(int size, int num) {
super(size, size);
Expand All @@ -24,10 +24,10 @@ public StarBattleBoard(int size, int num) {

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

/*
/*
public StarBattleCell getCell(int groupIndex, int x, int y) {
return getCell(x + (groupIndex % groupSize) * groupSize, y + (groupIndex / groupSize) * groupSize);
}*/
Expand All @@ -44,7 +44,9 @@ public Set<StarBattleCell> getRow(int rowNum) {
return row;
}

public int getPuzzleNumber() { return puzzleNum; }
public int getPuzzleNumber() {
return puzzleNum;
}

public Set<StarBattleCell> getCol(int colNum) {
Set<StarBattleCell> column = new HashSet<>();
Expand Down Expand Up @@ -72,7 +74,7 @@ public void setRegion(int regionNum, StarBattleRegion region) {
public int columnStars(int columnIndex) {
int stars = 0;
if (columnIndex < size) {
for (StarBattleCell c: this.getCol(columnIndex)) {
for (StarBattleCell c : this.getCol(columnIndex)) {
if (c.getType() == StarBattleCellType.STAR) {
++stars;
}
Expand All @@ -84,7 +86,7 @@ public int columnStars(int columnIndex) {
public int rowStars(int rowIndex) {
int stars = 0;
if (rowIndex < size) {
for (StarBattleCell c: this.getRow(rowIndex)) {
for (StarBattleCell c : this.getRow(rowIndex)) {
if (c.getType() == StarBattleCellType.STAR) {
++stars;
}
Expand All @@ -109,5 +111,3 @@ public StarBattleBoard copy() {
return copy;
}
}


29 changes: 14 additions & 15 deletions src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import edu.rpi.legup.model.elements.Element;
import edu.rpi.legup.model.gameboard.GridCell;

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

Expand All @@ -13,18 +12,20 @@ public class StarBattleCell extends GridCell<Integer> {
/**
* StarBattleCell Constructor - creates a new StarBattle cell to hold the puzzleElement
*
* @param value value of the star battle cell denoting its state
* @param location location of the cell on the board
* @param value value of the star battle cell denoting its state
* @param location location of the cell on the board
* @param groupIndex indicates what group # the cell is in.
* @param size size of the star battle cell
* @param size size of the star battle cell
*/
public StarBattleCell(int value, Point location, int groupIndex, int size) {
super(value, location);
this.groupIndex = groupIndex;
this.max = size;
}

public int getGroupIndex() { return groupIndex; }
public int getGroupIndex() {
return groupIndex;
}

@Override
public void setType(Element e, MouseEvent m) {
Expand All @@ -38,27 +39,25 @@ public void setType(Element e, MouseEvent m) {
case "STBL-PLAC-0003":
this.data = -1;
break;
case "STBL-UNPL-0001"://Not sure how button events work
switch (m.getButton()){

case "STBL-UNPL-0001": // Not sure how button events work
switch (m.getButton()) {
case MouseEvent.BUTTON1:
if (this.data > 0 || this.data < -3) {
this.data = -3;
}
else {
} else {
this.data = this.data + 1;
}
break;
case MouseEvent.BUTTON3:
if (this.data > -4) {
this.data = this.data - 1;
}
else {
this.data = -1;//Unsure
} else {
this.data = -1; // Unsure
}
break;
}
break;
break;
}
}

Expand All @@ -85,4 +84,4 @@ public StarBattleCell copy() {
copy.setGiven(isGiven);
return copy;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package edu.rpi.legup.puzzle.starbattle;

import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.ElementFactory;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.save.InvalidFileFormatException;
import java.awt.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

import java.awt.*;

public class StarBattleCellFactory extends ElementFactory {
@Override
public StarBattleCell importCell(Node node, Board board) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("cell")) {
throw new InvalidFileFormatException("starbattle Factory: unknown puzzleElement puzzleElement");
throw new InvalidFileFormatException(
"starbattle Factory: unknown puzzleElement puzzleElement");
}

StarBattleBoard starbattleBoard = (StarBattleBoard) board;
Expand All @@ -24,28 +25,27 @@ public StarBattleCell importCell(Node node, Board board) throws InvalidFileForma
int value = Integer.valueOf(attributeList.getNamedItem("value").getNodeValue());
int x = Integer.valueOf(attributeList.getNamedItem("x").getNodeValue());
int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue());
int groupIndex = Integer.valueOf(attributeList.getNamedItem("groupIndex").getNodeValue());
int groupIndex =
Integer.valueOf(attributeList.getNamedItem("groupIndex").getNodeValue());
if (x >= size || y >= size) {
throw new InvalidFileFormatException("starbattle Factory: cell location out of bounds");
throw new InvalidFileFormatException(
"starbattle Factory: cell location out of bounds");
}
if (groupIndex >= size || groupIndex < 0) {
throw new InvalidFileFormatException("starbattle Factory: not in a valid region");
}
if (value != 0) { //ALL INITIAL PUZZLES ARE BLANK, SUBJECT TO CHANGE
if (value != 0) { // ALL INITIAL PUZZLES ARE BLANK, SUBJECT TO CHANGE
throw new InvalidFileFormatException("starbattle Factory: cell unknown value");
}

StarBattleCell cell = new StarBattleCell(value, new Point(x, y), groupIndex, size);
cell.setIndex(y * size + x);
return cell;
}

catch (NumberFormatException e1) {
} catch (NumberFormatException e1) {
e1.printStackTrace();
throw new InvalidFileFormatException("starbattle Factory: unknown value where integer expected");
}

catch (NullPointerException e2) {
throw new InvalidFileFormatException(
"starbattle Factory: unknown value where integer expected");
} catch (NullPointerException e2) {
e2.printStackTrace();
throw new InvalidFileFormatException("starbattle Factory: could not find attribute(s)");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//StarBattleCellType.java
// StarBattleCellType.java
package edu.rpi.legup.puzzle.starbattle;

public enum StarBattleCellType {
STAR(-2), BLACK(-1), UNKNOWN(0);
STAR(-2),
BLACK(-1),
UNKNOWN(0);

public int value;
public int value;

StarBattleCellType(int value) {
this.value = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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

import java.awt.event.MouseEvent;

public class StarBattleController extends ElementController {
Expand All @@ -11,23 +10,24 @@ public void changeCell(MouseEvent e, PuzzleElement data) {
StarBattleCell cell = (StarBattleCell) 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 {
this.boardView
.getSelectionPopupMenu()
.show(
boardView,
this.boardView.getCanvas().getX() + e.getX(),
this.boardView.getCanvas().getY() + e.getY());
} else {
if (cell.getData() >= 0) {
data.setData(-2);
}
else {
} else {
data.setData(cell.getData() + 1);
}
}
}
else {
} else {
if (e.getButton() == MouseEvent.BUTTON3) {
if (cell.getData() == -2) {
data.setData(0);
}
else {
} else {
data.setData(cell.getData() - 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.rpi.legup.puzzle.starbattle;

import edu.rpi.legup.ui.boardview.GridElementView;

import java.awt.*;

public class StarBattleElementView extends GridElementView {
Expand All @@ -22,7 +21,14 @@ public void drawElement(Graphics2D graphics2D) {
if (type == StarBattleCellType.STAR) {
graphics2D.setColor(Color.LIGHT_GRAY);
graphics2D.fillRect(location.x, location.y, size.width, size.height);
graphics2D.drawImage(StarBattleView.STAR, location.x, location.y, size.width, size.height, Color.WHITE, null);
graphics2D.drawImage(
StarBattleView.STAR,
location.x,
location.y,
size.width,
size.height,
Color.WHITE,
null);
graphics2D.setColor(Color.BLACK);
graphics2D.drawRect(location.x, location.y, size.width, size.height);
} else if (type == StarBattleCellType.BLACK) {
Expand All @@ -36,6 +42,5 @@ public void drawElement(Graphics2D graphics2D) {
graphics2D.setColor(Color.BLACK);
graphics2D.drawRect(location.x, location.y, size.width, size.height);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.rpi.legup.puzzle.starbattle;

import edu.rpi.legup.model.PuzzleExporter;

import org.w3c.dom.Document;

public class StarBattleExporter extends PuzzleExporter {
Expand All @@ -20,14 +19,15 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
org.w3c.dom.Element cellsElement = newDocument.createElement("cells");
for (StarBattleCell cell : sb_region.getCells()) {
if (cell.getData() == 0) {
org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, cell);
org.w3c.dom.Element cellElement =
puzzle.getFactory().exportCell(newDocument, cell);
cellsElement.appendChild(cellElement);
}
regionsElement.appendChild(cellsElement);
}
boardElement.appendChild(regionsElement);
}

return boardElement;
}
}
Loading

0 comments on commit e258634

Please sign in to comment.