Skip to content

Commit

Permalink
1.1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hunter2actual committed Apr 16, 2024
1 parent 578d8ad commit 5e7f792
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 23 deletions.
2 changes: 1 addition & 1 deletion DalamudMinesweeper.Tests/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class TestHelpers
public static MinesweeperGame InitialiseGame(string[] boardStrings, int initialX, int initialY)
{
var numMines = boardStrings.Sum(s => s.Count(c => c == '*'));
var game = new MinesweeperGame(boardStrings[0].Length, boardStrings.Length, numMines, false, () => { });
var game = new MinesweeperGame(boardStrings[0].Length, boardStrings.Length, numMines, false, () => { }, revealShortcut: true);
game.Click(initialX, initialY);
game.Board = BoardBuilder.FromStrings(boardStrings);
game.Click(initialX, initialY);
Expand Down
10 changes: 5 additions & 5 deletions DalamudMinesweeper.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"Author": "hunter2_",
"Name": "Minesweeper",
"InternalName": "DalamudMinesweeper",
"AssemblyVersion": "1.0.1.1",
"Description": "Logic puzzle in which you find and flag hidden mines.\n\nLeft click to uncover a square, right click to place a flag.\nClick a number that has the right amount of adjacent flags to reveal adjacent tiles.\nThe game ends when all mines are flagged and all safe squares have been uncovered.\nClick the smiley face to start a new game.",
"AssemblyVersion": "1.1.0.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": [
"minesweeper",
Expand All @@ -18,9 +18,9 @@
"LoadPriority": 0,
"Punchline": "Classic puzzle game.",
"AcceptsFeedback": true,
"DownloadLinkInstall": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.0.1.1/latest.zip",
"DownloadLinkUpdate": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.0.1.1/latest.zip",
"DownloadLinkInstall": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.1.0.0/latest.zip",
"DownloadLinkUpdate": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.1.0.0/latest.zip",
"IconUrl": "https://raw.githubusercontent.com/hunter2actual/DalamudMinesweeper/master/images/icon.png",
"Changelog": "Safeguards on config window to prevent bad state."
"Changelog": "Configurable shortcuts"
}
]
3 changes: 2 additions & 1 deletion DalamudMinesweeper/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Dalamud.Plugin;
using DalamudMinesweeper.Game;
using System;
using System.Collections.Generic;

namespace DalamudMinesweeper;

Expand All @@ -17,6 +16,8 @@ public class Configuration : IPluginConfiguration
public bool DevMode { get; set; } = false;
public bool NoGuess { get; set; } = false;
public int NoGuessTimeoutMs { get; set; } = 1500;
public bool RevealShortcut { get; set; } = false;
public bool FlagShortcut { get; set; } = false;

public Scores Scores { get; set; } = new Scores([]);

Expand Down
2 changes: 1 addition & 1 deletion DalamudMinesweeper/DalamudMinesweeper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="Dalamud.Plugin.Bootstrap.targets" />

<PropertyGroup>
<Version>1.0.1.1</Version>
<Version>1.1.0.0</Version>
<Description>A logic puzzle featuring hidden mines.</Description>
<PackageProjectUrl>https://github.com/hunter2actual/DalamudMinesweeper</PackageProjectUrl>
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
Expand Down
63 changes: 62 additions & 1 deletion DalamudMinesweeper/Game/BoardExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static bool ToggleCellFlag(this Board board, int x, int y)
return board.cells[x, y].isFlagged = !board.cells[x, y].isFlagged;
}

public static bool CellIsFulfilled(this Board board, int x, int y)
public static bool CellIsFulfilledForRevealing(this Board board, int x, int y)
{
var currentCell = board.cells[x, y];
if (currentCell.contents != CellContents.Number || currentCell.isFlagged)
Expand Down Expand Up @@ -103,6 +103,38 @@ public static bool CellIsFulfilled(this Board board, int x, int y)
return neighbouringFlags == currentCell.numNeighbouringMines;
}

public static bool CellIsFulfilledForFlagging(this Board board, int x, int y)
{
var currentCell = board.cells[x, y];
if (currentCell.contents != CellContents.Number || currentCell.isFlagged)
return false;

var neighbouringHidden = 0;

// Loop through a square around the current cell
for (int y2 = y - 1; y2 <= y + 1; y2++)
{
for (int x2 = x - 1; x2 <= x + 1; x2++)
{
// Skip self
if (x2 == x && y2 == y)
continue;

// Avoid out of bounds
if (x2 < 0 || y2 < 0 || x2 >= board.width || y2 >= board.height)
continue;

var neighbourCell = board.cells[x2, y2];
if (!neighbourCell.isRevealed)
{
neighbouringHidden++;
}
}
}

return neighbouringHidden == currentCell.numNeighbouringMines;
}

