… if not for the fact that I didn’t know you could access Lists like arrays, which ended up giving me the most DISGUSTING CODE. I spent about four days stressing over this challenge, but I can see why people like TDD.
And yes, I know my comments are a bit useless but i’m just posting this so you can laugh
.
foreach (int roll in rolls) {
if (i % 2 == 0) { //First part of frame.
if (rolledMultiStrike && i != 20) { //Deal multistrike.
frameList.Add(20 + roll);
rolledMultiStrike = false;
}
if (tempVal + roll == 20) { //Detect Multistrike.
rolledMultiStrike = true;
}
if (rolledSpare) { // Deal spare
frameList.Add(10 + roll);
}
if (i == 20 && rolledStrikeInLastFrame) {
frameList.Add(10 + tempVal + roll);
} else if (roll == 10 && i != 20) { //Handle a strike.
if (i == 18) {
rolledStrikeInLastFrame = true;
} else {
rolledStrike = true;
}
if (i == 18 || i == 20) {
i++;
} else {
i += 2;
}
} else if (i == 20 && ! rolledSpare){
frameList.Add(tempVal+roll);
} else { //Handle normal bowl.
i++;
}
rolledSpare = false;
tempVal = roll;
} else if (i % 2 != 0) { //Last part of frame.
if (rolledStrike) { //Handle a strike
frameList.Add(10 + tempVal + roll);
rolledStrike = false;
}
if (tempVal + roll == 10) { //Detect a spare for next frame.
rolledSpare = true;
} else if (! rolledStrike && ! rolledStrikeInLastFrame){ //Otherwise treat as reg roll.
frameList.Add(tempVal + roll);
}
if (rolledStrikeInLastFrame) {
tempVal = roll;
}
i++;
}
}
return frameList;
}