Declaring and Initializing the Sub' Hunter Variables
We know lots about variables, types and how to manipulate them but we haven't considered what variables and types the Sub' Hunter game will need. It will help to first consider all the different values and types we need to keep track of and manipulate, then we can come up with a list of names and types before actually adding the declaration code to the project. After that, we will initialize the variables.
Planning the variables
Let's have a think about what our game needs to keep track of. This will dictate the variables, types, and names that we will declare.
- We need to know how many pixels wide and high the screen is comprised of. We will call these variables
numberHorizontalPixels
andnumberVerticalPixels
. They will be of typeint
. - Once we have calculated the size (in pixels) of one block on the game grid we will want to remember it. We will use an
int
variable calledblockSize
. - If we have the size of each block we...