logo资料库

Beginning C++ Through Game Programming(4th) 无水印pdf.pdf

第1页 / 共447页
第2页 / 共447页
第3页 / 共447页
第4页 / 共447页
第5页 / 共447页
第6页 / 共447页
第7页 / 共447页
第8页 / 共447页
资料共447页,剩余部分请下载后查看
Cover
Copyright
Acknowledgments
About the Author
Contents
Introduction
1 Types, Variables, and Standard I/O: Lost Fortune
Introducing C++
Writing Your First C++ Program
Working with the std Namespace
Using Arithmetic Operators
Declaring and Initializing Variables
Performing Arithmetic Operations with Variables
Working with Constants
Introducing Lost Fortune
Summary
Questions and Answers
Discussion Questions
Exercises
2 Truth, Branching, and the Game Loop: Guess My Number
Understanding Truth
Using the if Statement
Using the else Clause
Using a Sequence of if Statements with else Clauses
Using the switch Statement
Using while Loops
Using do Loops
Using break and continue Statements
Using Logical Operators
Generating Random Numbers
Understanding the Game Loop
Introducing Guess My Number
Summary
Questions and Answers
Discussion Questions
Exercises
3 for Loops, Strings, and Arrays: Word Jumble
Using for Loops
Understanding Objects
Using string Objects
Using Arrays
Understanding C-Style Strings
Using Multidimensional Arrays
Introducing Word Jumble
Summary
Questions and Answers
Discussion Questions
Exercises
4 The Standard Template Library: Hangman
Introducing the Standard Template Library
Using Vectors
Using Iterators
Using Algorithms
Understanding Vector Performance
Examining Other STL Containers
Planning Your Programs
Introducing Hangman
Summary
Questions and Answers
Discussion Questions
Exercises
5 Functions: Mad Lib
Creating Functions
Using Parameters and Return Values
Understanding Software Reuse
Working with Scopes
Using Global Variables
Using Global Constants
Using Default Arguments
Overloading Functions
Inlining Functions
Introducing the Mad Lib Game
Summary
Questions and Answers
Discussion Questions
Exercises
6 References: Tic-Tac-Toe
Using References
Passing References to Alter Arguments
Passing References for Efficiency
Deciding How to Pass Arguments
Returning References
Introducing the Tic-Tac-Toe Game
Summary
Questions and Answers
Discussion Questions
Exercises
7 Pointers: Tic-Tac-Toe 2.0
Understanding Pointer Basics
Understanding Pointers and Constants
Passing Pointers
Returning Pointers
Understanding the Relationship between Pointers and Arrays
Introducing the Tic-Tac-Toe 2.0 Game
Summary
Questions and Answers
Discussion Questions
Exercises
8 Classes: Critter Caretaker
Defining New Types
Using Constructors
Setting Member Access Levels
Using Static Data Members and Member Functions
Introducing the Critter Caretaker Game
Summary
Questions and Answers
Discussion Questions
Exercises
9 Advanced Classes and Dynamic Memory: Game Lobby
Using Aggregation
Using Friend Functions and Operator Overloading
Dynamically Allocating Memory
Working with Data Members and the Heap
Introducing the Game Lobby Program
Summary
Questions and Answers
Discussion Questions
Exercises
10 Inheritance and Polymorphism: Blackjack
Introducing Inheritance
Controlling Access under Inheritance
Calling and Overriding Base Class Member Functions
Using Overloaded Assignment Operators and Copy Constructors in Derived Classes
Introducing Polymorphism
Using Abstract Classes
Introducing the Blackjack Game
Summary
Questions and Answers
Discussion Questions
Exercises
Appendix A Creating Your First C++ Program
Appendix B Operator Precedence
Appendix C Keywords
Appendix D ASCII Chart
Appendix E Escape Sequences
Index
BEGINNING C++ THROUGH GAME PROGRAMMING, FOURTH EDITION MICHAEL DAWSON Cengage Learning PTR 2
Beginning C++ Through Game Programming, Fourth Edition Michael Dawson Publisher and General Manager, Cengage Learning PTR: Stacy L. Hiquet Associate Director of Marketing: Sarah Panella Manager of Editorial Services: Heather Talbot Senior Marketing Manager: Mark Hughes Senior Product Manager: Emi Smith Project Editor: Dan Foster, Scribe Tribe Technical Reviewer: Joshua Smith Interior Layout Tech: MPS Limited Cover Designer: Mike Tanamachi Proofreader and Indexer: Kelly Talbot © 2015 Cengage Learning PTR. CENGAGE and CENGAGE LEARNING are registered trademarks of Cengage Learning, Inc., within the United States and certain other jurisdictions. ALL RIGHTS RESERVED. No part of this work covered by the copyright herein may be reproduced, transmitted, stored, or used in any form or by any means graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, information networks, or information storage and retrieval systems, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the publisher. For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706. 3
For permission to use material from this text or product, submit all requests online at cengage.com/permissions. Further permissions questions can be emailed to permissionrequest@cengage.com. All trademarks are the property of their respective owners. All images © Cengage Learning unless otherwise noted. Library of Congress Control Number: 2014939190 ISBN-13: 978-1-305-10991-9 ISBN-10: 1-305-10991-0 eISBN-10: 1-305-10992-9 Cengage Learning PTR 20 Channel Center Street Boston, MA 02210 USA Cengage Learning is a leading provider of customized learning solutions with office locations around the globe, including Singapore, the United Kingdom, Australia, Mexico, Brazil, and Japan. Locate your local office at: international.cengage.com/region. Cengage Learning products are represented in Canada by Nelson Education, Ltd. For your lifelong learning solutions, visit cengageptr.com. Visit our corporate website at cengage.com. Printed in the United States of America 1 2 3 4 5 6 7 16 15 14 4
To my sweet, tough cookie—for all of the help, support, understanding (and distractions) you offered. And to Ariella Saraswati Dawson, a girl who’s even more impressive than her name. I look forward to rediscovering the world with you, Monkey. 5
ACKNOWLEDGMENTS Every book you’ve ever read perpetuates a big fat lie. And I’m here to out the publishing industry’s dirty little secret: Books are not “by” only one person. Yes, you see only one name on many book covers (including this one), but it takes a team of dedicated people to pull off the final product. Authors could not do it alone; I certainly could not have done it alone. So I want to thank all those who helped make this new edition a reality. Thanks to Dan Foster, who pulled double duty as both Project Editor and Copy Editor. Dan was able to help improve a book that had already seen multiple editors. Thanks to Joshua Smith, my Technical Reviewer, who made sure my programs worked as advertised. Thanks to Kelly Talbot, my Proofreader, whose work makes this book look good—literally. I also want to thank Emi Smith, my Senior Acquisitions Editor, for all of her encouragement. Finally, I want to thank all of the game programmers who created the games I played while growing up. They inspired me to work on small games of my own and to eventually work in the game industry. I hope I can inspire a few readers to do the same. 6
ABOUT THE AUTHOR Michael Dawson is a game programming author and instructor who teaches students the art and science of writing their own games. Mike has developed and taught game programming courses for UCLA Extension, The Digital Media Academy, and The Los Angeles Film School. In addition, his books have been required reading in colleges and universities around the country. Mike got his start in the game industry as a producer and designer, but he also “starred” in an adventure game in which the player controls the main character, named Mike Dawson. In the game, the player directs the digitized images of Dawson, who must stop an extraterrestrial invasion before an implanted alien embryo is born from his head. In real life, Mike is the author of Beginning C++ Through Game Programming, Python Programming for the Absolute Beginner, C++ Projects: Programming with Text-Based Games, and Guide to Programming with Python. He earned his bachelor’s degree in Computer Science from the University of Southern California. Visit his website at www.programgames.com to learn more or to get support for any of his books. 7
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 8
分享到:
收藏