When it comes to game programming, C++ is the name of the game. If you aspire to move from game player to game creator, it all starts with learning the fundamentals of C++ and game-programming basics. With BEGINNING C++ THROUGH GAME PROGRAMMING, FOURTH EDITION, you will find an up-to-date and thorough introduction to everything you need to get started—with no previous programming experience required. In the new fourth edition of this popular guide to learning C++, you will work with a complete program while learning each new concept and a game program at the end of each chapter. A final game project at the end of the book draws together everything you’ve learned. Written with the beginning programmer in mind, BEGINNING C++ THROUGH GAME PROGRAMMING, FOURTH EDITION is a great way to get started in game programming Contents Introduction Chapter 1 Types, Variables, and Standard I/O: Lost Fortune Introducing C++ Using C++ for Games Creating an Executable File Dealing with Errors Understanding the ISO Standard Writing Your First C++ Program Introducing the Game Over Program Commenting Code Using Whitespace Including Other Files Defining the main() Function Displaying Text through the Standard Output Terminating Statements Returning a Value from main() Working with the std Namespace Introducing the Game Over 2.0 Program Employing a using Directive Introducing the Game Over 3.0 Program Employing using Declarations Understanding When to Employ using Using Arithmetic Operators Introducing the Expensive Calculator Program Adding, Subtracting, and Multiplying Understanding Integer and Floating Point Division Using the Modulus Operator Understanding Order of Operations Declaring and Initializing Variables Introducing the Game Stats Program Understanding Fundamental Types Understanding Type Modifiers Declaring Variables Naming Variables Assigning Values to Variables Initializing Variables Displaying Variable Values Getting User Input Defining New Names for Types Understanding Which Types to Use Performing Arithmetic Operations with Variables Introducing the Game Stats 2.0 Program Altering the Value of a Variable Using Combined Assignment Operators Using Increment and Decrement Operators Dealing with Integer Wrap Around Working with Constants Introducing the Game Stats 3.0 Program Using Constants Using Enumerations Introducing Lost Fortune Setting Up the Program Getting Information from the Player Telling the Story Summary Questions and Answers Discussion Questions Exercises Chapter 2 Truth, Branching, and the Game Loop: Guess My Number Understanding Truth Using the if Statement Introducing the Score Rater Program Testing true and false Interpreting a Value as true or false Using Relational Operators Nesting if Statements Using the else Clause Introducing the Score Rater 2.0 Program Creating Two Ways to Branch Using a Sequence of if Statements with else Clauses Introducing the Score Rater 3.0 Program Creating a Sequence of if Statements with else Clauses Using the switch Statement Introducing the Menu Chooser Program Creating Multiple Ways to Branch Using while Loops Introducing the Play Again Program Looping with a while Loop Using do Loops Introducing the Play Again 2.0 Program Looping with a do Loop Using break and continue Statements Introducing the Finicky Counter Program Creating a while (true) Loop Using the break Statement to Exit a Loop Using the continue Statement to Jump Back to the Top of a Loop Understanding When to Use break and continue Using Logical Operators Introducing the Designers Network Program Using the Logical AND Operator Using the Logical OR Operator Using the Logical NOT Operator Understanding Order of Operations Generating Random Numbers Introducing the Die Roller Program Calling the rand() Function Seeding the Random Number Generator Calculating a Number within a Range Understanding the Game Loop Introducing Guess My Number Applying the Game Loop Setting Up the Game Creating the Game Loop Wrapping Up the Game Summary Questions and Answers Discussion Questions Exercises Chapter 3 For Loops, Strings, and Arrays: Word Jumble Using for Loops Introducing the Counter Program Counting with for Loops Using Empty Statements in for Loops Nesting for Loops Understanding Objects Using String Objects Introducing the String Tester Program Creating string Objects Concatenating string Objects Using the size() Member Function Indexing a string Object Iterating through string Objects Using the find() Member Function Using the erase() Member Function Using the empty() Member Function Using Arrays Introducing the Hero's Inventory Program Creating Arrays Indexing Arrays Accessing Member Functions of an Array Element Being Aware of Array Bounds Understanding C-Style Strings Using Multidimensional Arrays Introducing the Tic-Tac-Toe Board Program Creating Multidimensional Arrays Indexing Multidimensional Arrays Introducing Word Jumble Setting Up the Program Picking a Word to Jumble Jumbling the Word Welcoming the Player Entering the Game Loop Saying Goodbye Summary Questions and Answers Discussion Questions Exercises Chapter 4 The Standard Template Library: Hangman Introducing the Standard Template Library Using Vectors Introducing the Hero's Inventory 2.0 Program Preparing to Use Vectors Declaring a Vector Using the push_back() Member Function Using the size() Member Function Indexing Vectors Calling Member Functions of an Element Using the pop_back() Member Function Using the clear() Member Function Using the empty() Member Function Using Iterators Introducing the Hero's Inventory 3.0 Program Declaring Iterators Looping through a Vector Changing the Value of a Vector Element Accessing Member Functions of a Vector Element Using the insert() Vector Member Function Using the erase() Vector Member Function Using Algorithms Introducing the High Scores Program Preparing to Use Algorithms Using the find() Algorithm Using the random_shuffle() Algorithm Using the sort() Algorithm Understanding Vector Performance Examining Vector Growth Examining Element Insertion and Deletion Examining Other STL Containers Planning Your Programs Using Pseudocode Using Stepwise Refinement Introducing Hangman Planning the Game Setting Up the Program Initializing Variables and Constants Entering the Main Loop Getting the Player's Guess Ending the Game Summary Questions and Answers Discussion Questions Exercises Chapter 5 Functions: Mad Lib Creating Functions Introducing the Instructions Program Declaring Functions Defining Functions Calling Functions Understanding Abstraction Using Parameters and Return Values Introducing the Yes or No Program Returning a Value Accepting Values into Parameters Understanding Encapsulation Understanding Software Reuse Working with Scopes Introducing the Scoping Program Working with Separate Scopes Working with Nested Scopes Using Global Variables Introducing the Global Reach Program Declaring Global Variables Accessing Global Variables Hiding Global Variables Altering Global Variables Minimizing the Use of Global Variables Using Global Constants Using Default Arguments Introducing the Give Me a Number Program Specifying Default Arguments Assigning Default Arguments to Parameters Overriding Default Arguments Overloading Functions Introducing the Triple Program Creating Overloaded Functions Calling Overloaded Functions Inlining Functions Introducing the Taking Damage Program Specifying Functions for Inlining Calling Inlined Functions Introducing the Mad Lib Game Setting Up the Program The main() Function The askText() Function The askNumber() Function The tellStory() Function Summary Questions and Answers Discussion Questions Exercises Chapter 6 References: Tic-Tac-Toe Using References Introducing the Referencing Program Creating References Accessing Referenced Values Altering Referenced Values Passing References to Alter Arguments Introducing the Swap Program Passing by Value Passing by Reference Passing References for Efficiency Introducing the Inventory Displayer Program Understanding the Pitfalls of Reference Passing Declaring Parameters as Constant References Passing a Constant Reference Deciding How to Pass Arguments Returning References Introducing the Inventory Referencer Program Returning a Reference Displaying the Value of a Returned Reference Assigning a Returned Reference to a Reference Assigning a Returned Reference to a Variable Altering an Object through a Returned Reference Introducing the Tic-Tac-Toe Game Planning the Game Setting Up the Program The main() Function The instructions() Function The askYesNo() Function The askNumber() Function The humanPiece() Function The opponent() Function The displayBoard() Function The winner() Function The isLegal() Function The humanMove() Function The computerMove() Function The announceWinner() Function Summary Questions and Answers Discussion Questions Exercises Chapter 7 Pointers: Tic-Tac-Toe 2.0 Understanding Pointer Basics Introducing the Pointing Program Declaring Pointers Initializing Pointers Assigning Addresses to Pointers Dereferencing Pointers Reassigning Pointers Using Pointers to Objects Understanding Pointers and Constants Using a Constant Pointer Using a Pointer to a Constant Using a Constant Pointer to a Constant Summarizing Constants and Pointers Passing Pointers Introducing the Swap Pointer Version Program Passing by Value Passing a Constant Pointer Returning Pointers Introducing the Inventory Pointer Program Returning a Pointer Using a Returned Pointer to Display a Value Assigning a Returned Pointer to a Pointer Assigning to a Variable the Value Pointed to by a Returned Pointer Altering an Object through a Returned Pointer Understanding the Relationship between Pointers and Arrays Introducing the Array Passer Program Using an Array Name as a Constant Pointer Passing and Returning Arrays Introducing the Tic-Tac-Toe 2.0 Game Summary Questions and Answers Discussion Questions Exercises Chapter 8 Classes: Critter Caretaker Defining New Types Introducing the Simple Critter Program Defining a Class Defining Member Functions Instantiating Objects Accessing Data Members Calling Member Functions Using Constructors Introducing the Constructor Critter Program Declaring and Defining a Constructor Calling a Constructor Automatically Setting Member Access Levels Introducing the Private Critter Program Specifying Public and Private Access Levels Defining Accessor Member Functions Defining Constant Member Functions Using Static Data Members and Member Functions Introducing the Static Critter Program Declaring and Initializing Static Data Members Accessing Static Data Members Declaring and Defining Static Member Functions Calling Static Member Functions Introducing the Critter Caretaker Game Planning the Game Planning the Pseudocode The Critter Class The main() Function Summary Questions and Answers Discussion Questions Exercises Chapter 9 Advanced Classes and Dynamic Memory: Game Lobby Using Aggregation Introducing the Critter Farm Program Using Object Data Members Using Container Data Members Using Friend Functions and Operator Overloading Introducing the Friend Critter Program Creating Friend Functions Overloading Operators Dynamically Allocating Memory Introducing the Heap Program Using the new Operator Using the delete Operator Avoiding Memory Leaks Working with Data Members and the Heap Introducing the Heap Data Member Program Declaring Data Members that Point to Values on the Heap Declaring and Defining Destructors Declaring and Defining Copy Constructors Overloading the Assignment Operator Introducing the Game Lobby Program The Player Class The Lobby Class The Lobby::AddPlayer() Member Function The Lobby::RemovePlayer() Member Function The Lobby::Clear() Member Function The operator