python games
use python to build games for newcomersFor Caro, with more lovethan l ever knew hadA Note to parents and fellowProgrammersThank your for reading this book. My motivation for writing this book comes from a gapI saw in today's literature for kids interested in learning to program. I started programmingwhen I was 9 years old in the BaSiC language with a book similar to this one. during thecourse of writing this, I've realized how a modern language like python has madeprogramming far easier and versatile for a new generation of programmers. Python has agentle learning curve while still being a serious language that is used by programmersprofessionallyThe current crop of programming books for kids that I've seen fell into two categoriesFirst, books that did not teach programming so much as"game creation software or adumbed-down languages to make programming easy (to the point that it is no longerprogramming) Or second, they taught programming like a mathematics textbook: allprinciples and concepts with little application given to the reader. This book takes adifferent approach: show the source code for games right up front and explainprogramming principles from the examplesI have also made this book available under the creative commons license. which allowsyou to make copies and distribute this book(or excerpts) with my full permission, as longas attribution to me is left intact and it is used for noncommercial purposes. (See thecopyright page. )I want to make this book a gift to a world that has given me so muchThank you again for reading this book, and feel free to email me any questions orcommentsAl Swcigargal@inventwithpython.comThe full text of this book is available in html or pdf format athttp://inventwithpython.comLATERMy Richard The Third thevideo Game is going to beJm, APPARENTLY, progr amming is for folkFANT点三T工Care thrilled when a compuiter reminds themJAll, I need to they're missing a bracket, or semicolon七Man I HEAR THAT do is programmust be, because theyItthat happen So oFTENhot going we工CAN' T EVEM GET R工 CHARDTHE TH工RDT0Mo↓EbbLes. witg the tan'opyright0S十t199to man, forgetEm thisProgramming's a skill! I just thought it, was a ski1] Ild pick叩pea511yI dontn口w已已r1工dan' t need tknow the difference between friggin已arCh已已WANT T○KN○wk已R1 charo工工TJumPA you kns凵cKsCot toearnbefor e you0 2008 Rvan Nor thqUanta. comDinosaur Comics reproduced with permission. Thanks RyanWho is this book forProgramming isnt hard. But it is hard to find learning materials that teach you to do interesting things withprogramming. Other computer books go over many topics that most new bie coders don t need. This book willteach you how to program your own computer games. You will learn a useful skill and have fun games to show forThis book is forComplete beginners who wants to teach themselves computer programming, even if they have no previousexperlence programmingKids and teenagers who want to learn computer programming by creating games. Kids as young as 9 or 10years old should be able to follow alongAdults and teachers who wish to teach others programmingAnyone, young or old, who wants to learn how to program by learning a professional programminglanguageTable of contentsSource Code Listinghello. pyguess. py30jokes. py51dragon. py58buggy py83coin Flips. py87hangman. py103tictactoe. py150truefalsefizz py172bagels. py184sonar. py213ChInherpy244reversI py261aisin. py292aisim2 py294aisim3 py299pygameHello world py 309animation. py324collision Detection. py 338pygameInput py348sprites AndSounds py 360dodger. py371Installing PythonDownloading and Installing PythonStarting python4How to use this bookThe Featured programsine Numbers and spacesSummary2 The Interactive shellSome Simple Math Stuff8Evaluating ExpressionsStoring values in Variables12USing more Than One variable15Summary3 Strings, and Your First Program18Strings18String concatenationWriting Programs in IDLE'S File editor20Hello world!20How the Hello world Program Works23Summary264 Guess the number28The "Guess the number game28Sample run of guess the number29Guess the Number's source code29The import statement31The random randint( Function32Passing Arguments to Functions34Blocks36The boolean Data ty37Comparison Operators37Conditions38Experiment with Booleans, Comparison Operators, and Conditions 38Looping with While statements41The Player guesses41if statements44Leaving Loops early with the break statement45Check if the Player Won46Summary: What Exactly is Programming?47A Web Page for Program Tracing485 Jokes50Make the Most of print()50Sample run of jokes50Joke's Source code51Escape Characters52Quotes and Double Quotes53The end Keyword argument54Summary556 Dragon Realm56Introducing Functions56Sample run of Dragon Realm57Dragon Realm's Source Code57def statements60Boolean OperatorsReturn values65Variable Scope65Parameters68Where to Put Function definitions70Displaying the game results71The colon73Where the Program Really Begins73Designing the Program75Summary767 Using the Debugger77Bugs!77Starting the Debugger78Stepping80The Go and Quit Buttons81Stepping Over and Stepping Out81Find the bug83Break points86Summary888 Flow charts89How to Play hangman89Sample run of Hangman89ASCII Art91Designing a program with a flowchart92Creating the Flow Chart93Summary: The Importance of Planning Out the Game9 Hangman102Hangman's Source Code103Multi-line strings107ConstantⅤ ariables108Lists108Changing the values of List Items with Index assignment110List concatenation110The in Operator111Removing items from lists with del statements112ists of lists113114The reverse()and append() list Methods115The Difference between Methods and Functions116The split() Function16The range() andlist() functions120for loops121elif( Else If)Statements127Review of the functions we defined131Making new changes to the hangman program132Dictionaries139Sets of words for hangman142The random choice() Function143Multiple assignment145Summary14710 Tic Tac Toe148Sample run of fic tac Toe149Source code of tic tac toe150Designing the program154Game Al156List References162Short-Circuit EvaluationThe None value175Summary: Creating Game-Playing Artificial Intelligences18211 Bagels183Sample run184Bagel's Source Code184Designing the program186The random shuffle() Function188Augmented Assignment Operators190The sort( List Method192The join( String Method192String Interpolation194Summary: Getting Good at Bagels19812 Cartesian Coordinates200Grids and Cartesian Coordinates201Negative Numbers202Math tricks204Absolute Values and the abs() function206Coordinate System of a Computer monitor207Summary: USing this Math in Games20813 Sonar Treasure hunt209Sample run210Sonar's Source code213Designing the Program218The remove() List Method229Summary: Review of our Sonar Game23814 Caesar Cipher239About Cryptograph239The Caesar Cipher240ASCII, and Using Numbers for Letters241The chr() and ord( functions242Sample run of Caesar Cipher243Caesar Cipher's Source Code244The isalpha() String Method247The isupper()and islower()String Methods248
下载地址
用户评论