Invent Your Own Computer Games with Python, 4th Edition

Invent Your Own Computer Games with Python
by 
Al Sweigart
December 2016, 376 pp.
ISBN-13: 
978-1-59327-795-6

“It's a great introduction to Python and a great introduction to building fairly simple but interesting games. The author's not just a talented coder, but a Python maestro. And his programming techniques provide good lessons on how to approach programming tasks.”
Computerworld

“Games are a great way to engage kids, and Python is a perfect language for them to see immediate results on the screen as they code. Invent Your Own Computer Games with Python should be a hit.”
GeekDad

Invent Your Own Computer Games with Python will teach you how to make computer games using the popular Python programming language—even if you’ve never programmed before!

Begin by building classic games like Hangman, Guess the Number, and Tic-Tac-Toe, and then work your way up to more advanced games, like a text-based treasure hunting game and an animated collision-dodging game with sound effects. Along the way, you’ll learn key programming and math concepts that will help you take your game programming to the next level.

Learn how to:

  • Combine loops, variables, and flow control statements into real working programs
  • Choose the right data structures for the job, such as lists, dictionaries, and tuples
  • Add graphics and animation to your games with the pygame module
  • Handle keyboard and mouse input
  • Program simple artificial intelligence so you can play against the computer
  • Use cryptography to convert text messages into secret code
  • Debug your programs and find common errors

As you work through each game, you’ll build a solid foundation in Python and an understanding of computer science fundamentals.

What new game will you create with the power of Python?

The projects in this book are compatible with Python 3.

Author Bio 

Al Sweigart is a professional software developer who teaches programming to kids and adults. His programming tutorials can be found at inventwithpython.com. He is the author of Automate the Boring Stuff with Python and Scratch Programming Playground.

Table of contents 

Chapter 1: The Interactive Shell
Chapter 2: Writing Programs
Chapter 3: Guess the Number
Chapter 4: Jokes
Chapter 5: Dragon Realm
Chapter 6: Using the Debugger
Chapter 7: Designing Hangman with Flowcharts
Chapter 8: Writing the Hangman Code
Chapter 9: Extending Hangman
Chapter 10: Tic-Tac-Toe
Chapter 11: Bagels
Chapter 12: Cartesian Coordinates
Chapter 13: Sonar Treasure Hunt
Chapter 14: Caesar Cipher
Chapter 15: Reversi
Chapter 16: AI Simulation
Chapter 17: Using Pygame and Graphics
Chapter 18: Animating Graphics
Chapter 19: Collision Detection and Input
Chapter 20: Sounds and Images
Chapter 21: Dodger

Reviews 

Recommended by Geekdad in their “Ultimate-est List of Toys, Kits, and Books to Teach Kids Coding”

“...Pretty close to the ultimate how-to-learn python book. First, it combines an easy ramp up from expecting you to know virtually nothing to having you try out – and understand – Python. Second, it provides the code, the tools, and the explanations required for you build a number of increasingly sophisticated games and the know-how to branch out to creating games completely on your own.”
Computerworld

“Many of the games include flowcharts so the reader will better understand the logic needed to complete the game, and I was especially happy to see a few chapters focus on topics not necessary limited to games such as Cartesian coordinates and using the built-in Debugger.”
GeekDad

“This is an excellent way to learn Python, if you are a kid or not. Little kids can learn with their adult guide, and older kids will eat this book up in an afternoon or two.”
Greg Laden, National Geographic's ScienceBlogs

Updates 

Page 13
In the second paragraph under the Writing Programs in IDLE's File Editor section, the sentence "Then select New Window if you are using Windows or New File if you are using OS X." should read "Then select New File."

Page 16
In the first paragraph under the Running Your Program section, the sentence "Click File => Run Module." should read "Click Run => Run Module."

Page 23
Line 12 which reads for i in range(6): should be for guessesTaken in range(6):

Page 23
Line 27 which reads guessesTaken = str(guessesTaken) should be guessesTaken = str(guessesTaken + 1)

Page 26
Line 12 which reads for i in range(6): should be for guessesTaken in range(6):

Page 27
Line 12 in Figure 3-1 which reads for i in range(6): should be for guessesTaken in range(6):

Page 28
Line 12 which reads for i in range(6): should be for guessesTaken in range(6):

Page 29
Line 12 in Figure 3-2 which reads for i in range(6): should be for guessesTaken in range(6):

Page 35
Line 27 which reads guessesTaken = str(guessesTaken) should be guessesTaken = str(guessesTaken + 1)

Page 35
In the last paragraph under the Checking Whether the Player Won section the sentence "Line 27 calls the str() function, which returns the string form of guessesTaken." should read "Line 27 calls the str() function, which returns the string form of guessesTaken plus 1 (since the range function goes from 0 to 5 instead of 1 to 6)."
In the same paragraph, the sentence "This is why line 27 had to change guessesTaken to sting form." should read "This is why line 27 had to change guessesTaken + 1 to string form."

Page 36
Line 12 which reads for i in range(4): should be for guessesTaken in range(4):