1. 首页
  2. 编程语言
  3. Python
  4. 用python进行游戏编程.pdf

用python进行游戏编程.pdf

上传者: 2021-04-29 21:08:18上传 .PDF文件 4.89 MB 热度 17次

Table of ContentsSource Code Listinghello.py 21guess.py 30jokes.py 51dragon.py 58buggy.py 83coinFlips.py 87hangman.py 103tictactoe.py 150truefalsefizz.py 172bagels.py 184sonar.py 213cipher.py 244reversi.py 261aisim1.py 292aisim2.py 294aisim3.py 299pygameHelloWorld.py 309animation.py 324collisionDetection.py 338pygameInput.py 348spritesAndSounds.py 360dodger.py 3711 Installing Python 1Downloading and Installing Python 2Starting Python 4How to Use This Book 4The Featured Programs 5Line Numbers and Spaces 5Summary 72 The Interactive Shell 8Some Simple Math Stuff 8Evaluating Expressions 11Storing Values in Variables 12Using More Than One Variable 15Summary 163 Strings, and Your First Program 18Strings 18String Concatenation 19Writing Programs in IDLE's File Editor 20Hello World! 20How the "Hello World" Program Works 23Summary 264 Guess the Number 28The "Guess the Number" Game 28Sample Run of "Guess the Number" 29Guess the Number's Source Code 29The import Statement 31The random.randint() Function 32Passing Arguments to Functions 34Blocks 36The Boolean Data Type 37Comparison Operators 37Conditions 38Experiment with Booleans, Comparison Operators, and Conditions 38Looping with While Statements 41The Player Guesses 41if Statements 44Leaving Loops Early with the break Statement 45Check if the Player Won 46Summary: What Exactly is Programming? 47A Web Page for Program Tracing 485 Jokes 50Make the Most of print() 50Sample Run of Jokes 50Joke's Source Code 51Escape Characters 52Quotes and Double Quotes 53The end Keyword Argument 54Summary 556 Dragon Realm 56Introducing Functions 56Sample Run of Dragon Realm 57Dragon Realm's Source Code 57def Statements 60Boolean Operators 61Return Values 65Variable Scope 65Parameters 68Where to Put Function Definitions 70Displaying the Game Results 71The Colon : 73Where the Program Really Begins 73Designing the Program 75Summary 767 Using the Debugger 77Bugs! 77Starting the Debugger 78Stepping 80The Go and Quit Buttons 81Stepping Over and Stepping Out 81Find the Bug 83Break Points 86Summary 888 Flow Charts 89How to Play "Hangman" 89Sample Run of "Hangman" 89ASCII Art 91Designing a Program with a Flowchart 92Creating the Flow Chart 93Summary: The Importance of Planning Out the Game 1009 Hangman 102Hangman's Source Code 103Multi-line Strings 107Constant Variables 108Lists 108Changing the Values of List Items with Index Assignment 110List Concatenation 110The in Operator 111Removing Items from Lists with del Statements 112Lists of Lists 113Methods 114The reverse() and append() List Methods 115The Difference Between Methods and Functions 116The split() Function 116The range() and list() Functions 120for Loops 121elif ("Else If") Statements 127Review of the Functions We Defined 131Making New Changes to the Hangman Program 132Dictionaries 139Sets of Words for Hangman 142The random.choice() Function 143Multiple Assignment 145Summary 14710 Tic Tac Toe 148Sample Run of Tic Tac Toe 149Source Code of Tic Tac Toe 150Designing the Program 154Game AI 156List References 162Short-Circuit Evaluation 170The None Value 175Summary: Creating Game-Playing Artificial Intelligences 18211 Bagels 183Sample Run 184Bagel's Source Code 184Designing the Program 186The random.shuffle() Function 188Augmented Assignment Operators 190The sort() List Method 192The join() String Method 192String Interpolation 194Summary: Getting Good at Bagels 19812 Cartesian Coordinates 200Grids and Cartesian Coordinates 201Negative Numbers 202Math Tricks 204Absolute Values and the abs() Function 206Coordinate System of a Computer Monitor 207Summary: Using this Math in Games 20813 Sonar Treasure Hunt 209Sample Run 210Sonar's Source Code 213Designing the Program 218The remove() List Method 229Summary: Review of our Sonar Game 23814 Caesar Cipher 239About Cryptography 239The Caesar Cipher 240ASCII, and Using Numbers for Letters 241The chr() and ord() Functions 242Sample Run of Caesar Cipher 243Caesar Cipher's Source Code 244The isalpha() String Method 247The isupper() and islower() String Methods 248Brute Force 251Summary: Reviewing Our Caesar Cipher Program 25315 Reversi 256How to Play Reversi 255Sample Run 257Reversi's Source Code 260The bool() Function 276Summary: Reviewing the Reversi Game 29016 AI Simulation 291"Computer vs. Computer" Games 291AISim1.py Source Code 292AISim2.py Source Code 294Percentages 296The round() Function 297Comparing Different AI Algorithms 299AISim3.py Source Code 299Learning New Things by Running Simulation Experiments 30517 Graphics and Animation 306Installing Pygame 307Hello World in Pygame 308Hello World's Source Code 308Importing the Pygame Module 311Variables Store References to Objects 313Colors in Pygame 313Fonts, and the pygame.font.SysFont() Function 315Attributes 316Constructor Functions and the type() function. 317The pygame.PixelArray Data Type 321Events and the Game Loop 322Animation 324The Animation Program's Source Code 324Some Small Modifications 335Summary: Pygame Programming 33518 Collision Detection and Input 337The Collision Detection Program's Source Code 337The Collision Detection Function 341The pygame.time.Clock Object and tick() Method 344The Keyboard Input Program's Source Code 348The colliderect() Method 356Summary: Collision Detection and Pygame Input 35619 Sound and Images 358Image and Sound Files 360Sprites and Sounds Program 360The Sprites and Sounds Program's Source Code 360Setting Up the Window and the Data Structure 364The pygame.transform.scale() Function 364Summary: Games with Graphics and Sounds 36820 Dodger 369Review of the Basic Pygame Data Types 370Dodger's Source Code 371Implementing the Cheat Codes 392Modifying the Dodger Game 397Summary: Creating Your Own Games 397Appendix ADifferences Between Python 2 and 3 399Appendix BStatements, Functions, and Methods Reference 403Appendix CRunning Python Programs without Python Installed 404Appendix DCommon Error Messages in Python 407Glossary 411About the Author 421

下载地址
用户评论