[Add] UI, menu, pause and timer
This commit is contained in:
@@ -22,17 +22,23 @@ namespace Minesweeper.Commands
|
||||
{
|
||||
private readonly IBoardEcsSyncService boardEcsSyncService;
|
||||
private readonly IBoardService boardService;
|
||||
private readonly IGamePauseService pauseService;
|
||||
private readonly IGameStateService gameStateService;
|
||||
private readonly IGameTimerService timerService;
|
||||
|
||||
public StartGameCommandHandler(IBoardService boardService, IBoardEcsSyncService boardEcsSyncService, IGameStateService gameStateService)
|
||||
public StartGameCommandHandler(IBoardService boardService, IBoardEcsSyncService boardEcsSyncService, IGamePauseService pauseService, IGameStateService gameStateService, IGameTimerService timerService)
|
||||
{
|
||||
this.boardService = boardService;
|
||||
this.boardEcsSyncService = boardEcsSyncService;
|
||||
this.pauseService = pauseService;
|
||||
this.gameStateService = gameStateService;
|
||||
this.timerService = timerService;
|
||||
}
|
||||
|
||||
public void Handle(StartGameCommand command)
|
||||
{
|
||||
pauseService.Resume();
|
||||
timerService.Reset();
|
||||
boardService.InitializeEmptyBoard();
|
||||
gameStateService.SetState(GameState.Preparing);
|
||||
boardEcsSyncService.SyncBoard(boardService);
|
||||
@@ -45,16 +51,23 @@ namespace Minesweeper.Commands
|
||||
private readonly IBoardEcsSyncService boardEcsSyncService;
|
||||
private readonly IBoardService boardService;
|
||||
private readonly IGameStateService gameStateService;
|
||||
private readonly IGamePauseService pauseService;
|
||||
|
||||
public OpenCellCommandHandler(IBoardService boardService, IBoardEcsSyncService boardEcsSyncService, IGameStateService gameStateService)
|
||||
public OpenCellCommandHandler(IBoardService boardService, IBoardEcsSyncService boardEcsSyncService, IGameStateService gameStateService, IGamePauseService pauseService)
|
||||
{
|
||||
this.boardService = boardService;
|
||||
this.boardEcsSyncService = boardEcsSyncService;
|
||||
this.gameStateService = gameStateService;
|
||||
this.pauseService = pauseService;
|
||||
}
|
||||
|
||||
public void Handle(OpenCellCommand command)
|
||||
{
|
||||
if (pauseService.IsPaused)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var state = gameStateService.Current;
|
||||
if (state != GameState.Preparing && state != GameState.Playing)
|
||||
{
|
||||
@@ -103,16 +116,23 @@ namespace Minesweeper.Commands
|
||||
private readonly IBoardEcsSyncService boardEcsSyncService;
|
||||
private readonly IBoardService boardService;
|
||||
private readonly IGameStateService gameStateService;
|
||||
private readonly IGamePauseService pauseService;
|
||||
|
||||
public ToggleFlagCommandHandler(IBoardService boardService, IBoardEcsSyncService boardEcsSyncService, IGameStateService gameStateService)
|
||||
public ToggleFlagCommandHandler(IBoardService boardService, IBoardEcsSyncService boardEcsSyncService, IGameStateService gameStateService, IGamePauseService pauseService)
|
||||
{
|
||||
this.boardService = boardService;
|
||||
this.boardEcsSyncService = boardEcsSyncService;
|
||||
this.gameStateService = gameStateService;
|
||||
this.pauseService = pauseService;
|
||||
}
|
||||
|
||||
public void Handle(ToggleFlagCommand command)
|
||||
{
|
||||
if (pauseService.IsPaused)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var state = gameStateService.Current;
|
||||
if (state != GameState.Preparing && state != GameState.Playing)
|
||||
{
|
||||
@@ -134,17 +154,23 @@ namespace Minesweeper.Commands
|
||||
{
|
||||
private readonly IBoardEcsSyncService boardEcsSyncService;
|
||||
private readonly IBoardService boardService;
|
||||
private readonly IGamePauseService pauseService;
|
||||
private readonly IGameStateService gameStateService;
|
||||
private readonly IGameTimerService timerService;
|
||||
|
||||
public RestartCommandHandler(IBoardService boardService, IBoardEcsSyncService boardEcsSyncService, IGameStateService gameStateService)
|
||||
public RestartCommandHandler(IBoardService boardService, IBoardEcsSyncService boardEcsSyncService, IGamePauseService pauseService, IGameStateService gameStateService, IGameTimerService timerService)
|
||||
{
|
||||
this.boardService = boardService;
|
||||
this.boardEcsSyncService = boardEcsSyncService;
|
||||
this.pauseService = pauseService;
|
||||
this.gameStateService = gameStateService;
|
||||
this.timerService = timerService;
|
||||
}
|
||||
|
||||
public void Handle(RestartCommand command)
|
||||
{
|
||||
pauseService.Resume();
|
||||
timerService.Reset();
|
||||
boardService.InitializeEmptyBoard();
|
||||
gameStateService.SetState(GameState.Preparing);
|
||||
boardEcsSyncService.SyncBoard(boardService);
|
||||
@@ -154,31 +180,58 @@ namespace Minesweeper.Commands
|
||||
|
||||
public sealed class PauseCommandHandler : IGameCommandHandler<PauseCommand>
|
||||
{
|
||||
private readonly IGamePauseService pauseService;
|
||||
private readonly IGameStateService gameStateService;
|
||||
|
||||
public PauseCommandHandler(IGamePauseService pauseService, IGameStateService gameStateService)
|
||||
{
|
||||
this.pauseService = pauseService;
|
||||
this.gameStateService = gameStateService;
|
||||
}
|
||||
|
||||
public void Handle(PauseCommand command)
|
||||
{
|
||||
if (gameStateService.Current == GameState.Playing)
|
||||
{
|
||||
pauseService.Pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ResumeCommandHandler : IGameCommandHandler<ResumeCommand>
|
||||
{
|
||||
private readonly IGamePauseService pauseService;
|
||||
|
||||
public ResumeCommandHandler(IGamePauseService pauseService)
|
||||
{
|
||||
this.pauseService = pauseService;
|
||||
}
|
||||
|
||||
public void Handle(ResumeCommand command)
|
||||
{
|
||||
pauseService.Resume();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class GoToMenuCommandHandler : IGameCommandHandler<GoToMenuCommand>
|
||||
{
|
||||
private readonly IBoardEcsSyncService boardEcsSyncService;
|
||||
private readonly IGamePauseService pauseService;
|
||||
private readonly IGameStateService gameStateService;
|
||||
private readonly IGameTimerService timerService;
|
||||
|
||||
public GoToMenuCommandHandler(IBoardEcsSyncService boardEcsSyncService, IGameStateService gameStateService)
|
||||
public GoToMenuCommandHandler(IBoardEcsSyncService boardEcsSyncService, IGamePauseService pauseService, IGameStateService gameStateService, IGameTimerService timerService)
|
||||
{
|
||||
this.boardEcsSyncService = boardEcsSyncService;
|
||||
this.pauseService = pauseService;
|
||||
this.gameStateService = gameStateService;
|
||||
this.timerService = timerService;
|
||||
}
|
||||
|
||||
public void Handle(GoToMenuCommand command)
|
||||
{
|
||||
pauseService.Resume();
|
||||
timerService.Reset();
|
||||
gameStateService.SetState(GameState.FieldSelection);
|
||||
boardEcsSyncService.SyncGameState(gameStateService.Current, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user