Chapter 17: Switch Statements to the Rescue
Switch Statements are used if we wish to add more power-ups later on in our game(s). Conditional statements will eventually add clutter in our code and Switch Statements will help us avoid that.
The game being made currently has 3 power-up Triple Shot, Speed Boost and Shield which are _powerupIDs called cases. The cases will be numbered off starting with 0 and not 1 like most would think. In coding 0 is considered a number. Then each case in each Switch Statement that's ended need to follow with the keyword break;. Also adding a default case for if a _powerUpID passed through that is not 0, 1 or 2, it performs specific code.
Now with this the game will still accomplishes what it did before but, now more efficient and much easier to read.