dev
This commit is contained in:
parent
4779340cb4
commit
aadac068b5
|
|
@ -49,11 +49,11 @@ namespace GameHandler.UnitTests
|
||||||
{
|
{
|
||||||
GameService service = new GameService();
|
GameService service = new GameService();
|
||||||
var ts1 = service.Start(DeathGameHandler.GAMENAME_DEATHBOX);
|
var ts1 = service.Start(DeathGameHandler.GAMENAME_DEATHBOX);
|
||||||
var bs1 = ts1.BoardState;
|
var bs1 = ts1.ThrowState.BoardState;
|
||||||
|
|
||||||
var pinThrow = PinThrow.Create(1,PinPicture.Create(1,PinState.Down), false, false);
|
var pinThrow = PinThrow.Create(1,PinPicture.Create(1,PinState.Down), false, false);
|
||||||
var ts2 = service.HandleThrow(pinThrow);
|
var ts2 = service.HandleThrow(pinThrow);
|
||||||
var bs2 = ts2.BoardState;
|
var bs2 = ts2.ThrowState.BoardState;
|
||||||
|
|
||||||
|
|
||||||
Assert.That(bs2, Is.Not.EqualTo(bs1));
|
Assert.That(bs2, Is.Not.EqualTo(bs1));
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,13 @@ namespace GameHandler.DeathGame
|
||||||
public ThrowMode ThrowMode() => GameModel.ThrowMode.Decrease;
|
public ThrowMode ThrowMode() => GameModel.ThrowMode.Decrease;
|
||||||
|
|
||||||
public bool FreePlayerSelection() => false;
|
public bool FreePlayerSelection() => false;
|
||||||
|
|
||||||
|
public int GetCurrentPlayerId(IGameModel gameModel)
|
||||||
|
{
|
||||||
|
var gm = gameModel as DeathGameModel;
|
||||||
|
return gm.Coffins.First().PlayerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ThrowsPerRount() => 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,15 @@ namespace GameHandler.GameHandler
|
||||||
return GAMENAME_FREETRAINING;
|
return GAMENAME_FREETRAINING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int GetCurrentPlayerId(IGameModel gameModel)
|
||||||
|
{
|
||||||
|
var gm = gameModel as FreeGameModel;
|
||||||
|
return gm.PlayerIds.First();
|
||||||
|
}
|
||||||
|
|
||||||
public IGameModel InitGameModel(int[] playerIds, IGameSettings gameSettings)
|
public IGameModel InitGameModel(int[] playerIds, IGameSettings gameSettings)
|
||||||
{
|
{
|
||||||
return new FreeGameModel();
|
return new FreeGameModel(playerIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ using GameHandler.GameHandler;
|
||||||
using GameHandler.Parser;
|
using GameHandler.Parser;
|
||||||
using GameModel.Contract;
|
using GameModel.Contract;
|
||||||
using GameModel.DeathGame;
|
using GameModel.DeathGame;
|
||||||
|
using GameModel.Contracts;
|
||||||
|
|
||||||
namespace GameHandler
|
namespace GameHandler
|
||||||
{
|
{
|
||||||
|
|
@ -19,7 +20,7 @@ namespace GameHandler
|
||||||
private bool _isStarted = false;
|
private bool _isStarted = false;
|
||||||
private IGameHandler _gh;
|
private IGameHandler _gh;
|
||||||
private ThrowHandler _th;
|
private ThrowHandler _th;
|
||||||
private ThrowState _lastState;
|
private GameState _lastState;
|
||||||
|
|
||||||
public GameService()
|
public GameService()
|
||||||
{
|
{
|
||||||
|
|
@ -32,7 +33,7 @@ namespace GameHandler
|
||||||
{
|
{
|
||||||
if (_lastState != null)
|
if (_lastState != null)
|
||||||
{
|
{
|
||||||
return _lastState.BoardState.ThrowMode == ThrowMode.Decrease ? "Abräumen" : "Volle";
|
return _lastState.ThrowState.BoardState.ThrowMode == ThrowMode.Decrease ? "Abräumen" : "Volle";
|
||||||
}
|
}
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
@ -40,12 +41,12 @@ namespace GameHandler
|
||||||
|
|
||||||
static int[] defaultPlayerIds => new[] {1,2,3,4};
|
static int[] defaultPlayerIds => new[] {1,2,3,4};
|
||||||
|
|
||||||
public ThrowState Start(string gameName = FreeGameHandler.GAMENAME_FREETRAINING)
|
public GameState Start(string gameName = FreeGameHandler.GAMENAME_FREETRAINING)
|
||||||
{
|
{
|
||||||
return Start(defaultPlayerIds, new DeathGameSettings(6), gameName);
|
return Start(defaultPlayerIds, new DeathGameSettings(6), gameName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ThrowState Start(int[] playerIds, IGameSettings gameSettings, string gameName = FreeGameHandler.GAMENAME_FREETRAINING)
|
public GameState Start(int[] playerIds, IGameSettings gameSettings, string gameName = FreeGameHandler.GAMENAME_FREETRAINING)
|
||||||
{
|
{
|
||||||
if (_isStarted)
|
if (_isStarted)
|
||||||
{
|
{
|
||||||
|
|
@ -58,12 +59,13 @@ namespace GameHandler
|
||||||
|
|
||||||
_th = new ThrowHandler();
|
_th = new ThrowHandler();
|
||||||
|
|
||||||
_lastState = ThrowState.Create(_gh.ThrowMode(), _gh.ThrowsPerRount());
|
var throwState = ThrowState.Create(_gh.ThrowMode(), _gh.ThrowsPerRount());
|
||||||
|
_lastState = GameState.Create(throwState, _gh.GetCurrentPlayerId(gm), gm);
|
||||||
return _lastState;
|
return _lastState;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ThrowState HandleThrow(PinThrow pinThrow)
|
public GameState HandleThrow(PinThrow pinThrow)
|
||||||
{
|
{
|
||||||
if (!_isStarted)
|
if (!_isStarted)
|
||||||
{
|
{
|
||||||
|
|
@ -72,8 +74,9 @@ namespace GameHandler
|
||||||
|
|
||||||
pinThrow = AutoCompletePlayerId(pinThrow);
|
pinThrow = AutoCompletePlayerId(pinThrow);
|
||||||
|
|
||||||
_lastState = _th.Update(_lastState, pinThrow);
|
var throwState = _th.Update(_lastState.ThrowState, pinThrow);
|
||||||
return _lastState;
|
_lastState = _lastState with { ThrowState = throwState };
|
||||||
|
return _lastState ;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PinThrow AutoCompletePlayerId(PinThrow pinThrow)
|
private PinThrow AutoCompletePlayerId(PinThrow pinThrow)
|
||||||
|
|
@ -87,8 +90,8 @@ namespace GameHandler
|
||||||
{
|
{
|
||||||
return pinThrow;
|
return pinThrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pinThrow with { PlayerId = _gh.GetCurrentPlayerId() };
|
return pinThrow with { PlayerId = _gh.GetCurrentPlayerId(_lastState.GameModel) };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
|
|
@ -102,7 +105,7 @@ namespace GameHandler
|
||||||
|
|
||||||
public ThrowCommandData ParseThrowData(string stringData)
|
public ThrowCommandData ParseThrowData(string stringData)
|
||||||
{
|
{
|
||||||
return ThrowCommandParser.Parse(stringData, _gh.FreePlayerSelection(), 0); // TOOD: Player
|
return ThrowCommandParser.Parse(stringData, _gh.FreePlayerSelection(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool FreePlayerSelection => _gh.FreePlayerSelection();
|
public bool FreePlayerSelection => _gh.FreePlayerSelection();
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ namespace GameModel.Contract
|
||||||
|
|
||||||
bool FreePlayerSelection() => true;
|
bool FreePlayerSelection() => true;
|
||||||
IGameModel InitGameModel(int[] playerIds, IGameSettings gameSettings);
|
IGameModel InitGameModel(int[] playerIds, IGameSettings gameSettings);
|
||||||
int GetCurrentPlayerId();
|
int GetCurrentPlayerId(IGameModel gameModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,6 @@ using System.Threading.Tasks;
|
||||||
namespace GameModel.Contracts
|
namespace GameModel.Contracts
|
||||||
{
|
{
|
||||||
public interface IGameModel
|
public interface IGameModel
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace GameModel.FreeGame
|
namespace GameModel.FreeGame
|
||||||
{
|
{
|
||||||
public record FreeGameModel : IGameModel
|
public record FreeGameModel(int[] PlayerIds) : IGameModel
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
using GameModel.Contracts;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GameModel
|
||||||
|
{
|
||||||
|
public record GameState(ThrowState ThrowState, int NextPlayerId, IGameModel GameModel)
|
||||||
|
{
|
||||||
|
public static GameState Create(ThrowState throwState, int nextPlayerId, IGameModel gm)
|
||||||
|
{
|
||||||
|
return new GameState(throwState, nextPlayerId, gm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -83,7 +83,7 @@ void StartGameAction(string gameName)
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
var proptText = _gs.FreePlayerSelection ? $"Spieler,Wurf [yellow]{bs.ThrowCount + 1}[/]:" : $"Wurf [yellow]{bs.ThrowCount + 1}[/]";
|
var proptText = _gs.FreePlayerSelection ? $"Spieler,Wurf [yellow]{bs.ThrowState.ThrowCount + 1}[/]:" : $"Wurf [yellow]{bs.ThrowState.ThrowCount + 1}[/]";
|
||||||
|
|
||||||
var stringData = AnsiConsole.Prompt(
|
var stringData = AnsiConsole.Prompt(
|
||||||
new TextPrompt<string>(proptText)
|
new TextPrompt<string>(proptText)
|
||||||
|
|
@ -126,14 +126,14 @@ IGameSettings GetGameSettings(string gameName)
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Show(ThrowState throwState)
|
void Show(GameState gameState)
|
||||||
{
|
{
|
||||||
AnsiConsole.Clear();
|
AnsiConsole.Clear();
|
||||||
|
|
||||||
ShowPlayer();
|
ShowPlayer();
|
||||||
|
|
||||||
ShowThrow(throwState);
|
ShowThrow(gameState.ThrowState);
|
||||||
ShowBoard(throwState.BoardState);
|
ShowBoard(gameState.ThrowState.BoardState);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue