forked from Bram-Hub/LEGUP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automated Java code formatting changes
- Loading branch information
Showing
22 changed files
with
883 additions
and
888 deletions.
There are no files selected for viewing
131 changes: 64 additions & 67 deletions
131
src/main/java/edu/rpi/legup/puzzle/minesweeper/Minesweeper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,64 @@ | ||
package edu.rpi.legup.puzzle.minesweeper; | ||
|
||
import edu.rpi.legup.model.Puzzle; | ||
import edu.rpi.legup.model.gameboard.Board; | ||
import edu.rpi.legup.model.gameboard.PuzzleElement; | ||
import edu.rpi.legup.model.rules.ContradictionRule; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class Minesweeper extends Puzzle { | ||
|
||
public static final String NAME = "Minesweeper"; | ||
|
||
public Minesweeper() { | ||
this.name = NAME; | ||
this.importer = new MinesweeperImporter(this); | ||
this.exporter = new MinesweeperExporter(this); | ||
this.factory = MinesweeperCellFactory.INSTANCE; | ||
} | ||
|
||
@Override | ||
@Contract(pure = false) | ||
public void initializeView() { | ||
this.boardView = new MinesweeperView((MinesweeperBoard) this.currentBoard); | ||
this.boardView.setBoard(this.currentBoard); | ||
addBoardListener(boardView); | ||
} | ||
|
||
@Override | ||
@Contract("_ -> null") | ||
public @Nullable Board generatePuzzle(int difficulty) { | ||
return null; | ||
} | ||
|
||
@Override | ||
@Contract(pure = true) | ||
public boolean isBoardComplete(@NotNull Board board) { | ||
MinesweeperBoard minesweeperBoard = (MinesweeperBoard) board; | ||
|
||
for (ContradictionRule rule : contradictionRules) { | ||
if (rule.checkContradiction(minesweeperBoard) == null) { | ||
return false; | ||
} | ||
} | ||
for (PuzzleElement<?> data : minesweeperBoard.getPuzzleElements()) { | ||
final MinesweeperCell cell = (MinesweeperCell) data; | ||
if (cell.getData().equals(MinesweeperTileData.empty())) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
@Contract(pure = true) | ||
public void onBoardChange(@NotNull Board board) { | ||
|
||
} | ||
|
||
@Override | ||
@Contract(pure = true) | ||
public boolean isValidDimensions(int rows, int columns) { | ||
return rows >= 1 && columns >= 1; | ||
} | ||
|
||
} | ||
package edu.rpi.legup.puzzle.minesweeper; | ||
|
||
import edu.rpi.legup.model.Puzzle; | ||
import edu.rpi.legup.model.gameboard.Board; | ||
import edu.rpi.legup.model.gameboard.PuzzleElement; | ||
import edu.rpi.legup.model.rules.ContradictionRule; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class Minesweeper extends Puzzle { | ||
|
||
public static final String NAME = "Minesweeper"; | ||
|
||
public Minesweeper() { | ||
this.name = NAME; | ||
this.importer = new MinesweeperImporter(this); | ||
this.exporter = new MinesweeperExporter(this); | ||
this.factory = MinesweeperCellFactory.INSTANCE; | ||
} | ||
|
||
@Override | ||
@Contract(pure = false) | ||
public void initializeView() { | ||
this.boardView = new MinesweeperView((MinesweeperBoard) this.currentBoard); | ||
this.boardView.setBoard(this.currentBoard); | ||
addBoardListener(boardView); | ||
} | ||
|
||
@Override | ||
@Contract("_ -> null") | ||
public @Nullable Board generatePuzzle(int difficulty) { | ||
return null; | ||
} | ||
|
||
@Override | ||
@Contract(pure = true) | ||
public boolean isBoardComplete(@NotNull Board board) { | ||
MinesweeperBoard minesweeperBoard = (MinesweeperBoard) board; | ||
|
||
for (ContradictionRule rule : contradictionRules) { | ||
if (rule.checkContradiction(minesweeperBoard) == null) { | ||
return false; | ||
} | ||
} | ||
for (PuzzleElement<?> data : minesweeperBoard.getPuzzleElements()) { | ||
final MinesweeperCell cell = (MinesweeperCell) data; | ||
if (cell.getData().equals(MinesweeperTileData.empty())) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
@Contract(pure = true) | ||
public void onBoardChange(@NotNull Board board) {} | ||
|
||
@Override | ||
@Contract(pure = true) | ||
public boolean isValidDimensions(int rows, int columns) { | ||
return rows >= 1 && columns >= 1; | ||
} | ||
} |
72 changes: 36 additions & 36 deletions
72
src/main/java/edu/rpi/legup/puzzle/minesweeper/MinesweeperBoard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
package edu.rpi.legup.puzzle.minesweeper; | ||
|
||
import edu.rpi.legup.model.gameboard.GridBoard; | ||
|
||
public class MinesweeperBoard extends GridBoard { | ||
|
||
public MinesweeperBoard(int width, int height) { | ||
super(width, height); | ||
} | ||
|
||
public MinesweeperBoard(int size) { | ||
super(size); | ||
} | ||
|
||
@Override | ||
public MinesweeperCell getCell(int x, int y) { | ||
return (MinesweeperCell) super.getCell(x, y); | ||
} | ||
|
||
|
||
/** | ||
* Performs a deep copy of the Board | ||
* | ||
* @return a new copy of the board that is independent of this one | ||
*/ | ||
@Override | ||
public MinesweeperBoard copy() { | ||
MinesweeperBoard newMinesweeperBoard = new MinesweeperBoard(this.dimension.width, this.dimension.height); | ||
for (int x = 0; x < this.dimension.width; x++) { | ||
for (int y = 0; y < this.dimension.height; y++) { | ||
newMinesweeperBoard.setCell(x, y, getCell(x, y).copy()); | ||
} | ||
} | ||
return newMinesweeperBoard; | ||
} | ||
} | ||
package edu.rpi.legup.puzzle.minesweeper; | ||
|
||
import edu.rpi.legup.model.gameboard.GridBoard; | ||
|
||
public class MinesweeperBoard extends GridBoard { | ||
|
||
public MinesweeperBoard(int width, int height) { | ||
super(width, height); | ||
} | ||
|
||
public MinesweeperBoard(int size) { | ||
super(size); | ||
} | ||
|
||
@Override | ||
public MinesweeperCell getCell(int x, int y) { | ||
return (MinesweeperCell) super.getCell(x, y); | ||
} | ||
|
||
/** | ||
* Performs a deep copy of the Board | ||
* | ||
* @return a new copy of the board that is independent of this one | ||
*/ | ||
@Override | ||
public MinesweeperBoard copy() { | ||
MinesweeperBoard newMinesweeperBoard = | ||
new MinesweeperBoard(this.dimension.width, this.dimension.height); | ||
for (int x = 0; x < this.dimension.width; x++) { | ||
for (int y = 0; y < this.dimension.height; y++) { | ||
newMinesweeperBoard.setCell(x, y, getCell(x, y).copy()); | ||
} | ||
} | ||
return newMinesweeperBoard; | ||
} | ||
} |
149 changes: 73 additions & 76 deletions
149
src/main/java/edu/rpi/legup/puzzle/minesweeper/MinesweeperCell.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,73 @@ | ||
package edu.rpi.legup.puzzle.minesweeper; | ||
|
||
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; | ||
|
||
public class MinesweeperCell extends GridCell<MinesweeperTileData> { | ||
|
||
public MinesweeperCell(@NotNull MinesweeperTileData value, @NotNull Point location) { | ||
super(value, location); | ||
} | ||
|
||
public @NotNull MinesweeperTileType getTileType() { | ||
return super.data.type(); | ||
} | ||
|
||
public @NotNull int getTileNumber() { | ||
return super.data.data(); | ||
} | ||
|
||
@Override | ||
@Contract(pure = false) | ||
/** | ||
* Sets this cell's data to the value specified by {@link Element#getElementID()} | ||
*/ | ||
public void setType(@NotNull Element element, @NotNull MouseEvent event) { | ||
switch (element.getElementID()) { | ||
case MinesweeperElementIdentifiers.BOMB -> { | ||
this.data = MinesweeperTileData.bomb(); | ||
break; | ||
} | ||
case MinesweeperElementIdentifiers.FLAG -> { | ||
final int currentData = super.data.data(); | ||
switch (event.getButton()) { | ||
case MouseEvent.BUTTON1 -> { | ||
if (currentData >= 8) { | ||
this.data = MinesweeperTileData.empty(); | ||
return; | ||
} | ||
this.data = MinesweeperTileData.flag(currentData + 1); | ||
return; | ||
} | ||
case MouseEvent.BUTTON2, MouseEvent.BUTTON3 -> { | ||
if (currentData <= 0) { | ||
this.data = MinesweeperTileData.empty(); | ||
return; | ||
} | ||
this.data = MinesweeperTileData.flag(currentData - 1); | ||
return; | ||
} | ||
} | ||
} | ||
default -> { | ||
this.data = MinesweeperTileData.empty(); | ||
} | ||
} | ||
} | ||
|
||
public void setCellType(MinesweeperTileData type){ | ||
this.data = type; | ||
} | ||
|
||
@Override | ||
@Contract(pure = true) | ||
public @NotNull MinesweeperCell copy() { | ||
MinesweeperCell copy = new MinesweeperCell(data, (Point) location.clone()); | ||
copy.setIndex(index); | ||
copy.setModifiable(isModifiable); | ||
copy.setGiven(isGiven); | ||
return copy; | ||
} | ||
} | ||
package edu.rpi.legup.puzzle.minesweeper; | ||
|
||
import edu.rpi.legup.model.elements.Element; | ||
import edu.rpi.legup.model.gameboard.GridCell; | ||
import java.awt.*; | ||
import java.awt.event.MouseEvent; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class MinesweeperCell extends GridCell<MinesweeperTileData> { | ||
|
||
public MinesweeperCell(@NotNull MinesweeperTileData value, @NotNull Point location) { | ||
super(value, location); | ||
} | ||
|
||
public @NotNull MinesweeperTileType getTileType() { | ||
return super.data.type(); | ||
} | ||
|
||
public @NotNull int getTileNumber() { | ||
return super.data.data(); | ||
} | ||
|
||
@Override | ||
@Contract(pure = false) | ||
/** Sets this cell's data to the value specified by {@link Element#getElementID()} */ | ||
public void setType(@NotNull Element element, @NotNull MouseEvent event) { | ||
switch (element.getElementID()) { | ||
case MinesweeperElementIdentifiers.BOMB -> { | ||
this.data = MinesweeperTileData.bomb(); | ||
break; | ||
} | ||
case MinesweeperElementIdentifiers.FLAG -> { | ||
final int currentData = super.data.data(); | ||
switch (event.getButton()) { | ||
case MouseEvent.BUTTON1 -> { | ||
if (currentData >= 8) { | ||
this.data = MinesweeperTileData.empty(); | ||
return; | ||
} | ||
this.data = MinesweeperTileData.flag(currentData + 1); | ||
return; | ||
} | ||
case MouseEvent.BUTTON2, MouseEvent.BUTTON3 -> { | ||
if (currentData <= 0) { | ||
this.data = MinesweeperTileData.empty(); | ||
return; | ||
} | ||
this.data = MinesweeperTileData.flag(currentData - 1); | ||
return; | ||
} | ||
} | ||
} | ||
default -> { | ||
this.data = MinesweeperTileData.empty(); | ||
} | ||
} | ||
} | ||
|
||
public void setCellType(MinesweeperTileData type) { | ||
this.data = type; | ||
} | ||
|
||
@Override | ||
@Contract(pure = true) | ||
public @NotNull MinesweeperCell copy() { | ||
MinesweeperCell copy = new MinesweeperCell(data, (Point) location.clone()); | ||
copy.setIndex(index); | ||
copy.setModifiable(isModifiable); | ||
copy.setGiven(isGiven); | ||
return copy; | ||
} | ||
} |
Oops, something went wrong.