diff --git a/DalamudMinesweeper.json b/DalamudMinesweeper.json index 3184a93..33607f0 100644 --- a/DalamudMinesweeper.json +++ b/DalamudMinesweeper.json @@ -3,7 +3,7 @@ "Author": "hunter2_", "Name": "Minesweeper", "InternalName": "DalamudMinesweeper", - "AssemblyVersion": "1.2.0.0", + "AssemblyVersion": "1.2.2.0", "Description": "Logic puzzle in which you find and flag hidden mines.\n\nLeft click to uncover a square, right click to place a flag.\nThe game ends when all mines are flagged and all safe squares have been uncovered.\nClick the smiley face to start a new game.", "ApplicableVersion": "any", "Tags": [ @@ -18,9 +18,9 @@ "LoadPriority": 0, "Punchline": "Classic puzzle game.", "AcceptsFeedback": true, - "DownloadLinkInstall": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.2.0.0/latest.zip", - "DownloadLinkUpdate": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.2.0.0/latest.zip", + "DownloadLinkInstall": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.2.2.0/latest.zip", + "DownloadLinkUpdate": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.2.2.0/latest.zip", "IconUrl": "https://raw.githubusercontent.com/hunter2actual/DalamudMinesweeper/master/images/icon.png", - "Changelog": "Update for FFXIV 7.1" + "Changelog": "Consider game won when all safe cells revealed, even if not all mines are flagged (thanks cheege)" } ] \ No newline at end of file diff --git a/DalamudMinesweeper/DalamudMinesweeper.csproj b/DalamudMinesweeper/DalamudMinesweeper.csproj index a0a31f8..87f098b 100644 --- a/DalamudMinesweeper/DalamudMinesweeper.csproj +++ b/DalamudMinesweeper/DalamudMinesweeper.csproj @@ -3,7 +3,7 @@ - 1.2.1.0 + 1.2.2.0 A logic puzzle featuring hidden mines. https://github.com/hunter2actual/DalamudMinesweeper AGPL-3.0-or-later diff --git a/DalamudMinesweeper/Game/BoardExtensions.cs b/DalamudMinesweeper/Game/BoardExtensions.cs index dbac54b..a391695 100644 --- a/DalamudMinesweeper/Game/BoardExtensions.cs +++ b/DalamudMinesweeper/Game/BoardExtensions.cs @@ -50,6 +50,19 @@ public static Board HideAll(this Board board) return board; } + public static Board FlagAllMines(this Board board) + { + for (int x = 0; x < board.width; x++) { + for (int y = 0; y < board.height; y++) { + if (board.cells[x, y].contents is CellContents.Mine) + { + board.cells[x, y].isFlagged = true; + } + } + } + return board; + } + public static CellContents RevealCell(this Board board, int x, int y) { board.cells[x, y].isRevealed = true; @@ -220,18 +233,8 @@ public static void RevealConnectedField(this Board board, int x, int y) return; } - public static bool IsVictory(this Board board) - { - var cells = board.cells.ToList(); - - var minesAreFlagged = cells - .Where(c => c.contents is CellContents.Mine) - .All(c => c.isFlagged); - - var nonMinesRevealed = cells + public static bool IsVictory(this Board board) => + board.cells.ToList() .Where(c => c.contents is not CellContents.Mine) .All(c => c.isRevealed); - - return minesAreFlagged && nonMinesRevealed; - } } \ No newline at end of file diff --git a/DalamudMinesweeper/Game/MinesweeperGame.cs b/DalamudMinesweeper/Game/MinesweeperGame.cs index 1c4bc4d..b33c665 100644 --- a/DalamudMinesweeper/Game/MinesweeperGame.cs +++ b/DalamudMinesweeper/Game/MinesweeperGame.cs @@ -109,6 +109,7 @@ public void RightClick(int x, int y) public void Win() { GameState = GameState.Victorious; + FlagAllMines(); _onVictory(); _stopwatch.Stop(); } @@ -117,6 +118,8 @@ public void Win() public void HideAll() => Board.HideAll(); + public void FlagAllMines() => Board.FlagAllMines(); + public Cell GetCell(int x, int y) => Board.cells[x, y]; public int NumUnflaggedMines() diff --git a/DalamudMinesweeper/Plugin.cs b/DalamudMinesweeper/Plugin.cs index 52c9b1b..1a7c8f8 100644 --- a/DalamudMinesweeper/Plugin.cs +++ b/DalamudMinesweeper/Plugin.cs @@ -35,7 +35,7 @@ public Plugin( _configWindow = new ConfigWindow(this); _scoresWindow = new ScoresWindow(this); - _mainWindow = new MainWindow(this, Configuration, Service.TextureProvider); + _mainWindow = new MainWindow(this, Configuration); WindowSystem.AddWindow(_configWindow); WindowSystem.AddWindow(_scoresWindow); diff --git a/DalamudMinesweeper/Windows/MainWindow.cs b/DalamudMinesweeper/Windows/MainWindow.cs index 6888ec4..7faa147 100644 --- a/DalamudMinesweeper/Windows/MainWindow.cs +++ b/DalamudMinesweeper/Windows/MainWindow.cs @@ -6,15 +6,12 @@ using DalamudMinesweeper.Sweepers; using DalamudMinesweeper.Sprites; using ImGuiNET; -using Dalamud.Plugin.Services; namespace DalamudMinesweeper.Windows; public class MainWindow : Window, IDisposable { private readonly TileSprites _tileSprites; - private readonly NumberSprites _numberSprites; - private readonly Sweeper _sweeper; private readonly Configuration _configuration; private MinesweeperGame _game; @@ -24,7 +21,6 @@ public class MainWindow : Window, IDisposable // Pixel sizes private readonly int _dalamudWindowPaddingPx = 8; private int _gridSquareSizePx; - private Vector2 _gridSquareSizePxVec2; private readonly int _borderWidthPx = 12; private readonly Vector2 _borderWidthPxVec2 = new(12, 12); private readonly int _titleBarHeightPx = 26; @@ -36,7 +32,7 @@ public class MainWindow : Window, IDisposable private Footer _footer; private Background _background; - public MainWindow(Plugin plugin, Configuration configuration, ITextureProvider textureProvider) : base("Minesweeper", + public MainWindow(Plugin plugin, Configuration configuration) : base("Minesweeper", ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse | ImGuiWindowFlags.NoResize @@ -50,14 +46,12 @@ public MainWindow(Plugin plugin, Configuration configuration, ITextureProvider t _configuration = configuration; _tileSprites = new TileSprites(Service.PluginInterface); - _numberSprites = new NumberSprites(Service.PluginInterface); - _gridSquareSizePxVec2 = new Vector2(0, 0); + var numberSprites = new NumberSprites(Service.PluginInterface); - _sweeper = new Sweeper(); _game = InitialiseGame(); _gameBoard = new GameBoard(_game, _tileSprites, _configuration); - _header = new Header(_game, _tileSprites, _numberSprites, _configuration, () => InitialiseGame()); - _footer = new Footer(_game, _configuration, plugin.DrawConfigUI, plugin.DrawScoresUI, _sweeper); + _header = new Header(_game, _tileSprites, numberSprites, _configuration, () => InitialiseGame()); + _footer = new Footer(_game, _configuration, plugin.DrawConfigUI, plugin.DrawScoresUI, new Sweeper()); _background = new Background(_game, _configuration, _borderWidthPx); } @@ -65,10 +59,9 @@ public override void Draw() { // Calculate element sizes var windowPos = ImGui.GetWindowPos(); - var headerHeightPx = (int) (_tileSprites.SmileySize.Y + 8)* _configuration.Zoom; + var headerHeightPx = (int) (_tileSprites.SmileySize.Y + 8) * _configuration.Zoom; _gridSquareSizePx = (int) _tileSprites.TileSize.X * _configuration.Zoom; - _gridSquareSizePxVec2.X = _gridSquareSizePxVec2.Y = _gridSquareSizePx; _boardDimensions = new Vector2(_game.Width, _game.Height); var windowWidthPx = _gridSquareSizePx*_boardDimensions.X + 2*_borderWidthPx*_configuration.Zoom + 2*_dalamudWindowPaddingPx; var windowHeightPx = _gridSquareSizePx*_boardDimensions.Y + 2*_borderWidthPx*_configuration.Zoom + 2*_dalamudWindowPaddingPx