public static void ClickAdjacentUnflaggedTiles(this Board board, int x, int y, Action<int, int> clickAction)
{
var currentCell = board.cells[x, y];
Expand Down Expand Up @@ -130,6 +162,35 @@ public static void ClickAdjacentUnflaggedTiles(this Board board, int x, int y, A
return;
}

public static void FlagAdjacentHiddenTiles(this Board board, int x, int y, Action<int, int> rightClickAction)
{
var currentCell = board.cells[x, y];
if (currentCell.contents != CellContents.Number || currentCell.isFlagged)
return;

// Loop through a square around the current cell
for (int y2 = y - 1; y2 <= y + 1; y2++)
{
for (int x2 = x - 1; x2 <= x + 1; x2++)
{
// Skip self
if (x2 == x && y2 == y)
continue;

// Avoid out of bounds
if (x2 < 0 || y2 < 0 || x2 >= board.width || y2 >= board.height)
continue;

var neighbourCell = board.cells[x2, y2];
if (!neighbourCell.isFlagged && !neighbourCell.isRevealed)
{
rightClickAction(x2, y2);
}
}
}
return;
}

public static void RevealConnectedField(this Board board, int x, int y)
{
var currentCell = board.cells[x, y];
Expand Down
17 changes: 15 additions & 2 deletions DalamudMinesweeper/Game/MinesweeperGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ public class MinesweeperGame
private Stopwatch _stopwatch;
private readonly bool _noGuess;
private Action _onVictory;
private readonly bool _revealShortcut;
private readonly bool _flagShortcut;

public MinesweeperGame(int width, int height, int numMines, bool noGuess, Action onVictory, int noGuessTimeoutMs = 1500)

public MinesweeperGame(int width, int height, int numMines, bool noGuess, Action onVictory,
int noGuessTimeoutMs = 1500, bool revealShortcut = false, bool flagShortcut = false)
{
Width = width;
Height = height;
Expand All @@ -32,6 +36,8 @@ public MinesweeperGame(int width, int height, int numMines, bool noGuess, Action
_noGuessGenerator = new NoGuessGenerator(Width, Height, NumMines, noGuessTimeoutMs);
NoGuessValid = true;
_onVictory = onVictory;
_revealShortcut = revealShortcut;
_flagShortcut = flagShortcut;
}

public void Click(int x, int y)
Expand Down Expand Up @@ -66,7 +72,7 @@ public void Click(int x, int y)
RevealAll();
break;
case CellContents.Number:
if (cell.isRevealed && Board.CellIsFulfilled(x, y))
if (_revealShortcut && cell.isRevealed && Board.CellIsFulfilledForRevealing(x, y))
{
Board.ClickAdjacentUnflaggedTiles(x, y, Click);
}
Expand All @@ -88,6 +94,13 @@ public void RightClick(int x, int y)
{
if (GameState != GameState.Playing || !_firstMoveTaken) return;

if (_flagShortcut)
{
var cell = GetCell(x, y);
if (cell.contents is CellContents.Number && Board.CellIsFulfilledForFlagging(x, y))
Board.FlagAdjacentHiddenTiles(x, y, RightClick);
}

Board.ToggleCellFlag(x, y);

if(Board.IsVictory()) Win();
Expand Down
2 changes: 1 addition & 1 deletion DalamudMinesweeper/Game/NoGuessGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Board Generate(int initialX, int initialY)
}

private MinesweeperGame DummyGame()
=> new MinesweeperGame(_width, _height, _numMines, false, () => { });
=> new MinesweeperGame(_width, _height, _numMines, false, () => { }, revealShortcut: true, flagShortcut: false);

private async Task<(bool swept, Board board)> TestBoard(int initialX, int initialY, CancellationToken ct)
{
Expand Down
9 changes: 4 additions & 5 deletions DalamudMinesweeper/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public void Dispose()

private void OnCommand(string command, string args)
{
// in response to the slash command, just display our main ui
_mainWindow.IsOpen = true;
_mainWindow.IsOpen = !_mainWindow.IsOpen;
}

private void DrawUI()
Expand All @@ -70,16 +69,16 @@ private void DrawUI()

private void DrawMainUI()
{
_mainWindow.IsOpen = true;
_mainWindow.IsOpen = !_mainWindow.IsOpen;
}

public void DrawConfigUI()
{
_configWindow.IsOpen = true;
_configWindow.IsOpen = !_configWindow.IsOpen;
}

public void DrawScoresUI()
{
_scoresWindow.IsOpen = true;
_scoresWindow.IsOpen = !_scoresWindow.IsOpen;
}
}
35 changes: 31 additions & 4 deletions DalamudMinesweeper/Windows/ConfigWindow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Numerics;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Windowing;
using ImGuiNET;

Expand All @@ -14,7 +15,7 @@ public ConfigWindow(Plugin plugin) : base(
ImGuiWindowFlags.NoScrollbar |
ImGuiWindowFlags.NoScrollWithMouse)
{
Size = new Vector2(310, 250);
Size = new Vector2(380, 380);
SizeCondition = ImGuiCond.Once;

_configuration = plugin.Configuration;
Expand All @@ -24,6 +25,7 @@ public void Dispose() { }

public override void Draw()
{
ImGui.Text("Difficulty:");
// Difficulty buttons
if (ImGui.Button("Easy")) {
_configuration.BoardWidth = 9;
Expand All @@ -44,6 +46,7 @@ public override void Draw()
}

// Config setters
ImGui.PushItemWidth(150f * ImGuiHelpers.GlobalScale);
var width = _configuration.BoardWidth;
if (ImGui.InputInt("Board width", ref width))
{
Expand Down Expand Up @@ -72,16 +75,17 @@ public override void Draw()
_configuration.NumMines = numMines;
}

ImGui.Dummy(new Vector2(0,20));
ImGui.Dummy(new Vector2(0, 30));

//var devMode = _configuration.DevMode;
//if (ImGui.Checkbox("Dev mode", ref devMode))
//{
// _configuration.DevMode = devMode;
//}

ImGui.Text("No guess mode:");
var noGuess = _configuration.NoGuess;
if (ImGui.Checkbox("No guess mode", ref noGuess))
if (ImGui.Checkbox("Enable no guess mode", ref noGuess))
{
_configuration.NoGuess = noGuess;
}
Expand All @@ -104,7 +108,30 @@ public override void Draw()
ImGui.Dummy(new Vector2(0, 26));
}

ImGui.Dummy(new Vector2(0, 20));
ImGui.Dummy(new Vector2(0, 30));

ImGui.Text("Shortcuts:");
var revealShortcut = _configuration.RevealShortcut;
if (ImGui.Checkbox("Click on a number to automatically reveal adjacent tiles", ref revealShortcut))
{
_configuration.RevealShortcut = revealShortcut;
}
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip("Only when the number already has the appropriate number of adjacent flags.");
}
var flagShortcut = _configuration.FlagShortcut;
if (ImGui.Checkbox("Right click on a number to automatically place adjacent flags", ref flagShortcut))
{
_configuration.FlagShortcut = flagShortcut;
}
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip("Only when the number has the appropriate number of adjacent hidden tiles.");
}


ImGui.Dummy(new Vector2(0, 37));


if (ImGui.Button("Reset zoom level"))
Expand Down
4 changes: 3 additions & 1 deletion DalamudMinesweeper/Windows/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ private MinesweeperGame InitialiseGame()
_configuration.NumMines,
_configuration.NoGuess,
RecordScore,
_configuration.NoGuessTimeoutMs);
_configuration.NoGuessTimeoutMs,
_configuration.RevealShortcut,
_configuration.FlagShortcut);

if (_header is not null)
{
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Dalamud plugin for FFXIV, install by adding `https://raw.githubusercontent.com/h

How to play:
- Left click to uncover a square, right click to place a flag.
- Click a number that has the right amount of adjacent flags to reveal adjacent tiles.
- The game ends when all mines are flagged and all safe squares have been uncovered.
- Click the smiley face to start a new game.

Features:
- Score board
- No-guess mode!
- 3 difficulty presets
- Optional shortcuts

![Minesweeper plugin screenshot](/images/screenshot.png?raw=true "Minesweeper plugin screenshot")

Expand Down

0 comments on commit 5e7f792

Please sign in to comment.