dev
This commit is contained in:
parent
99513fb9a1
commit
4779340cb4
|
|
@ -40,12 +40,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) // TODO: add players
|
public ThrowState 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) // TODO: add players
|
public ThrowState Start(int[] playerIds, IGameSettings gameSettings, string gameName = FreeGameHandler.GAMENAME_FREETRAINING)
|
||||||
{
|
{
|
||||||
if (_isStarted)
|
if (_isStarted)
|
||||||
{
|
{
|
||||||
|
|
@ -58,19 +58,11 @@ namespace GameHandler
|
||||||
|
|
||||||
_th = new ThrowHandler();
|
_th = new ThrowHandler();
|
||||||
|
|
||||||
//var throwMode = GameTypeId == 0 ? ThrowMode.Reposition : ThrowMode.Decrease;
|
|
||||||
//var throwsPerRount = GameTypeId == 0 ? INFINIT_THROWS : 3;
|
|
||||||
|
|
||||||
_lastState = ThrowState.Create(_gh.ThrowMode(), _gh.ThrowsPerRount());
|
_lastState = ThrowState.Create(_gh.ThrowMode(), _gh.ThrowsPerRount());
|
||||||
return _lastState;
|
return _lastState;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//private IGameHandler GetGameHandler(string gameName)
|
|
||||||
//{
|
|
||||||
// throw new NotImplementedException();
|
|
||||||
//}
|
|
||||||
|
|
||||||
public ThrowState HandleThrow(PinThrow pinThrow)
|
public ThrowState HandleThrow(PinThrow pinThrow)
|
||||||
{
|
{
|
||||||
if (!_isStarted)
|
if (!_isStarted)
|
||||||
|
|
@ -78,10 +70,27 @@ namespace GameHandler
|
||||||
throw new InvalidGameStateExcpetion("Game not started");
|
throw new InvalidGameStateExcpetion("Game not started");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pinThrow = AutoCompletePlayerId(pinThrow);
|
||||||
|
|
||||||
_lastState = _th.Update(_lastState, pinThrow);
|
_lastState = _th.Update(_lastState, pinThrow);
|
||||||
return _lastState;
|
return _lastState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PinThrow AutoCompletePlayerId(PinThrow pinThrow)
|
||||||
|
{
|
||||||
|
if (_gh.FreePlayerSelection() && pinThrow.PlayerId == 0)
|
||||||
|
{
|
||||||
|
throw new InvalidPinThrowException("PlayerId connot be 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_gh.FreePlayerSelection())
|
||||||
|
{
|
||||||
|
return pinThrow;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pinThrow with { PlayerId = _gh.GetCurrentPlayerId() };
|
||||||
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
if (!_isStarted)
|
if (!_isStarted)
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@ namespace GameHandler.Parser
|
||||||
if (string.IsNullOrEmpty(data))
|
if (string.IsNullOrEmpty(data))
|
||||||
throw new ArgumentNullException("data");
|
throw new ArgumentNullException("data");
|
||||||
|
|
||||||
if (!withFreePlayerSelection && playerId == 0)
|
if (!withFreePlayerSelection && playerId != 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("playerid required");
|
throw new ArgumentNullException("playerid not selectable");
|
||||||
}
|
}
|
||||||
|
|
||||||
string pindata;
|
string pindata;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
// See https://aka.ms/new-console-template for more information
|
// See https://aka.ms/new-console-template for more information
|
||||||
using CommandLine;
|
using CommandLine;
|
||||||
using GameHandler;
|
using GameHandler;
|
||||||
|
using GameHandler.DeathGame;
|
||||||
using GameHandler.Extensions;
|
using GameHandler.Extensions;
|
||||||
using GameModel;
|
using GameModel;
|
||||||
using GameModel.Contract;
|
using GameModel.Contract;
|
||||||
|
using GameModel.DeathGame;
|
||||||
using KoogleCli.Model;
|
using KoogleCli.Model;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
@ -74,7 +76,7 @@ void NewGameAction()
|
||||||
void StartGameAction(string gameName)
|
void StartGameAction(string gameName)
|
||||||
{
|
{
|
||||||
_gs = new GameService();
|
_gs = new GameService();
|
||||||
var bs = _gs.Start(new[] { 1,2,3,4}, null, gameName );
|
var bs = _gs.Start(new[] { 1,2,3,4}, GetGameSettings(gameName), gameName );
|
||||||
|
|
||||||
|
|
||||||
Show(bs);
|
Show(bs);
|
||||||
|
|
@ -115,6 +117,15 @@ void StartGameAction(string gameName)
|
||||||
ShowMainMenu();
|
ShowMainMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IGameSettings GetGameSettings(string gameName)
|
||||||
|
{
|
||||||
|
if (gameName == DeathGameHandler.GAMENAME_DEATHBOX)
|
||||||
|
{
|
||||||
|
return new DeathGameSettings(6);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
void Show(ThrowState throwState)
|
void Show(ThrowState throwState)
|
||||||
{
|
{
|
||||||
AnsiConsole.Clear();
|
AnsiConsole.Clear();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue