[Add] UI, menu, pause and timer

This commit is contained in:
2026-06-06 22:03:20 +07:00
parent 1483964eaf
commit f4ecf8b6f9
23 changed files with 2440 additions and 11 deletions
@@ -0,0 +1,48 @@
using System;
using UnityEngine;
using VContainer.Unity;
namespace Minesweeper.Core
{
public sealed class GameTimerService : IGameTimerService, ITickable
{
private readonly IGamePauseService pauseService;
private readonly IGameStateService gameStateService;
private int lastReportedSeconds = -1;
public GameTimerService(IGameStateService gameStateService, IGamePauseService pauseService)
{
this.gameStateService = gameStateService;
this.pauseService = pauseService;
}
public event Action<float> TimeChanged;
public float ElapsedSeconds { get; private set; }
public void Tick()
{
if (gameStateService.Current != GameState.Playing || pauseService.IsPaused)
{
return;
}
ElapsedSeconds += Time.deltaTime;
var seconds = Mathf.FloorToInt(ElapsedSeconds);
if (seconds == lastReportedSeconds)
{
return;
}
lastReportedSeconds = seconds;
TimeChanged?.Invoke(ElapsedSeconds);
}
public void Reset()
{
ElapsedSeconds = 0f;
lastReportedSeconds = -1;
TimeChanged?.Invoke(ElapsedSeconds);
}
}
}