Skip to content

Instantly share code, notes, and snippets.

@erikdietrich
Created November 8, 2012 20:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save erikdietrich/4041192 to your computer and use it in GitHub Desktop.
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