[Add] UI, menu, pause and timer
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
|
||||
namespace Minesweeper.Core
|
||||
{
|
||||
public sealed class GamePauseService : IGamePauseService
|
||||
{
|
||||
public event Action<bool> PauseChanged;
|
||||
|
||||
public bool IsPaused { get; private set; }
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (IsPaused)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IsPaused = true;
|
||||
PauseChanged?.Invoke(IsPaused);
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
if (!IsPaused)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IsPaused = false;
|
||||
PauseChanged?.Invoke(IsPaused);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40441c28481279147959eafabd8a032a
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed8262be24a32a04abfd5bc5ec8544bb
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace Minesweeper.Core
|
||||
{
|
||||
public interface IGamePauseService
|
||||
{
|
||||
event Action<bool> PauseChanged;
|
||||
|
||||
bool IsPaused { get; }
|
||||
|
||||
void Pause();
|
||||
void Resume();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82dfb9fe1e7004f4f88df366f8e76b2d
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace Minesweeper.Core
|
||||
{
|
||||
public interface IGameTimerService
|
||||
{
|
||||
event Action<float> TimeChanged;
|
||||
|
||||
float ElapsedSeconds { get; }
|
||||
|
||||
void Reset();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61242d395cb1d974daffd9e0815ec34c
|
||||
Reference in New Issue
Block a user