Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. public static string FormatRolls(List<int> rolls){
  2.     string output = "";
  3.    
  4.     for (int i = 0, box = 1; i < rolls.Count; i++) {                               
  5.         if (box >= 19 && rolls [i] == 10) {                                             //Strike in last frame
  6.             output += "X";
  7.             box++;
  8.         } else if ((box > 1 && rolls [i] == 10 && rolls [i - 1] != 0) ||                //Strike in frames 1-9
  9.                   (box == 1 && rolls [i] == 10)) {
  10.             output += "X ";                                                             //Increment 2 since second
  11.             box += 2;                                                                   //bowl in frame isn't needed
  12.         } else if (rolls [i] == 0) {                                                    //Gutterball
  13.             output += "-";
  14.             box++;
  15.         } else if (((box % 2) == 0 || box == 21) && rolls [i - 1] + rolls [i] == 10) {  //Spare
  16.             output += "/";
  17.             box++;
  18.         } else {
  19.             output += rolls [i].ToString ();                                            //1 to 9 pin falls
  20.             box++;
  21.         }
  22.     }
  23.     return output;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement