diff --git a/GameHandler/GameHandler/DeathGameHandler.cs b/GameHandler/GameHandler/DeathGameHandler.cs index b5c0684..8c20695 100644 --- a/GameHandler/GameHandler/DeathGameHandler.cs +++ b/GameHandler/GameHandler/DeathGameHandler.cs @@ -72,14 +72,15 @@ namespace GameHandler.DeathGame return new DeathGameModel(1, coffins.OrderBy(_ => random.Next()).ToList().ToArray(), deathGameSettings, playerIds); } - public IGameModel Update(PinThrow pinThrow, IGameModel gameModel, BoardState boardStateBeforeUpdate) + public IGameModel Update(PinThrow pinThrow, IGameModel gameModel, BoardState boardStateBeforeUpdate, ThrowState throwStateAfterUpdate) { var isTrowIntoAllPins = boardStateBeforeUpdate.PinPicture.UpCount == 9; var boardCleared = pinThrow.IsCleared; - return CalcNextModel(gameModel as DeathGameModel, pinThrow.PinCount, isTrowIntoAllPins, boardCleared); + var firstThrowInRound = throwStateAfterUpdate.ThrowCount == 1; + return CalcNextModel(gameModel as DeathGameModel, pinThrow.PinCount, isTrowIntoAllPins, boardCleared, firstThrowInRound); } - public DeathGameModel CalcNextModel(DeathGameModel gm, int pinCount, bool isTrowIntoAllPins, bool boardCleared) + public DeathGameModel CalcNextModel(DeathGameModel gm, int pinCount, bool isTrowIntoAllPins, bool boardCleared, bool firstThrowInRound) { var current = gm.Coffins.First(); var next = gm.Coffins.Skip(1).First(); @@ -90,7 +91,7 @@ namespace GameHandler.DeathGame if (isTrowIntoAllPins) // into all pins { incX = true; - if (pinCount < 3) + if ((pinCount < 3) && firstThrowInRound) { OnFirstThrowFailed(gm, current); incLine = true; diff --git a/GameHandler/GameHandler/FreeGameHandler.cs b/GameHandler/GameHandler/FreeGameHandler.cs index cac9551..12744fc 100644 --- a/GameHandler/GameHandler/FreeGameHandler.cs +++ b/GameHandler/GameHandler/FreeGameHandler.cs @@ -33,7 +33,7 @@ namespace GameHandler.GameHandler return new FreeGameModel(playerIds, playerIds.First(), throws); } - public IGameModel Update(PinThrow pinThrow, IGameModel gameModel, BoardState boardStateBeforeUpdate) + public IGameModel Update(PinThrow pinThrow, IGameModel gameModel, BoardState boardStateBeforeUpdate, ThrowState throwStateAfterUpdate) { if (gameModel == null) { diff --git a/GameHandler/GameService.cs b/GameHandler/GameService.cs index 525287e..e4665f5 100644 --- a/GameHandler/GameService.cs +++ b/GameHandler/GameService.cs @@ -96,11 +96,11 @@ namespace GameHandler pinThrow = AutoCompletePlayerId(pinThrow); - var throwState = _th.Update(_lastState.ThrowState, pinThrow); - var gameModel = _gh.Update(pinThrow, _lastState.GameModel, boardStateBeforeUpdate); - var expenseModel = _eh.CheckThrow(throwState.BoardState, pinThrow, gameModel.PlayerIds, _lastState.ExpenseModel); + var throwStateAfterUpdate = _th.Update(_lastState.ThrowState, pinThrow); + var gameModel = _gh.Update(pinThrow, _lastState.GameModel, boardStateBeforeUpdate, throwStateAfterUpdate); + var expenseModel = _eh.CheckThrow(throwStateAfterUpdate.BoardState, pinThrow, gameModel.PlayerIds, _lastState.ExpenseModel); - _lastState = _lastState with { ThrowState = throwState, GameModel = gameModel, NextPlayerId = _gh.GetCurrentPlayerId(gameModel), ExpenseModel = expenseModel }; + _lastState = _lastState with { ThrowState = throwStateAfterUpdate, GameModel = gameModel, NextPlayerId = _gh.GetCurrentPlayerId(gameModel), ExpenseModel = expenseModel }; return _lastState ; } diff --git a/GameModel/Contracts/IGameHandler.cs b/GameModel/Contracts/IGameHandler.cs index 6f93bf7..47fe1b0 100644 --- a/GameModel/Contracts/IGameHandler.cs +++ b/GameModel/Contracts/IGameHandler.cs @@ -22,7 +22,8 @@ namespace GameModel.Contract IGameModel InitGameModel(int[] playerIds, IGameSettings gameSettings); int GetCurrentPlayerId(IGameModel gameModel); - IGameModel Update(PinThrow pinThrow, IGameModel gameModel, BoardState boardStateBeforeUpdate); + IGameModel Update(PinThrow pinThrow, IGameModel gameModel, BoardState boardStateBeforeUpdate, + ThrowState throwStateAfterUpdate); event EventHandler GameExpenseOccured; }