Skip to content

Instantly share code, notes, and snippets.

@Butter1484
Created May 13, 2017 21:00
Show Gist options
  • Save Butter1484/eed1831ba089349f95ee58ef88dfa23b to your computer and use it in GitHub Desktop.
Save Butter1484/eed1831ba089349f95ee58ef88dfa23b to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public static class ScoreMaster {
public static List<int> ScoreFrames(List<int> rolls)
{
List<int> frameList = new List<int>();
for (int i = 0; i < rolls.Count - 1; i+=2)
{
if (rolls[i] != 10)
{
int total = rolls[i] + rolls[i + 1];
//Spare calculation
if (total == 10)
{
if (i + 2 < rolls.Count)
{
total += rolls[i + 2];
}
else
{
continue;
}
}
frameList.Add(total);
}
//Strikes
if (rolls[i] == 10 && frameList.Count < 9)
{
if (i + 2 < rolls.Count)
{
int total = rolls[i] + rolls[i + 1] + rolls[i + 2];
frameList.Add(total);
i--;
continue;
}
else
{
break;
}
}
//Last frame strike
else if (rolls[i] == 10 && frameList.Count == 9)
{
int total = rolls[i] + rolls[i + 1] + rolls[i + 2];
frameList.Add(total);
break;
}
}
return frameList;
}
public static List<int> ScoreCumulative(List<int> rolls)
{
List<int> cumulative = new List<int>();
int total = 0;
foreach(int frameScore in ScoreFrames(rolls))
{
total += frameScore;
cumulative.Add(total);
}
return cumulative;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment