[Add] Field and mine generation

This commit is contained in:
2026-06-06 21:18:10 +07:00
parent 8ed9cc655f
commit 1a6f8901a2
17 changed files with 481 additions and 7 deletions
@@ -1,4 +1,5 @@
using Minesweeper.Core;
using Minesweeper.ECS;
namespace Minesweeper.Commands
{
@@ -19,23 +20,54 @@ namespace Minesweeper.Commands
public sealed class StartGameCommandHandler : IGameCommandHandler<StartGameCommand>
{
private readonly IBoardEcsSyncService boardEcsSyncService;
private readonly IBoardService boardService;
private readonly IGameStateService gameStateService;
public StartGameCommandHandler(IGameStateService gameStateService)
public StartGameCommandHandler(IBoardService boardService, IBoardEcsSyncService boardEcsSyncService, IGameStateService gameStateService)
{
this.boardService = boardService;
this.boardEcsSyncService = boardEcsSyncService;
this.gameStateService = gameStateService;
}
public void Handle(StartGameCommand command)
{
boardService.InitializeEmptyBoard();
gameStateService.SetState(GameState.Preparing);
boardEcsSyncService.SyncBoard(boardService);
boardEcsSyncService.SyncGameState(gameStateService.Current, false);
}
}
public sealed class OpenCellCommandHandler : IGameCommandHandler<OpenCellCommand>
{
private readonly IBoardEcsSyncService boardEcsSyncService;
private readonly IBoardService boardService;
private readonly IGameStateService gameStateService;
public OpenCellCommandHandler(IBoardService boardService, IBoardEcsSyncService boardEcsSyncService, IGameStateService gameStateService)
{
this.boardService = boardService;
this.boardEcsSyncService = boardEcsSyncService;
this.gameStateService = gameStateService;
}
public void Handle(OpenCellCommand command)
{
if (gameStateService.Current != GameState.Preparing)
{
return;
}
if (!boardService.GenerateAfterFirstClick(command.X, command.Y))
{
return;
}
gameStateService.SetState(GameState.Playing);
boardEcsSyncService.SyncBoard(boardService);
boardEcsSyncService.SyncGameState(gameStateService.Current, true);
}
}
@@ -48,16 +80,23 @@ namespace Minesweeper.Commands
public sealed class RestartCommandHandler : IGameCommandHandler<RestartCommand>
{
private readonly IBoardEcsSyncService boardEcsSyncService;
private readonly IBoardService boardService;
private readonly IGameStateService gameStateService;
public RestartCommandHandler(IGameStateService gameStateService)
public RestartCommandHandler(IBoardService boardService, IBoardEcsSyncService boardEcsSyncService, IGameStateService gameStateService)
{
this.boardService = boardService;
this.boardEcsSyncService = boardEcsSyncService;
this.gameStateService = gameStateService;
}
public void Handle(RestartCommand command)
{
boardService.InitializeEmptyBoard();
gameStateService.SetState(GameState.Preparing);
boardEcsSyncService.SyncBoard(boardService);
boardEcsSyncService.SyncGameState(gameStateService.Current, false);
}
}
@@ -77,16 +116,19 @@ namespace Minesweeper.Commands
public sealed class GoToMenuCommandHandler : IGameCommandHandler<GoToMenuCommand>
{
private readonly IBoardEcsSyncService boardEcsSyncService;
private readonly IGameStateService gameStateService;
public GoToMenuCommandHandler(IGameStateService gameStateService)
public GoToMenuCommandHandler(IBoardEcsSyncService boardEcsSyncService, IGameStateService gameStateService)
{
this.boardEcsSyncService = boardEcsSyncService;
this.gameStateService = gameStateService;
}
public void Handle(GoToMenuCommand command)
{
gameStateService.SetState(GameState.FieldSelection);
boardEcsSyncService.SyncGameState(gameStateService.Current, false);
}
}
}