dev
This commit is contained in:
parent
7a3d73ce66
commit
f6348a847d
|
|
@ -21,27 +21,29 @@ namespace GameHandler
|
|||
{
|
||||
public class GameService
|
||||
{
|
||||
private IContainer _rootContainer { get; set; }
|
||||
private readonly IContainer? _rootContainer;
|
||||
private bool _isStarted = false;
|
||||
private ILifetimeScope _scope;
|
||||
private IGameHandler _gh;
|
||||
private ThrowHandler _th;
|
||||
private ExpenseHandler _eh;
|
||||
private GameStateHandler _gameStateHandler;
|
||||
private Game _game;
|
||||
private ILifetimeScope? _scope;
|
||||
private IGameHandler? _gh;
|
||||
private ThrowHandler? _th;
|
||||
private ExpenseHandler? _eh;
|
||||
private GameStateHandler? _gameStateHandler;
|
||||
private Game? _game;
|
||||
|
||||
public GameState GameModel { get => _gameStateHandler.GameState; }
|
||||
public GameState? GameModel { get => _gameStateHandler?.GameState; }
|
||||
|
||||
public GameService(IContainer rootContainer = null)
|
||||
public bool FreePlayerSelection => _gh != null && _gh.FreePlayerSelection();
|
||||
|
||||
public GameService(IContainer? rootContainer = null)
|
||||
{
|
||||
_rootContainer = rootContainer;
|
||||
this._rootContainer = rootContainer;
|
||||
}
|
||||
|
||||
public string ThrowModeName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_gameStateHandler.GameState != null)
|
||||
if (_gameStateHandler?.GameState != null)
|
||||
{
|
||||
return _gameStateHandler.GameState.ThrowState.BoardState.ThrowMode == ThrowMode.Decrease ? "Abräumen" : "Volle";
|
||||
}
|
||||
|
|
@ -153,9 +155,9 @@ namespace GameHandler
|
|||
return ThrowCommandParser.Parse(stringData, _gh.FreePlayerSelection(), 0);
|
||||
}
|
||||
|
||||
public async Task<GameState> Load(Guid gameId)
|
||||
public async Task<GameState?> Load(Guid gameId)
|
||||
{
|
||||
Game game = null;
|
||||
Game? game = null;
|
||||
using (var scope = _rootContainer?.BeginLifetimeScope())
|
||||
{
|
||||
var gs = new GameStateHandler(scope.Resolve<IGameRepository>(), scope.Resolve<IExpenseRepository>());
|
||||
|
|
@ -176,6 +178,16 @@ namespace GameHandler
|
|||
return res;
|
||||
}
|
||||
|
||||
public bool FreePlayerSelection => _gh.FreePlayerSelection();
|
||||
public GameState Undo()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public GameState Redo()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace GameHandler.Parser
|
|||
pindata = data;
|
||||
}
|
||||
|
||||
return new ThrowCommandData(playerId, Regex.Match(pindata, @"\d+").Value, data.Contains("b"), data.Contains("s"), data.Contains("e"));
|
||||
return new ThrowCommandData(playerId, Regex.Match(pindata, @"\d+").Value, data.Contains("b"), data.Contains("s"), data.Contains("e"), data.Contains("u"), data.Contains("r"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace GameModel
|
||||
{
|
||||
public record ThrowCommandData(int PlayerId, string Pindata, bool Bell, bool Sink, bool Abort)
|
||||
public record ThrowCommandData(int PlayerId, string Pindata, bool Bell, bool Sink, bool Abort, bool Undo, bool Redo)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,6 +181,20 @@ void StartGameAction(string gameName, Guid gameId)
|
|||
break;
|
||||
}
|
||||
|
||||
if (throwData.Undo)
|
||||
{
|
||||
gameState = _gs.Undo();
|
||||
Show(gameState);
|
||||
break;
|
||||
}
|
||||
|
||||
if (throwData.Redo)
|
||||
{
|
||||
gameState = _gs.Redo();
|
||||
Show(gameState);
|
||||
break;
|
||||
}
|
||||
|
||||
var task = _gs.HandleThrow(PinThrow.Create(throwData.Pindata, throwData.Bell, throwData.Sink, throwData.PlayerId));
|
||||
gameState = task.Result;
|
||||
Show(gameState);
|
||||
|
|
|
|||
Loading…
Reference in New Issue