[Add] Menu with configs and size fix

This commit is contained in:
2026-06-06 23:48:55 +07:00
parent 7104089c00
commit a9767c5301
29 changed files with 453 additions and 153 deletions
+6 -27
View File
@@ -1,22 +1,17 @@
using System;
using System.Collections.Generic;
using Minesweeper.Config;
namespace Minesweeper.Core
{
public sealed class BoardService : IBoardService
{
private const int DefaultWidth = 9;
private const int DefaultHeight = 9;
private const int DefaultMinesCount = 10;
private readonly MinesweeperGameConfig config;
private readonly IGameSettingsService settingsService;
private readonly Random random = new Random();
private CellData[,] cells;
public BoardService(MinesweeperGameConfig config)
public BoardService(IGameSettingsService settingsService)
{
this.config = config;
this.settingsService = settingsService;
}
public int Width { get; private set; }
@@ -28,11 +23,9 @@ namespace Minesweeper.Core
public void InitializeEmptyBoard()
{
ResolveConfig(out var width, out var height, out var minesCount);
Width = width;
Height = height;
MinesCount = minesCount;
Width = settingsService.SizeX;
Height = settingsService.SizeY;
MinesCount = Math.Min(settingsService.MinesCount, Width * Height - 1);
OpenedSafeCellsCount = 0;
IsGenerated = false;
cells = new CellData[Width, Height];
@@ -147,20 +140,6 @@ namespace Minesweeper.Core
return result;
}
private void ResolveConfig(out int width, out int height, out int minesCount)
{
width = config.Width;
height = config.Height;
minesCount = config.MinesCount;
if (width <= 0 || height <= 0 || minesCount <= 0 || minesCount >= width * height)
{
width = DefaultWidth;
height = DefaultHeight;
minesCount = DefaultMinesCount;
}
}
private void EnsureInitialized()
{
if (cells == null)