playablegit add .

This commit is contained in:
LunarAkai 2024-03-22 21:18:34 +01:00
commit c164d1b6cd
6 changed files with 133 additions and 101 deletions

View file

@ -22,9 +22,7 @@ import com.google.common.base.Preconditions;
import de.lunarakai.minecleaner.game.BoardSize; import de.lunarakai.minecleaner.game.BoardSize;
import de.lunarakai.minecleaner.game.Cell; import de.lunarakai.minecleaner.game.Cell;
import de.lunarakai.minecleaner.game.Game; import de.lunarakai.minecleaner.game.Game;
import de.lunarakai.minecleaner.game.Tile.TileType;
import de.lunarakai.minecleaner.utils.MinecleanerHeads; import de.lunarakai.minecleaner.utils.MinecleanerHeads;
import net.md_5.bungee.api.ChatColor;
public class MinecleanerArena { public class MinecleanerArena {
private final MinecleanerPlugin plugin; private final MinecleanerPlugin plugin;
@ -34,8 +32,7 @@ public class MinecleanerArena {
private int widthIndex = 0; private int widthIndex = 0;
private final BlockFace orientation; private final BlockFace orientation;
private ArenaStatus arenaStatus = ArenaStatus.INACTIVE; private ArenaStatus arenaStatus = ArenaStatus.INACTIVE;
private UUID[] blockDisplays = new UUID[81]; // todo needs to be of size boardSizes[widthIndex] private UUID[] blockDisplays;
private TileType[] currentMinecleaerTileTypesState;
private Player currentPlayer; private Player currentPlayer;
private long currentGameStartTime; private long currentGameStartTime;
@ -62,7 +59,7 @@ public class MinecleanerArena {
this.name = Preconditions.checkNotNull(arenaSection.getString("name")); this.name = Preconditions.checkNotNull(arenaSection.getString("name"));
this.location = Preconditions.checkNotNull(arenaSection.getLocation("location")); this.location = Preconditions.checkNotNull(arenaSection.getLocation("location"));
this.widthIndex = Preconditions.checkNotNull(arenaSection.getInt("fieldwidth")); this.widthIndex = Preconditions.checkNotNull(arenaSection.getInt("fieldwidth"));
this.blockDisplays = new UUID[BoardSize.boardSizes[widthIndex] * BoardSize.boardSizes[widthIndex]];
BlockFace orientation = BlockFace.NORTH; BlockFace orientation = BlockFace.NORTH;
try { try {
@ -88,6 +85,7 @@ public class MinecleanerArena {
this.name = Preconditions.checkNotNull(name, "name"); this.name = Preconditions.checkNotNull(name, "name");
this.location = Preconditions.checkNotNull(location, "location"); this.location = Preconditions.checkNotNull(location, "location");
this.widthIndex = Preconditions.checkNotNull(widthIndex, ("fieldwidth")); this.widthIndex = Preconditions.checkNotNull(widthIndex, ("fieldwidth"));
this.blockDisplays = new UUID[BoardSize.boardSizes[widthIndex] * BoardSize.boardSizes[widthIndex]];
Preconditions.checkArgument(Math.abs(orientation.getModX()) + Math.abs(orientation.getModZ()) == 1, "no cardinal direction"); Preconditions.checkArgument(Math.abs(orientation.getModX()) + Math.abs(orientation.getModZ()) == 1, "no cardinal direction");
this.orientation = orientation; this.orientation = orientation;
@ -109,8 +107,10 @@ public class MinecleanerArena {
BlockData block0 = Material.NETHER_BRICKS.createBlockData(); BlockData block0 = Material.NETHER_BRICKS.createBlockData();
BlockData block1 = Material.BRICKS.createBlockData(); BlockData block1 = Material.BRICKS.createBlockData();
// todo: larger grids // todo: larger grids
for (int fx = -1; fx < 2; fx++) {
for (int fy = -1; fy < 2; fy++) {
for (int fx = -1; fx < 2 + widthIndex; fx++) {
for (int fy = -1; fy < 2 + widthIndex; fy++) {
loc.set(location.getX() + d1x * fx, location.getY() + fy, location.getZ() + d1z * fx); loc.set(location.getX() + d1x * fx, location.getY() + fy, location.getZ() + d1z * fx);
boolean f = (fx + fy) % 2 == 0; boolean f = (fx + fy) % 2 == 0;
world.setBlockData(loc, f ? block0 : block1); world.setBlockData(loc, f ? block0 : block1);
@ -118,6 +118,10 @@ public class MinecleanerArena {
} }
} }
/*
* Bei Größen WidthIndex 1 + 2 -> Mitte = ein Block nach Links unten versetzt
*/
public void generateBlockDisplays() { public void generateBlockDisplays() {
int size = BoardSize.boardSizes[widthIndex]; int size = BoardSize.boardSizes[widthIndex];
@ -148,9 +152,6 @@ public class MinecleanerArena {
int d1x = -d0z; int d1x = -d0z;
int d1z = d0x; int d1z = d0x;
// QWing sudoku = plugin.getGeneratorThread().getSudoku(Difficulty.EASY, true);
// int[] puzzle = sudoku == null ? new int[81] : sudoku.getPuzzle();
Location loc = location.clone(); Location loc = location.clone();
for(int fx = 0; fx < size; fx++) { for(int fx = 0; fx < size; fx++) {
final int fxf = fx; final int fxf = fx;
@ -159,9 +160,11 @@ public class MinecleanerArena {
// Todo not correctly alligned at different orientations (other than NORTH) // Todo not correctly alligned at different orientations (other than NORTH)
//loc.set(location.getX() + 0.11 - (d1x * fz) / 3.0 + d0x * 0.501 + d1x * 1.847, location.getY() - 0.9725 + fxf / 3.0, location.getZ() + 0.45 - (d1z * fz) / 3.0 + d0z * 0.501 + d1z * 1.847); //loc.set(location.getX() + 0.11 - (d1x * fz) / 3.0 + d0x * 0.501 + d1x * 1.847, location.getY() - 0.9725 + fxf / 3.0, location.getZ() + 0.45 - (d1z * fz) / 3.0 + d0z * 0.501 + d1z * 1.847);
loc.set(location.getX() - (d1x * fz) / 3.0 + d0x * 0.55 + d1x * 1.847, location.getY() - 0.8 + fxf / 3.0, location.getZ() + 0.45 - (d1z * fz) / 3.0 + d0z * 0.55 + d1z * 1.847); loc.set(location.getX() - (d1x * fz) / 3.0 + d0x * 0.55 + d1x * 1.847,
location.getY() - 0.8 + fxf / 3.0,
location.getZ() + 0.45 - (d1z * fz) / 3.0 + d0z * 0.55 + d1z * 1.847);
// Todo: Z-Fighting on Unknown Tile Heads (Front) // Todo: Z-Fighting on Unknown Tile Heads && Flags(Front)
// Todo: Z-Fighting on the Sides for all Tiles // Todo: Z-Fighting on the Sides for all Tiles
Display blockDisplay = world.spawn(loc, ItemDisplay.class, blockdisplay -> { Display blockDisplay = world.spawn(loc, ItemDisplay.class, blockdisplay -> {
Transformation transformation = blockdisplay.getTransformation(); Transformation transformation = blockdisplay.getTransformation();
@ -176,10 +179,6 @@ public class MinecleanerArena {
blockdisplay.setTransformation(newTransform); blockdisplay.setTransformation(newTransform);
blockdisplay.setRotation(rotation, -90); blockdisplay.setRotation(rotation, -90);
//MinecleanerHeads head = MinecleanerHeads.MINESWEEPER_TILE_UNKNOWN;
//blockdisplay.setBlock(MINECLEANER_HEADS[10].getHead().getType().createBlockData());
//blockdisplay.setBlock(head.getHead().clone().getType().createBlockData());
blockdisplay.setItemStack(MinecleanerHeads.MINESWEEPER_TILE_UNKNOWN.getHead()); blockdisplay.setItemStack(MinecleanerHeads.MINESWEEPER_TILE_UNKNOWN.getHead());
}); });
@ -219,7 +218,6 @@ public class MinecleanerArena {
public void startNewGame() { public void startNewGame() {
currentMinecleanerGame = new Game(plugin, BoardSize.boardSizes[widthIndex], BoardSize.mineCounter[widthIndex]); currentMinecleanerGame = new Game(plugin, BoardSize.boardSizes[widthIndex], BoardSize.mineCounter[widthIndex]);
currentMinecleanerGame.start(); currentMinecleanerGame.start();
//currentMinecleaerTileTypes = currentMinecleanerGame.getMinecleanerPuzzle(widthIndex, widthIndex);
arenaStatus = ArenaStatus.PLAYING; arenaStatus = ArenaStatus.PLAYING;
} }
@ -244,14 +242,13 @@ public class MinecleanerArena {
} }
} }
// block displays dont get removed
public void removeBlockDisplays() { public void removeBlockDisplays() {
int size = BoardSize.boardSizes[widthIndex]; int size = BoardSize.boardSizes[widthIndex];
World world = location.getWorld(); World world = location.getWorld();
for(int fx = 0; fx < size; fx++) { for(int fx = 0; fx < size; fx++) {
for(int fy = 0; fy < size; fy++) { for(int fy = 0; fy < size; fy++) {
UUID blockDisplayUuid = blockDisplays[fx + fy * 9]; UUID blockDisplayUuid = blockDisplays[fx + fy * size];
Entity blockDisplayEntity = blockDisplayUuid != null ? world.getEntity(blockDisplayUuid) : null; Entity blockDisplayEntity = blockDisplayUuid != null ? world.getEntity(blockDisplayUuid) : null;
if(blockDisplayEntity instanceof Display blockdisplay) { if(blockDisplayEntity instanceof Display blockdisplay) {
blockDisplayEntity.remove(); blockDisplayEntity.remove();
@ -261,66 +258,74 @@ public class MinecleanerArena {
} }
public void flagCell(int x, int y) { public void flagCell(int x, int y) {
if(currentMinecleanerGame != null) { if(currentMinecleanerGame != null && !currentMinecleanerGame.gameover) {
// flag block isnt shown / block does not change
//int id = x + y * 9;
Cell cell = currentMinecleanerGame.getCell(x, y); Cell cell = currentMinecleanerGame.getCell(x, y);
Player player = this.currentPlayer; if(!cell.isRevealed()) {
player.sendMessage(ChatColor.GOLD + "Cell: Pos(" + cell.position.x + "," + cell.position.y + "):" + " Is Flagged: " + cell.flagged + " ,Exploded: "
+ cell.exploded + " Is Revealed: " + cell.revealed);
currentMinecleanerGame.flag(x, y); Player player = this.currentPlayer;
plugin.getLogger().log(Level.SEVERE, " Is Flagged (before first if): " + cell.isFlagged()); currentMinecleanerGame.flag(x, y);
if(currentMinecleanerGame.gameover) {
plugin.getManager().handleGameover(player, this, true);
}
if(cell.isFlagged() == true) { //plugin.getLogger().log(Level.SEVERE, " Is Flagged (before first if): " + cell.isFlagged());
plugin.getLogger().log(Level.SEVERE, "Flagged Cell: [" + cell.position.x + "," + cell.position.y + "]");
setDiplayBlock(x, y, MinecleanerHeads.MINESWEEPER_TILE_FLAG);
if(cell.isFlagged() == true) {
plugin.getLogger().log(Level.SEVERE, "Flagged Cell: [" + cell.position.x + "," + cell.position.y + "]");
setDiplayBlock(x, y, MinecleanerHeads.MINESWEEPER_TILE_FLAG);
}
//plugin.getLogger().log(Level.SEVERE, " Is Flagged (before second if): " + cell.isFlagged());
if(cell.isFlagged() == false) {
plugin.getLogger().log(Level.SEVERE, "Unflagged Cell: [" + cell.position.x + "," + cell.position.y + "]");
setDiplayBlock(x, y, MinecleanerHeads.MINESWEEPER_TILE_UNKNOWN);
}
} }
plugin.getLogger().log(Level.SEVERE, " Is Flagged (before second if): " + cell.isFlagged());
if(cell.isFlagged() == false) {
plugin.getLogger().log(Level.SEVERE, "Unflagged Cell: [" + cell.position.x + "," + cell.position.y + "]");
setDiplayBlock(x, y, MinecleanerHeads.MINESWEEPER_TILE_UNKNOWN);
}
} }
} }
public void revealCell(int x, int y) { public void revealCell(int x, int y) {
if(currentMinecleanerGame != null) { if(currentMinecleanerGame != null && !currentMinecleanerGame.gameover) {
//int id = x + y * 9;
Cell cell = currentMinecleanerGame.getCell(x, y); Cell cell = currentMinecleanerGame.getCell(x, y);
Player player = this.currentPlayer;
player.sendMessage(ChatColor.GOLD + "Cell: Pos(" + cell.position.x + "," + cell.position.y + "):" + " Is Flagged: " + cell.flagged + " ,Is Revealed: " + cell.revealed + ", CellType: " + cell.getType());
if(!cell.isFlagged()) { if(!cell.isFlagged()) {
//int id = x + y * 9;
Player player = this.currentPlayer;
currentMinecleanerGame.reveal(x, y); currentMinecleanerGame.reveal(x, y);
}
if(cell.isRevealed() && cell.isExploded()) { setBlockForCellType(x, y, cell);
player.sendMessage(ChatColor.RED + "Game over :(");
}
setBlockForCellType(x, y, cell); if(currentMinecleanerGame.gameover) {
plugin.getManager().handleGameover(player, this, !(cell.isRevealed() && cell.isExploded()));
}
ArrayList<Cell> floodedCells = currentMinecleanerGame.getfloodedCells();
ArrayList<Cell> floodedCells = currentMinecleanerGame.getfloodedCells(); if(floodedCells != null) {
if(floodedCells != null) { for(int i = 0; i < floodedCells.size(); i++) {
player.sendMessage(ChatColor.GREEN + " Flooded Cells: [" + floodedCells.size() + "]"); Vector2i pos = floodedCells.get(i).position;
setBlockForCellType(pos.x, pos.y, floodedCells.get(i));
for(int i = 0; i < floodedCells.size(); i++) { }
Vector2i pos = floodedCells.get(i).position;
setBlockForCellType(pos.x, pos.y, floodedCells.get(i));
} }
} }
} }
} }
public void showMines() {
ArrayList<Cell> explodedCells = currentMinecleanerGame.getExplodedCells();
if(explodedCells != null) {
for(int i = 0; i < explodedCells.size(); i++) {
Vector2i pos = explodedCells.get(i).position;
setBlockForCellType(pos.x, pos.y, explodedCells.get(i));
}
}
}
private void setBlockForCellType(int x, int y, Cell cell) { private void setBlockForCellType(int x, int y, Cell cell) {
switch (cell.getType()) { switch (cell.getType()) {
case Empty: { case Empty: {
@ -374,8 +379,10 @@ public class MinecleanerArena {
case Mine: { case Mine: {
if(cell.isExploded()) { if(cell.isExploded()) {
setDiplayBlock(x, y, MinecleanerHeads.EXPLODED); setDiplayBlock(x, y, MinecleanerHeads.EXPLODED);
} else {
setDiplayBlock(x, y, MinecleanerHeads.TNT);
} }
setDiplayBlock(x, y, MinecleanerHeads.TNT);
break; break;
} }
default: { default: {
@ -394,9 +401,9 @@ public class MinecleanerArena {
int d1z = d0x; int d1z = d0x;
Location loc = location.clone(); Location loc = location.clone();
// todo: larger grids
for(int fx = -2; fx < 1; fx++) { for(int fx = -2 - widthIndex; fx < 1 ; fx++) {
for(int fy = -1; fy < 2; fy++) { for(int fy = -1; fy < 2 + widthIndex; fy++) {
loc.set(location.getX() + d1x + fx, location.getY() + fy, location.getZ() + d1z * fx); loc.set(location.getX() + d1x + fx, location.getY() + fy, location.getZ() + d1z * fx);
blocks.add(loc.clone()); blocks.add(loc.clone());
} }
@ -442,4 +449,8 @@ public class MinecleanerArena {
return blockDisplays; return blockDisplays;
} }
public int getSize() {
return BoardSize.boardSizes[widthIndex];
}
} }

View file

@ -44,20 +44,9 @@ public class MinecleanerListener implements Listener {
int d1z = d0x; int d1z = d0x;
if (e.getBlockFace() == arena.getOrientation()) { if (e.getBlockFace() == arena.getOrientation()) {
// Raytrace
// kann null sein
Player player = e.getPlayer(); Player player = e.getPlayer();
//RayTraceResult rayTraceResult = player.getWorld().rayTraceBlocks(player.getEyeLocation(), player.getEyeLocation().getDirection(), 64.0); RayTraceResult r2 = player.rayTraceBlocks(36.0);
RayTraceResult r2 = player.rayTraceBlocks(20.0);
//Location loc = e.getInteractionPoint().clone().subtract(arena.getLocation()).subtract(0.5, 0.5, 0.5); // null on left-click
/*
* TODO:
* [row] [coloumn] results depend on player position (on some player pos it works as it should, on most not)
*
*/
if(r2 != null) { if(r2 != null) {
Vector hitPos = r2.getHitPosition(); Vector hitPos = r2.getHitPosition();
@ -77,8 +66,6 @@ public class MinecleanerListener implements Listener {
double blockx = (dy / 3.0) * 9.0; double blockx = (dy / 3.0) * 9.0;
double blockz = (dz / 3.0) * 9.0; double blockz = (dz / 3.0) * 9.0;
int blockxInt = (int) blockx; int blockxInt = (int) blockx;
int blockzInt = (int) blockz; int blockzInt = (int) blockz;
blockx -= blockxInt; blockx -= blockxInt;
@ -106,8 +93,6 @@ public class MinecleanerListener implements Listener {
if(e.getAction() == Action.RIGHT_CLICK_BLOCK) { if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
hasRightClicked = true; hasRightClicked = true;
} }
// TODO Doesnt show messages for Cells: [ROW] [>5] (6, 7, 8 are missing)
//player.sendMessage("Arena click! " + blockxInt + " " + blockzInt + " Right Clicked: " + hasRightClicked); //player.sendMessage("Arena click! " + blockxInt + " " + blockzInt + " Right Clicked: " + hasRightClicked);
plugin.getManager().handleFieldClick(e.getPlayer(), blockxInt, blockzInt, hasRightClicked); plugin.getManager().handleFieldClick(e.getPlayer(), blockxInt, blockzInt, hasRightClicked);
} }

View file

@ -5,6 +5,7 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -26,10 +27,10 @@ import net.md_5.bungee.api.ChatColor;
public class MinecleanerManager { public class MinecleanerManager {
private final MinecleanerPlugin plugin; private final MinecleanerPlugin plugin;
private final Inventory confirmPlayingInventory; private final Inventory confirmPlayingInventory;
private final StatisticKey statisticsGamesTotal; private final StatisticKey statisticsGamesTotal;
@SuppressWarnings("deprecation") private int prevTick = 0;
public MinecleanerManager(MinecleanerPlugin plugin) { public MinecleanerManager(MinecleanerPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -76,6 +77,28 @@ public class MinecleanerManager {
player.sendMessage(ChatColor.YELLOW + "Du hast eine neue Runde Minecleaner gestartet."); player.sendMessage(ChatColor.YELLOW + "Du hast eine neue Runde Minecleaner gestartet.");
} }
public void handleGameover(Player player, MinecleanerArena arena, boolean isSuccessfullyCleared) {
if(!isSuccessfullyCleared) {
player.sendMessage(ChatColor.YELLOW + "Game Over! Du konntest das Feld nicht erfolgreich lösen!");
arena.showMines();
Bukkit.getScheduler().runTaskLater(plugin, () -> {
leaveArena(player, false);
}, 100L);
return;
}
player.sendMessage(ChatColor.YELLOW + "Glückwunsch, du konntest das Feld erfolgreich lösen!");
PlayerStatistics ps = plugin.getCubesideStatistics().getStatistics(player.getUniqueId());
ps.increaseScore(statisticsGamesTotal, 1);
Bukkit.getScheduler().runTaskLater(plugin, () -> {
leaveArena(player, false);
}, 100L);
}
public void clearAllArenas() { public void clearAllArenas() {
for(MinecleanerArena arena : plugin.getArenaList().getArenas()) { for(MinecleanerArena arena : plugin.getArenaList().getArenas()) {
if(arena.hasPlayer()) { if(arena.hasPlayer()) {
@ -93,16 +116,21 @@ public class MinecleanerManager {
Preconditions.checkArgument(arena != null, "player is in no arena"); Preconditions.checkArgument(arena != null, "player is in no arena");
Preconditions.checkState(arena.getArenaStatus() == ArenaStatus.PLAYING, "not running"); Preconditions.checkState(arena.getArenaStatus() == ArenaStatus.PLAYING, "not running");
// Fires Twice for Right Click on Same Tick, but only once for left click... stupid :< // Feels like a stupid solution for issue described in the next comment
if(hasRightClicked) { int currentTick = plugin.getServer().getCurrentTick();
// flag if(prevTick != currentTick) {
plugin.getLogger().log(Level.SEVERE, " Right Clicked @ Tick: " + plugin.getServer().getCurrentTick()); // Fires Twice for Right Click on Same Tick, but only once for left click... stupid :<
arena.flagCell(x, y); if(hasRightClicked) {
} else { // flag
// reveal plugin.getLogger().log(Level.SEVERE, " Right Clicked @ Tick: " + plugin.getServer().getCurrentTick());
plugin.getLogger().log(Level.SEVERE, " Left Clicked @ Tick: " + plugin.getServer().getCurrentTick()); arena.flagCell(x, y);
arena.revealCell(x, y); } else {
// reveal
plugin.getLogger().log(Level.SEVERE, " Left Clicked @ Tick: " + plugin.getServer().getCurrentTick());
arena.revealCell(x, y);
}
} }
prevTick = currentTick;
} }
public void getStatisticsForPlayer(OfflinePlayer player, Consumer<PlayerStatisticsData> callback) { public void getStatisticsForPlayer(OfflinePlayer player, Consumer<PlayerStatisticsData> callback) {

View file

@ -23,10 +23,6 @@ public final class MinecleanerPlugin extends JavaPlugin {
getServer().getScheduler().runTask(this, this::onLateEnable); getServer().getScheduler().runTask(this, this::onLateEnable);
} }
// TODO:
// doesnt save / load arenas correctly?
// -> can't delete arena after server restart
public void onLateEnable() { public void onLateEnable() {
playerUUIDCache = (PlayerUUIDCache) getServer().getPluginManager().getPlugin("PlayerUUIDCache"); playerUUIDCache = (PlayerUUIDCache) getServer().getPluginManager().getPlugin("PlayerUUIDCache");
cubesideStatistics = getServer().getServicesManager().load(CubesideStatisticsAPI.class); cubesideStatistics = getServer().getServicesManager().load(CubesideStatisticsAPI.class);

View file

@ -3,13 +3,13 @@ package de.lunarakai.minecleaner.game;
public class BoardSize { public class BoardSize {
public static int[] boardSizes = { public static int[] boardSizes = {
9, 9,
15, 12,
24, // nicht größer als 24 15, // nicht größer als 24
}; };
public static int[] mineCounter = { public static int[] mineCounter = {
12, 12,
40, 25,
100, 50,
}; };
} }

View file

@ -17,7 +17,9 @@ public class Game {
private Board board; private Board board;
private BoardSize boardSize; private BoardSize boardSize;
private Tilemap tilemap; private Tilemap tilemap;
private ArrayList<Cell> floodedCells; private ArrayList<Cell> floodedCells;
private ArrayList<Cell> explodedCells;
public Game(MinecleanerPlugin plugin, int width, int mineCount) { public Game(MinecleanerPlugin plugin, int width, int mineCount) {
this.plugin = plugin; this.plugin = plugin;
@ -26,6 +28,7 @@ public class Game {
this.mineCount = mineCount; this.mineCount = mineCount;
this.floodedCells = new ArrayList<>(); this.floodedCells = new ArrayList<>();
this.explodedCells = new ArrayList<>();
} }
private void onValidate() { private void onValidate() {
@ -177,6 +180,10 @@ public class Game {
if(cell.isRevealed()) return; if(cell.isRevealed()) return;
if(cell.getType() == Cell.CellType.Mine || cell.getType() == Cell.CellType.Invalid || cell.position == null) return; if(cell.getType() == Cell.CellType.Mine || cell.getType() == Cell.CellType.Invalid || cell.position == null) return;
if(cell.isFlagged()) {
cell.setFlaggedState(false);
}
cell.setRevealed(); cell.setRevealed();
floodedCells.add(cell); floodedCells.add(cell);
state[cell.position.x][cell.position.y] = cell; state[cell.position.x][cell.position.y] = cell;
@ -210,12 +217,13 @@ public class Game {
if(cell.getType() == Cell.CellType.Mine) { if(cell.getType() == Cell.CellType.Mine) {
cell.revealed = true; cell.revealed = true;
state[x][y] = cell; state[x][y] = cell;
explodedCells.add(cell);
} }
} }
} }
} }
private void checkWinCondition() { public void checkWinCondition() {
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
Cell cell = state[x][y]; Cell cell = state[x][y];
@ -254,4 +262,8 @@ public class Game {
public ArrayList<Cell> getfloodedCells() { public ArrayList<Cell> getfloodedCells() {
return floodedCells; return floodedCells;
} }
public ArrayList<Cell> getExplodedCells() {
return explodedCells;
}
} }