7
Basics of Classes and Objects
The point of computing is to process data. We often encapsulate the processing and the data into a single definition. We can organize objects into classes with a common collection of attributes to define their internal state and common behavior. Each instance of a class is a distinct object with unique internal state and behavior.
This concept of state and behavior applies particularly well to the way games work. When building something like an interactive game, the user’s actions update the game state. Each of the player’s possible actions is a method to change the state of the game. In many games this leads to a lot of animation to show the transition from state to state. In a single-player arcade-style game, the enemies or opponents will often be separate objects, each with an internal state that changes based on other enemy actions and the player’s actions.
On the other hand, if we consider a card or dice game...