[Fix] UI Logic

This commit is contained in:
2026-06-06 22:33:15 +07:00
parent f4ecf8b6f9
commit fdb22e9213
134 changed files with 5367 additions and 269 deletions
@@ -0,0 +1,52 @@
using System.Collections.Generic;
using Minesweeper.Config;
using Minesweeper.Core;
namespace Minesweeper.Presentation.ReadModels
{
public sealed class GameReadModel : IGameReadModel
{
private readonly MinesweeperGameConfig config;
private readonly IBoardService boardService;
private readonly IGameStateService gameStateService;
public GameReadModel(MinesweeperGameConfig config, IBoardService boardService, IGameStateService gameStateService)
{
this.config = config;
this.boardService = boardService;
this.gameStateService = gameStateService;
}
public GameState State => gameStateService.Current;
public int Width => boardService.Width > 0 ? boardService.Width : config.Width;
public int Height => boardService.Height > 0 ? boardService.Height : config.Height;
public int MinesCount => boardService.MinesCount > 0 ? boardService.MinesCount : config.MinesCount;
public int FlaggedCellsCount => CountFlaggedCells();
public int RemainingMinesCount => MinesCount - FlaggedCellsCount;
public bool TryGetCell(int x, int y, out BoardCellData cell)
{
return boardService.TryGetCell(x, y, out cell);
}
public IReadOnlyList<BoardCellData> GetCells()
{
return boardService.GetCells();
}
private int CountFlaggedCells()
{
var cells = boardService.GetCells();
var count = 0;
for (var i = 0; i < cells.Count; i++)
{
if (cells[i].IsFlagged)
{
count++;
}
}
return count;
}
}
}