Fly Catch Revisited
In the control flow chapter we got started building a small game. The logic for this was all contained within the main function. With functions and procedures we can start to think about breaking this down.
Looking at the game code we can identify steps to update game, handle input, and draw game. The challenge at the moment is that many of these require us to change values in a number of variables. We do not currently have the tools to do this within separate procedures (but that will come in a couple of chapters).
For now, we can move the steps for draw game into a procedure. This will help us get started organising this, and we can progress toward more organised code as we learn some new tools and techniques.
Draw Game
We have the code for draw game outlined in our logic, so this should be a simple copy and paste action. You then need to add in the parameters that will tell draw game the details that it needs. You should end up with something like this:
Have a go at coding this. The code in main is still too long to make it really understandable, but we are making progress. With just a few more tools we will have this all under control. So let’s wrap this chapter up, so you can move on to the next step, where we can start to organise our data.