Book description
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
What new game will you create with the power of Python?
The projects in this book are compatible with Python 3.
Publisher resources
Table of contents
- Cover
- Title Page
- Copyright Page
- About the Author
- About the Technical Reviewer
- Brief Contents
- Contents in Detail
- Acknowledgments
- Introduction
- Chapter 1: The Interactive Shell
- Chapter 2: Writing Programs
-
Chapter 3: Guess the Number
- Sample Run of Guess the Number
- Source Code for Guess the Number
- Importing the random Module
- Generating Random Numbers with the random.randint() Function
- Welcoming the Player
- Flow Control Statements
- Getting the Player’s Guess
- Converting Values with the int(), float(), and str() Functions
- The Boolean Data Type
- if Statements
- Leaving Loops Early with the break Statement
- Checking Whether the Player Won
- Checking Whether the Player Lost
- Summary
- Chapter 4: A Joke-Telling Program
-
Chapter 5: Dragon Realm
- How to Play Dragon Realm
- Sample Run of Dragon Realm
- Flowchart for Dragon Realm
- Source Code for Dragon Realm
- Importing the random and time Modules
- Functions in Dragon Realm
- Multiline Strings
- How to Loop with while Statements
- Boolean Operators
- Return Values
- Global Scope and Local Scope
- Function Parameters
- Displaying the Game Results
- Deciding Which Cave Has the Friendly Dragon
- The Game Loop
- Summary
- Chapter 6: Using the Debugger
- Chapter 7: Designing Hangman with Flowcharts
-
Chapter 8: Writing the Hangman Code
- Source Code for Hangman
- Importing the random Module
- Constant Variables
- The Lists Data Type
- Calling Methods
- Getting a Secret Word from the Word List
- Displaying the Board to the Player
- Getting the Player’s Guess
- elif Statements
- Making Sure the Player Entered a Valid Guess
- Asking the Player to Play Again
- Review of the Hangman Functions
- The Game Loop
- Summary
- Chapter 9: Extending Hangman
-
Chapter 10: Tic-Tac-Toe
- Sample Run of Tic-Tac-Toe
- Source Code for Tic-Tac-Toe
- Designing the Program
- Importing the random Module
- Printing the Board on the Screen
- Letting the Player Choose X or O
- Deciding Who Goes First
- Placing a Mark on the Board
- Checking Whether the Player Won
- Duplicating the Board Data
- Checking Whether a Space on the Board Is Free
- Letting the Player Enter a Move
- Short-Circuit Evaluation
- Choosing a Move from a List of Moves
- The None Value
- Creating the Computer’s AI
- The Game Loop
- Summary
-
Chapter 11: The Bagels Deduction Game
- Sample Run of Bagels
- Source Code for Bagels
- Flowchart for Bagels
- Importing random and Defining getSecretNum()
- Shuffling a Unique Set of Digits
- Augmented Assignment Operators
- Calculating the Clues to Give
- The sort() List Method
- The join() String Method
- Checking Whether a String Has Only Numbers
- Starting the Game
- String Interpolation
- The Game Loop
- Summary
- Chapter 12: The Cartesian Coordinate System
-
Chapter 13: Sonar Treasure Hunt
- Sample Run of Sonar Treasure Hunt
- Source Code for Sonar Treasure Hunt
- Designing the Program
- Importing the random, sys, and math Modules
- Creating a New Game Board
- Drawing the Game Board
- Creating the Random Treasure Chests
- Determining Whether a Move Is Valid
- Placing a Move on the Board
- Printing the Game Instructions for the Player
- The Game Loop
- Summary
-
Chapter 14: Caesar Cipher
- Cryptography and Encryption
- How the Caesar Cipher Works
- Sample Run of Caesar Cipher
- Source Code for Caesar Cipher
- Setting the Maximum Key Length
- Deciding to Encrypt or Decrypt the Message
- Getting the Message from the Player
- Getting the Key from the Player
- Encrypting or Decrypting the Message
- Starting the Program
- The Brute-Force Technique
- Adding the Brute-Force Mode
- Summary
-
Chapter 15: The Reversegam Game
- How to Play Reversegam
- Sample Run of Reversegam
- Source Code for Reversegam
- Importing Modules and Setting Up Constants
- The Game Board Data Structure
- Checking Whether a Move Is Valid
- Checking for Valid Coordinates
- Getting the Score of the Game Board
- Getting the Player’s Tile Choice
- Determining Who Goes First
- Placing a Tile on the Board
- Copying the Board Data Structure
- Determining Whether a Space Is on a Corner
- Getting the Player’s Move
- Getting the Computer’s Move
- Printing the Scores to the Screen
- Starting the Game
- The Game Loop
- Asking the Player to Play Again
- Summary
- Chapter 16: Reversegam AI Simulation
-
Chapter 17: Creating Graphics
- Installing pygame
- Hello World in pygame
- Sample Run of pygame Hello World
- Source Code for pygame Hello World
- Importing the pygame Module
- Initializing pygame
- Setting Up the pygame Window
- Setting Up Color Variables
- Writing Text on the pygame Window
- Filling a Surface Object with a Color
- pygame’s Drawing Functions
- The blit() Method for Surface Objects
- Drawing the Surface Object to the Screen
- Events and the Game Loop
- Summary
- Chapter 18: Animating Graphics
-
Chapter 19: Collision Detection
- Sample Run of the Collision Detection Program
- Source Code for the Collision Detection Program
- Importing the Modules
- Using a Clock to Pace the Program
- Setting Up the Window and Data Structures
- Setting Up Variables to Track Movement
- Handling Events
- Teleporting the Player
- Adding New Food Squares
- Moving the Player Around the Window
- Drawing the Food Squares on the Window
- Summary
-
Chapter 20: Using Sounds and Images
- Adding Images with Sprites
- Sound and Image Files
- Sample Run of the Sprites and Sounds Program
- Source Code for the Sprites and Sounds Program
- Setting Up the Window and the Data Structure
- Setting Up the Music and Sounds
- Drawing the Player on the Window
- Checking for Collisions
- Drawing the Cherries on the Window
- Summary
-
Chapter 21: A Dodger Game with Sounds and Images
- Review of the Basic pygame Data Types
- Sample Run of Dodger
- Source Code for Dodger
- Importing the Modules
- Setting Up the Constant Variables
- Defining Functions
- Initializing pygame and Setting Up the Window
- Setting Up Font, Sound, and Image Objects
- Displaying the Start Screen
- Starting the Game
- The Game Loop
- Adding New Baddies
- Moving the Player’s Character and the Baddies
- Implementing the Cheat Codes
- Removing the Baddies
- Drawing the Window
- Checking for Collisions
- The Game Over Screen
- Modifying the Dodger Game
- Summary
- Index
- Resources
- The Electronic Frontier Foundation (EFF)
- Don’t Just Play Games—Make Them!
Product information
- Title: Invent Your Own Computer Games with Python , 4th Edition
- Author(s):
- Release date: December 2016
- Publisher(s): No Starch Press
- ISBN: 9781593277956
You might also like
book
Beginning Python Games Development : With Pygame, Second Edition
Beginning Python Games Development, Second Edition teaches you how to create compelling games using Python and …
book
Classic Computer Science Problems in Python
Classic Computer Science Problems in Python deepens your knowledge of problem solving techniques from the realm …
book
Make Python Talk
This fun, hands-on book will take your basic Python skills to the next level as you …
book
Expert Python Programming - Fourth Edition
Gain a deep understanding of building, maintaining, packaging, and shipping robust Python applications Key Features Discover …