Created
September 28, 2015 04:11
-
-
Save joshalanwagner/3aced80260cbedbdec56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static List<int> ScoreFrames (List<int> score) | |
| { | |
| List<int> frame = new List<int> (); | |
| List<string> result = new List<string> (); | |
| bool ball1 = true; | |
| for (int thisRoll = 0; thisRoll < score.Count; thisRoll++) | |
| { | |
| if (ball1 && score[thisRoll] == 10) {result.Add ("strike");} | |
| else if (!ball1 && (score[thisRoll - 1] + score[thisRoll] == 10)) {result.Add ("spare");} | |
| else {result.Add ("");} | |
| if (thisRoll > 1 && (result[thisRoll - 2] == "strike" || (ball1 && result[thisRoll - 1] == "spare"))) | |
| { | |
| frame.Add (score[thisRoll] + score[thisRoll - 1] + score[thisRoll - 2]); | |
| } | |
| if (result[thisRoll] == "" && !ball1 && frame.Count != 10) | |
| { | |
| frame.Add (score[thisRoll] + score[thisRoll - 1]); | |
| } | |
| if (ball1 && (result[thisRoll] == "" || frame.Count == 10)) {ball1 = false;} | |
| else {ball1 = true;} | |
| } | |
| return frame; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment