Game Development Reference
In-Depth Information
Summary
This chapter has introduced the flow control statements that are a core part of the C++ programming
language. These statements allow us to write game code that creates compelling interactive
experiences for our players. We can use if and switch statements to execute different code paths
depending on the values stored in variables at runtime. These values could be calculated from the
current state of the game or might be obtained from player input. You have also seen how we can
use loops to execute code repetitively. The for loop can be used to carry out an iterative block of
code over a fixed number of iterations and the while loop can be used to continue iterating until
some condition is met. You've also seen how we can use the continue and break keywords to gain
finer control over our loop execution.
We then used what we have learned to build a game loop for our Text Adventure game. We read
input from the player inside a while loop until they enter the option to quit. We used an if statement
to determine if the option the user entered matches the value we have chosen to represent quit.
The next chapter looks at program structure. It will show you how we can split our code across
multiple source files so that we can create projects that are more manageable. So far our program
has been relatively short and we have been working on our own. Professional game projects can
have tens of thousands of files and tens to hundreds of programmers all working at the same time.
You will learn how you can use source and header files, as well as namespaces, to modularize
your code.
 
Search WWH ::




Custom Search