Game Development Reference
In-Depth Information
int _tmain(int argc, _TCHAR* argv[])
{
Player player;
WelcomePlayer(player);
return 0;
}
Our program is now much more readable than before. The Player structure will be responsible for
storing all of the data related to our player object; for now we only need to keep track of the player's
name. We pass the player variable by reference to the WelcomePlayer function. This allows us to add
all of the code necessary to welcome our players to a single function and this function can assign
the player's name from cin directly into the Player reference.
Our _tmain function now has code that is almost plain English. This is the goal of our code for the
most part. Code that is human readable is very valuable when writing game programs. A lot of
the code written, especially code to be reused between projects, must be maintained by teams of
programmers. Having code that can be understood just by reading through it reduces the time it
takes to understand and make alterations to the code.
Summary
This chapter has covered the C-style functions and structures you can use while writing programs
in C++. Functions are the basic building blocks that allow us to write procedural programs. We have
learned how to use parameters and return values to help us write readable programs. We've also
looked at how pointers and references can be used to pass data into and out of functions. Finally,
we looked at how we can group variables into structures. Grouping data in this way allows us to
create our own types within the language. These types also aid us in writing programs that other
programmers can easily understand. You saw this put to good effect in our Text Adventure game
when we created a Player structure to group together data relating to our player.
Our programs are beginning to take a real form but they are still limited to carrying out basic
arithmetic. In the next chapter we will look at control flow statements that will allow our programs to
make decisions or repeat tasks over a large set of data.
 
Search WWH ::




Custom Search