This is the electronic PDF eBook that you can download and start reading right away. If you are looking for the physical hardcover book instead, you can find it here.
Start from the beginning by getting your computer ready for coding. You can use a desktop or laptop computer running Windows or Linux, or a Mac to learn how to code. These are the same steps that I use to get my computers ready and the process is easy to follow.
Then learn how to test your setup and make sure everything is working. Testing small steps is a big part of what you’ll learn in this eBook and it will help you to identify problems so they can be fixed right away.
You can use this eBook as a self-study guide or to supplement your current programming classes. It will provide you with insights and skills that are not taught in schools.
The first part of this eBook shows you the fundamentals you’ll need to use all the time. Topics are introduced as needed so you can see why they’re important. You don’t need any previous programming experience. All you need is a desire to learn and a curiosity to explore.
The second part of this eBook begins a large project to build an adventure game. Many other books will show you a finished design and try to explain it piece by piece. This eBook starts out with an empty project and slowly builds it over time. This lets you see how code is really written and how it changes over time. If you’ve ever stared at a blank page and wondered where to begin, this will help you.
I’m Abdul Wahid Tanner and have been programming C++ since 1992 and teaching others how to code for almost as long. Back then, there were no books to teach C++ and I learned everything by experimenting. I know the difficulties of learning how to code and can help you in your journey.
This eBook contains decades of insights and follows a learn-as-you-go style. It also contains some mistakes because we can all learn from those. This is a practical approach that doesn’t try to hide anything and lets you understand how to code. This is how real code is written.
Page count: 815
Book format: eBook PDF
Color: Yes. The text is mostly black with highlighted keywords and code names.
Source code: Yes. The code is colored blue for lines that are not changed and red for new or updated lines. This lets you spot the changes that are being made.
Images: Yes. The current output of the samples and the game are shown as well as screenshots of important setup and tool usage topics.
Topics covered in the eBook:
Chapter 1: Setting expectations
- Why use C++.
- Why do we need a language to code in?
- Is C++ for beginners?
- Is C++ still used?
- Why use games to learn how to code?
- Games help keep you motivated.
- What will you learn?
- Learning is not enough.
- How should you begin?
- How this book is organized.
- Just enough theory to get started.
- Project-based learning makes sense.
- You get to see the changes and understand why.
Chapter 2: Getting your computer ready for coding
- What do you need to write and run code?
- Use the computer you already have.
- Install your tools (Windows).
- Install your editor (Windows).
- Install your tools (Mac).
- Install your editor (Mac).
- Install your tools (Linux).
- Install your editor (Linux).
- How to organize multiple projects.
- How to start a new project.
- Making sure your project builds and runs.
Chapter 3: Learning the basics of C++
- Navigating and building Hello.
- Understanding your first code.
- Detailed line-by-line explanation of your first code.
- What does the code do?
- Simplifying main.
- Why does C++ need semicolons?
- Moving to C++.
- Adding comments.
- Why are types needed?
- Be careful with multiple projects.
- The beginning of every project looks like this.
- The char type.
- Encoding chars with ASCII.
- What does data mean?
- Creating variables in code.
- Back to the char type.
- How to give values to your variables.
- Using literal values instead of variables.
- Uniform initialization.
- You can put numbers in a char too.
- Choosing names.
- Where can you declare variables?
- Back to initialization.
- The bool type.
- Using stream manipulators.
- Why do we really need variables?
- Understanding boolean logic.
- The int type.
- How big are C++ types?
- Negative and positive values.
- Declaring and initializing int variables.
- Comparing values.
- The float and double types.
- Initializing double variables.
- Default precision.
- Comparing double and float initialization.
- Controlling display precision.
- Avoid large values with small fractions.
- Using fixed precision.
- Aligning numbers.
- Be careful of integer arithmetic.
- Avoid rounding errors.
- Reading from the keyboard.
- Making decisions in code.
- Always use curly braces.
- Doing something else in code.
- Choosing between specific values.
- Comparing if and switch statements.
- Memory addresses.
- Positional number systems.
- The pointer type.
- Virtual memory.
- Why do we need pointers?
- Declaring pointers.
- Finding the address of other variables.
- Using pointers.
- Pointers without a type.
- Casting with void pointers.
- Null pointers and nullptr.
- How are pointers used in real code?
- Allocating and freeing memory.
- Avoid leaking memory.
- A better way to manage memory.
- Doing things more than once.
- Be careful of off-by-one errors.
- Incrementing and decrementing values.
- The while loop.
- The for loop.
- The do while loop.
- How to use macros effectively.
- The range-based for loop.
- The array type.
- Using arrays in loops.
- Initializing array values.
- Staying within array bounds.
- Using arrays with pointers.
- Uninitialized vs. zero initialized arrays.
- Contructing arrays with variable sizes.
- Methods and functions.
- What makes up a method?
- Implementing a simple method.
- Calling methods in loops.
- Using compound operations.
- Methods are strongly typed.
- Using method return values.
- Adding method parameters.
- Using method default argument values.
- The reference type.
- How are references really used in code?
- Using references in loops.
- Using references with method parameters.
- Avoid references with default argument values.
- Dangling references will crash.
- Safely returning references from methods.
- C-style strings and literals.
- The std::string type.
- Reading text from the keyboard.
- Reading multiple parts from a stream.
- Creating temporary strings.
- Comparing strings.
- Other string operations.
- Converting strings to and from numbers.
- Strings as method parameters with const.
- Should const go on the left or the right?
- The std::vector type.
- Initializing vector values.
- How to use vectors as method parameters.
- Other vector operations.
- Using vectors like arrays.
- Using vectors with iterators.
- Throw away iterators when modifying.
- Comparing vectors and lists.
- Creating enum types.
- Creating enum class types.
- Creating struct types.
- Designing code to use structs.
- Setting struct default values.
- Using structs with pointers.
- Overloading methods with the same name.
- Why can’t variables be overloaded?
- Using the scope resolution operator.
- Method overloading rules.
- What happens when types don’t match?
- Safe method overloading with default arguments.
- Method overloading with ints and pointers.
- Algorithms are everywhere.
- How are algorithms used in C++?
- Comparing algorithms with design patterns.
- The std::find algorithm.
- Using a predicate with std::find_if.
- Method names decay into pointers.
- Using lambdas as unamed methods.
- Capturing variables and parameters.
- How to make sense of lambda syntax.
- The std::copy algorithm.
- The std::unique and std::sort algorithms.
- How to use unique properly with erase.
Chapter 4: Creating a game from the beginning
- Creating a Tile class.
- Editing a simple class.
- Comparing classes with structs.
- Controlling access.
- Why use a class instead of a struct?
- Constructing instances.
- Adding behavior through class methods.
- Implementing class methods.
- Implementing class constructors.
- Implementing getter methods.
- Creating a Resource class.
- When to use signed vs. unsigned types.
- Ensuring data is valid.
- Why you should avoid using statements.
- Should method parameters be copies?
- Connecting classes together.
- Creating a Level class.
- Organizing a collection for two dimensions.
- Use this simple way to get data.
- Avoiding strange or undesired behavior.
- Constructing temporary instances.
- More about signed vs. unsigned.
- Drawing to the computer screen.
- Agile creation of Character class.
- Creating a Location struct instead of a class.
- Creating a Direction enum header file.
- Working through agile design issues.
- Making progress on the drawing.
- How to start and make progress.
- Working with streams and text.
- When is it safe to use static_cast?
- Taking a detour to improve the code.
- Letting a class do things for itself.
- Adding a Mediator class to simplify the code.
- Adding numbers to chars?
- Object lifetime guarantees.
- Creating a Painter helper class.
- Forward declarations, pointers, and references.
- Implementing setter class methods.
- Creating a Game class.
- How to create higher-level wrappers.
- Making a class with all static methods.
- Dealing with unknown inputs.
- Recovering from stream errors.
- Accepting numeric input.
- Accepting single char input.
- How to handle errors or throw exceptions.
- Accepting text input.
- Calling static class methods.
- Changing from static to instance methods.
- Using Find and Replace.
- Specify options instead of assuming.
- Adding the game loop.
- Renaming a class the easy way.
Chapter 5: Accepting commands
- Implementing the command pattern.
- Creating an abstract Command class.
- Using pure virtual methods in an interface.
- Constructing and destructing classes.
- Other methods in Command.
- Creating a CommandMove derived class.
- Overloading methods by const.
- Moving along x and y coordinates.
- Creating and running commands.
- Using unique_ptr returned from a factory.
- Using the implicit this pointer.
- How to find and fix bugs.
- Checking movement boundaries.
- Refactoring character movement.
- Extending movement to all directions.
- Creating a CommandQuit derived class.
- Refactoring the game.
- Detecting collisions.
- Making a bigger map.
- Designing better commands.
- Using auto type deduction.
- Avoid using auto with vector<bool>.
Chapter 6: Adding behavior states
- Adding multiple display areas.
- Refactoring character placement.
- Adding an event system.
- How to use the std::variant type.
- Implementing tests for equality.
- Writing a template and calling std::visit.
- Debugging template method type resolution.
- Streaming game messages.
- Comparing systems, commands, and events.
- Pointers make terrible identifiers.
- Prefer code readability over cleverness.
- Adding more resources.
- Dealing with absent values.
- Adding multiple states.
- Creating a GameState class.
- Do you need empty cpp files?
- Creating concrete state classes.
- How to remove a class.
- Processing input to work with states.
- Don’t drain batteries with busy loops.
- Fixing state bugs.
- Using the ternary ?: operator.
- Refactoring the commands.
Chapter 7: Enhancing multiple characters
- Adding multiple characters.
- Selecting a default character.
- Moving the default character.
- How to simplify code through error checking.
- Choosing which character is default.
- Moving any character.
- Planning helps guide your designs.
- Showing the default character.
- How can correct code still have a bug?
Chapter 8: Managing inventory
- Displaying inventory.
- Identifying items.
- A big problem that’s easy to miss.
- Don’t be afraid to make copies.
- Taking items.
- Dropping items.
Chapter 9: Battling creatures
- Should you use a class hierarchy?
- This was a bug waiting to happen.
- How to spawn creatures.
- Adding action through updates.
- How refactoring broke the code.
- Letting creatures move on their own.
- Adding health and direction.
- Should all bugs be fixed?
- Attacking creatures.
- Getting creatures to fight back.
- Adding random chance.
- Moving creatures randomly.
- Where do you go from here?
Appendix
- C++ operators.
You must log in and be a buyer of this download to submit a review.