Skip to content

A scoring system for the sport of Bowling.

License

Notifications You must be signed in to change notification settings

borntocompile/bowling-score

Repository files navigation

bowling-score

What is it?

MFG.Bowling is a scoring system for the sport of Bowling.
It calculates all the complicated rules of bowling so you don't have to.
All you need to do is create a player and inform it of what the player scored that "turn".
The API will inform you when a player has completed all thier frames, when all your players have invoked this event your game is complete.

Requirements

Support for Unity 2018.x
The code will run in older versions of Unity, however the assembly definition will not.

API

Player

string Name
Frame[] Frames
int TotalScore

event Action<Frame> OnFrameComplete
event Action OnFramesCompleted

You can create a new player by newing the class Player

var player = new Player(name: "Hazza")

A players score card is made up of a collection of Frames.
Each frame is made up of a collection Rolls.

To apply a score to the Player, simply use

player.Roll(score);

The Player.OnFrameComplete event is available for when a player completes a frame.

player.OnFrameComplete += frame =>
{
    // Set next players turn.
};

Frame

int Index
FrameScoreType ScoreType
List<Roll> Roll
int TotalScore

A game of bowling consists of ten frames.

Roll

int Score FrameScoreType ScoreType

ScoreType

public enum FrameScoreType
{
	Unplayed,
	Strike,
	Spare,
	Standard,
	Miss,
	Foul
}

Example

An example script is included, it can be found at MFG.Bowling.Example
Attach the Example MonoBehaviour to a GameObject in your scene and run the game.
Check the console for the logs of what happened in the game.
A perfectGame option is available to simulate every turn as a strike.