KoogleV4/GameModel/PinThrow.cs

50 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GameModel
{
public record PinThrow(int PlayerId, PinPicture PicPicture, bool IsBell, bool IsSink)
{
public bool IsCircle => !IsSink && PicPicture.DownCount == 8 && (PicPicture.PinState5 == PinState.Up);
public bool IsNinePins => !IsSink && PinCount == 9;
/// <summary>
/// Count of hit pins with this throw
/// </summary>
public int PinCount => IsSink ? 0 : PicPicture.DownCount;
public bool IsNoWood => PicPicture.DownCount == 0 && !IsSink;
public bool IsCleared => PicPicture.UpCount == 0 && !IsSink;
public static PinThrow Create(int playerId, PinPicture picPicture, bool isBell, bool isSink)
{
return new PinThrow(playerId, picPicture, isBell, isSink);
}
public static PinThrow Create(int PlayerId, bool IsBell, bool IsSink)
{
var p = PinPicture.Create();
return Create(PlayerId, p, IsBell, IsSink);
}
public static PinThrow Create(string pindata, bool isBell, bool isSink, int playerId)
{
if (!string.IsNullOrEmpty(pindata))
{
if (!int.TryParse(pindata, out int dummy))
{
throw new InvalidDataException($"{pindata} cannot be parsed as throw");
}
}
var pic = PinPicture.Create(pindata);
return PinThrow.Create(playerId, pic, isBell, isSink);
}
}
}