KoogleV4/GameHandler/ThrowHandler.cs

63 lines
2.1 KiB
C#

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);
}
/// <summary>
/// Bild stellen
/// </summary>
/// <param name="boardstate"></param>
/// <param name="throwMode"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public ThrowState SetBoardstatePicture(PinPicture boardstate, ThrowMode throwMode)
{
throw new NotImplementedException();
}
/// <summary>
/// neu autstellen
/// </summary>
/// <param name="currentState"></param>
/// <param name="pinThrow"></param>
/// <returns></returns>
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;
}
}
}
}
}