The frame class
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
namespace ScratchPadTest | |
{ | |
public class Frame | |
{ | |
public static Frame Strike { get { return new Frame(10, 0); } } | |
public class UnderflowException : Exception { } | |
public class OverflowException : Exception { } | |
protected const int Mark = 10; | |
public int FirstThrow { get; protected set; } | |
public int SecondThrow { get; protected set; } | |
public virtual int Total { get { return FirstThrow + SecondThrow; } } | |
public bool IsStrike { get { return FirstThrow == Frame.Mark; } } | |
public bool IsSpare { get { return !IsStrike && Total == Frame.Mark; } } | |
protected Frame() { } | |
public Frame(int firstThrow, int secondThrow) | |
{ | |
if (firstThrow < 0 || secondThrow < 0) | |
throw new UnderflowException(); | |
if (firstThrow + secondThrow > Mark) | |
throw new OverflowException(); | |
FirstThrow = firstThrow; | |
SecondThrow = secondThrow; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment