1. Trang chủ
  2. » Tất cả

Invent Your Own Computer Games with Python (2008)

331 4 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Nội dung

Copyright 2008 © by Albert Sweigart "Invent Your Own Computer Games with Python" is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License You are free:   to Share - to copy, distribute, display, and perform the work to Remix - to make derivative works Under the following conditions:   Attribution - You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work) (Visibly include the title and author's name in any excerpts of this work.) Share Alike - If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one This summary is located here: http://creativecommons.org/licenses/by-sa/3.0/us/ Your fair use and other rights are in no way affected by the above There is a human-readable summary of the Legal Code (the full license), located here: http://creativecommons.org/licenses/by-sa/3.0/us/legalcode IYOCGwP - Version ISBN 978-0-9821060-0-6 For Caro, with more love than I ever knew I had A Note to Parents and Fellow Programmers I have more thanks for your interest and more apologies for this book's deficiencies than I can enumerate My motivation for writing this book comes from a gap I saw in today's literature for kids interested in learning to program I started programming when I was years old in the BASIC language with a book similar to this one During the course of writing this, I've realized how a modern language like Python has made programming far easier and more capable Python has a gentle learning curve while still being a serious language that is used by programmers professionally The current crop of programming books for kids that I've seen fell into two categories First, books that did not teach programming so much as "game creation software" or in dumbed down languages to make programming "easy" Or second, they taught programming like a mathematics textbook: all principles and concepts with application left to the reader This book takes a different approach: show the game source code right up front and explain programming principles from the examples My fellow programmers may notice that the games in this book all use console text, and also use a single stream of text rather than a console window system such as the one the Curses library provides This is on purpose Even though there are no graphics or sound, I think that the games are compelling enough in their own right I also think that graphics and images (and especially game construction kits) mask the true nature of programming I have the perhaps outdated notion that games not require fancy graphics to be fun The list of things that this book also does not cover: graphics, sound, graphical user interfaces, debugging, file I/O, exceptions, networking, data structures such as stacks and queues, and object oriented programming After trudging through massively verbose programming manuals myself, I've tried to strip down this book to its most concise form These other concepts have been reserved for later books I have also made this book available under the Creative Commons license, which allows you to make copies and distribute this book (or excerpts) with my full permission, as long as attribution to me is left intact and it is used for noncommercial purposes I view the last nine months of on and off effort in this book as my gift to world Thank you again for reading this book Al Sweigart al@coffeeghost.net The full text of this book is available in HTML or PDF format at: http://pythonbook.coffeeghost.net Who is this book for?     Anyone who wants to teach themselves computer programming, even if they have no previous experience programming Kids and teenagers who want to learn computer programming by programming games Kids as young as or 10 years old should be able to follow along Adults and teachers who wish to teach others programming Programmers who want to teach others "real" programming by example This book is available for free under a Attribution/Share-Alike Creative Commons license You can make as many copies of it as you like, as long as credit to the author is left in The Python programming language software this book teaches is also freely available from www.python.org Table of Contents Chapter - "Hello World!" - Your First Program x Hello! Downloading and Installing Python Starting the Python Interpreter Some Simple Math Stuff Evaluating Expressions Variables Strings Writing Programs Hello World! The Difference Between Statements and Expressions "My Favorite Stuff" Crazy Answers and Crazy Names for our Favorite Stuff Capitalizing our Variables Chapter - Guess the Number Source Code Arguments Blocks Conditions and Booleans if Statements Step by Step, One More Time Some Changes We Could Make What Exactly is Programming? A Web Page for Program Tracing Chapter - Jokes How Programs Run on Computers Source Code Some Other Escape Characters Quotes and Double Quotes Chapter - Dragon Realm Source Code def Statements x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x Boolean Operators Variable Scope Parameters Local Variables and Global Variables with the Same Name Where to Put Function Defintions The Colon : Step by Step, One More Time Designing the Program A Web Page for Program Tracing Chapter - Hangman ASCII Art Source Code Designing the Program Multi-line Strings Constant Variables Lists Changing the Values of List Items with Index Assignment List Concatenation The in Operator Removing Items from Lists with del Statements Lists of Lists Methods The len() Function The range() Function for Loops Strings Act Like Lists List Slicing and Substrings elif ("Else If") Statements And that's it! Dictionaries Sets of Words for Hangman Chapter - Tic Tac Toe Source Code Designing the Program Game AI List References x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x Short-Circuit Evaluation The None Value A Web Page for Program Tracing Chapter - Bagels Source Code Augmented Assignment Operators The sort() List Method The join() String Method String Interpolation Chapter - Sonar Grids and Cartesian Coordinates Negative Numbers Changing the Signs Absolute Values Coordinate System of a Computer Monitor Source Code Designing the Program The remove() List Method Chapter - Caesar Cipher About Cryptography ASCII, and Using Numbers for Letters The chr() and ord() Functions Source Code The isalpha() String Method The isupper() and islower() String Methods Cryptanalysis Brute Force Chapter 10 - Reversi How to Play Reversi Source Code The bool() Function The random.shuffle() Function Tips for Inventing Your Own Games x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x Chapter 11 - AI Simulation "Computer vs Computer" Games Percentages Integer Division The round() Function Learning New Things by Running Simulation Experiments x x x x x x ... Copyright 2008 © by Albert Sweigart "Invent Your Own Computer Games with Python" is licensed under a Creative Commons Attribution-Share Alike 3.0 United... random.shuffle() Function Tips for Inventing Your Own Games x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x Chapter 11 - AI Simulation "Computer vs Computer" Games Percentages Integer... But even if you don't become a computer programmer when you grow up, programming is a useful and fun skill to have (I still sometimes invent my own computer games. ) Computers are very useful machines

Ngày đăng: 13/04/2019, 01:40