using GameModel; namespace GameHandler { public class ThrowHandler { public ThrowState Init(ThrowMode throwMode, int ThrowsPerRound) { var picture = PinPicture.Create(); return new ThrowState(new BoardState(throwMode, picture), ThrowsPerRound, 0); } /// /// Bild stellen /// /// /// /// /// public ThrowState SetBoardstatePicture(PinPicture boardstate, ThrowMode throwMode) { throw new NotImplementedException(); } /// /// neu autstellen /// /// /// /// public ThrowState Update(ThrowState throwState, PinThrow pinThrow) { var resetBoard = throwState.ThrowCount + 1 == throwState.ThrowsPerRount; var newBoardState = UpdateBoardState(throwState, pinThrow, resetBoard); var throwCount = resetBoard ? 0 : throwState.ThrowCount + 1; return throwState with { BoardState = newBoardState, ThrowCount = throwCount }; } private static BoardState UpdateBoardState(ThrowState throwState, PinThrow pinThrow, bool resetBoard) { var boardState = throwState.BoardState; if (boardState.ThrowMode == ThrowMode.Reposition) { return boardState with { PinPicture = PinPicture.Create() }; } else { var result = boardState with { PinPicture = boardState.PinPicture + pinThrow }; if (result.PinPicture.UpCount == 0 || resetBoard) { return boardState with { PinPicture = PinPicture.Create() }; } else { return result; } } } } }