We will design the framework based on functional programming. The framework will do all non-pure work, so that the rest of the application can be built with pure functions (except for Math.random
).
Tip
Strictly speaking, Math.random
is not a pure function. Given that Math.random()
is not always equal to Math.random()
, that function will update some internal state.
In pure functional languages, such a function can still exist. That function takes a state and returns a random number and a new state. Since every call to random will get a different state, it can return different random values.
A game consists of an event loop. The amount of iterations that this loop does per second is called FPS or frames per second. Every step of the loop, the game state needs to be updated. For instance, enemies and the player can move, and the player can eat dots in Pac Man. At the end of each step, the game state must be redrawn.
The game must also handle user input. When the user presses...