A lot of this lesson is about test-driven development, but you should always remember that automatic testing goes hand-in-hand with manual testing - you need to do both! This became clear to me towards the end of BowlMaster. All of the tests passed, and so I went to play the game to see the scores finally show up on the screen. It was then that I started to see some irregularities - sometimes, but not always, the “roll” score would skip the third box, and the numbers would start to be wrong. At first I thought I might have dragged the wrong Text objects into ScoreDisplay, but that wasn’t it.
I started the debugging journey. I wrote some log files to see what string was being returned from FormatRolls, and the string had the irregularities that were being displayed on the screen. I went a step back to see what rolls were being sent, and that’s when I found that a negative number was being sent for the third bowl. Eventually, tracked it down to the PinsHaveSettled method in PinCounter, where I set a breakpoint and stepped through the code. I finally realized that a race condition was causing lastSettledCount to be reset to 10, and then getting overwritten as lastStandingCount. To fix this problem, I rearranged the code like this:
private void PinsHaveSettled() {
int pinsKnockedDown = lastSettledCount - lastStandingCount;
lastSettledCount = lastStandingCount;
lastStandingCount = -1;
gameManager.Bowl (pinsKnockedDown);
ballLeftBox = false;
standingDisplay.color = Color.green;
}
(i.e. gameManager.Bowl() came after setting the values, in case it ended up calling Reset().) I believe this is how it is in the lecture, but I had been confident enough in my previous code that I had made it all the way to the end of the lecture before realizing there was a bug. Just a friendly reminder to always do a lot of manual testing, and some help if you start seeing this particular issue yourself!