using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GameModel.FreeGame { public record FreeGameThrow(int PlayerId, int PinCount, int CircleCount, int SinkCount, int StrikeCount, int ClearedCount, int ThrowCount, int BellCount) { public static FreeGameThrow Create(int playerId) { return new FreeGameThrow(playerId, 0, 0, 0, 0, 0, 0, 0); } public static FreeGameThrow operator +(FreeGameThrow model, PinThrow pinThrow) { if (model.PlayerId != pinThrow.PlayerId) { throw new FreeGameThrowExcepetion("invalid Player id"); } return model with { PinCount = model.PinCount + pinThrow.PinCount, BellCount = model.BellCount + (pinThrow.IsBell ? 1 : 0), CircleCount = model.CircleCount + (pinThrow.IsCircle ? 1 : 0), SinkCount = model.SinkCount + (pinThrow.IsSink ? 1 : 0), StrikeCount = model.StrikeCount + (pinThrow.IsSink ? 1 : 0), ThrowCount = model.ThrowCount + 1, ClearedCount = model.ClearedCount + ( pinThrow.IsCleared ? 1 : 0), }; } } }