Win State Added
Each time a piece is filled, the checkWinner method is called which loops through the board array, and returns true if all of the GamePieceLight objects are filled. Learned that “is” is the equivalent of “instanceof” in Java, which I use to determine if the piece at a given cell is a GamePieceLight type. Created method to return the number of pieces on the board. The fewer pieces used, the higher the score. Created method to return the luminosity of all lights on the board, which is the sum of the Elex values of all the GamePieceLight objects in the board array. The higher the value, the more points. A perfect bonus is awarded if the luminosity value is sum of all the bust values of all the lights. Added bust instance variable to the GamePieceLight object and added a getter method. Created drawWinner method which displays the end of level statistics, which the player is graded upon. I think I’ll just use the classic S, A, B, C leveling system for now, and I will need to set point values for each grade in each level. The drawWinner method is only called if the hasWon variable is true. Later, I will also add the level time as a third statistic which the player can earn points. However, this may not be a good stat since time is somewhat related to the pieces used.
When the user has completed the level, a confirm button press will create a new GameLevel object instance, which will start a new level. For now, it is just the same level, but in the future the level layouts will be different, and the GameLevel constructor will probably take an ID parameter that determines which level will be loaded.
For the first test, I set the bust values for all the lights to 8, which is the same value as the starting wire. Therefore, I got a perfect score for just connecting all the lights without any resistors. Next, I used a few resistors to lower the overall luminosity value. It correctly returned the sum of the luminosity of all the lights which was 20 (6 for the first two lights, and 4 for the lower two lights), so I didn’t get a perfect luminosity score this time which required 32.
Luminosity and Bust values displayed
Added the bust numbers to the lights in red when the light is not filled. When the light has filled, the number changes to its luminosity value and is displayed in blue.