Index

Symbols

+ (addition) operator, 47-48

= (assignment) operator, 57

== (equality comparison) operator, 57

// (division) operator, 48

/ (division) operator, 48

% (modulus) operator, 48, 97-98

# (pound sign), commenting, 214, 344

- (subtraction) operator, 48

* (multiplication) operator, 42, 48

A

antialiasing, 340

append() function, 213, 274

arguments, 164, 165

commas and, 31

naming, 168

passing, 22-23

range() function, 93

self, 247-248

user-defined functions and, 167-170

variables and, 170

arrays, 212

ASCII code, 96

assignment operator (=), 57

asterisk (*), 42

attributes, 244. See also classes

B

backslash (), 147, 148

battling enemies, 277-279. See also game(s); text-based adventure game(s)

birthday countdown

datetime variable, 151

program flow, 150

requirements, 150

blit() function, 309

bugs, 134

C

Call of Duty, 122

calling a function, 23, 53

case sensitivity

color variables and, 291

variables and, 25, 26

choice() method, 73

choosing, random items, 38-39

Chromebook, 9, 11

classes, 54, 242

creating, 243-244

datetime, 55, 66

dictionaries and, 243

initializing, 250-251

instantiation, 246

player management system and, 251-255

properties, 244-246

reusability, 243

str, 70, 71

testing, 245-246

code(ing), 124

coloring your output, 260-264

commenting, 43-45, 141, 344

debugging, 134, 136

duplicate, 107, 322

executing, 19

indentation, 58, 77

open source, 286

optimizing, 194-195

planning and, 122-123

pseudo, 197

recursion, 238-239

refactoring, 204-206, 221

reuse, 174

string externalization, 196-201

testing, 73, 129

unit testing, 125

updating, 218-220

whitespace, 25

stripping, 72

collide_rect() function, 331

collision detection, 330-331, 350-351

colons ( : ), 57

Colorama, importing and initializing the library, 259-260

Colossal Cave Adventure, 178

combining, import statements, 218, 307

commas, 31

commenting, 43-45, 141

# (pound sign), 214, 344

computers, 5, 42. See also programming languages

communicating with, 6

microprocessors, 4

randomness and, 37

concatenation, 28, 42, 47, 130

conditional loops, 106-110, 115

indentation and, 106-107

conditions, 57

if statement, 59, 60-61

testing for, 59-62

constants, 156, 157

constructors, 250-251

converting, strings to numbers, 65-66, 115

Crazy Driver. See also Pygame

adding multiple enemies, 357-358

collision detection, 330-331, 350-351

dynamic access to game files, 302-305

frame rate, 293

game area, 294

game concept, 286-288

game loop, 295-299

Game Over! screen, 338-341

adding the high score, 354-356

ice cubes, adding, 348-351

increasing the difficulty, 334-336

initializing Pygame, 290-294

moving the enemy, 320-322

moving the player, 323-326

obtaining images, 289

oil slicks, 356-357

pausing, 341-343

placing the cars, 310-317

setting the background, 305-309

splash screen, 354

sprites, 313-317

tracking the score, 332-334

updating the display, 295

varying enemies, 343-348

work folders, 288-289

creating

classes, 243-244

inventory system, 230-232

lists, 80-82

methods, 247-250

new Python file, 17

user choice component, 207-208

variables, 24

CSS (Cascading Style Sheets), 363

curly braces ({ }), 225

D

data files, 362

data types, 43

datetime

class, 55, 66

library, 52-54

variable, 151

debugging, 134, 136

decisions. See also loops

elif statement, 66

else statement, 58-59, 75

if statement, 56-58, 65, 66, 67, 73

conditions, 57, 59

indentation and, 58

multiple tests and, 59-61

nested, 77

in operator, 62-63

testing for conditions, 59-62

decrypting messages, 102-103. See also encryption/decryption

def statement, 166, 167, 247. See also user-defined functions

dice

12-sided, 48

rolling, 45-46, 47

dictionaries, 225, 273

classes and, 243

functions and, 227

inventory system, 229-230, 233-237

creating, 230-232

displaying, 238

key:value pairs, 226

lists of, 228

updating, 227

dir() function, 246

display() function, 238

displaying, class properties, 246

duplicate code, 107, 322

E

editors, 7. See also IDEs (integrated development environments)

elif statement, 66, 116

else statement, 58-59, 75

encoding, 95

encryption/decryption, 95, 96, 99-102

ASCII code, 96

keys, 97-98

modulus operator, 97-98

equality comparison operator (==), 57

errors, in VS Code, 18

escape characters, 148

executing code, 19

Experience Design, 123

extend() function, 85

externalization. See also refactoring, string, 196-201

F

files. See also code(ing); game(s)

accessing dynamically, 302-305

creating, 17

data, 362

naming, 26-27

path, 302

saving, 27

test, 96

fill() method, 295

folders. See also work folder

creating

for Mac users, 14-15

for Windows users, 13-14

for loops, 90-91. See also loops

Crazy Driver, 297

iteration, 91

looping through items, 90-92

looping through numbers, 92-93

nested, 93-95

frame rate, 292-293

functions, 27, 164. See also classes; methods; variables

append(), 213

append() function, 274

arguments, 22-23, 165

blit(), 309

calling, 23, 53

collide_rect(), 331

dictionary, 227

dir(), 246

display(), 238

extend(), 85

get(), 199, 201, 233

getUserChoice(), 213-217, 236

input(), 28, 38, 65, 102, 126

numeric input and, 63-64

inputYesNo(), 221

int(), 64, 66

join(), 305

len(), 81, 89, 110, 126, 212

list, 88

methods and, 54

move_ip(), 324

now(), 53, 54

ord(), 97, 101

pop(), 85

print(), 28, 30, 31, 32, 46, 47, 55, 81, 84, 132-133

randrange(), 38, 46, 346

range(), 93

recursion, 238-239

render(), 340

returning a value, 28

reusable, 208-212

sleep(), 338

str(), 100

type(), 54

user input, 28-29

user-defined, 165-167

def statement, 166-167

passing arguments, 167-170, 209

returning values, 171-174

variables, 24, 25, 30, 46, 53

naming, 26

rules, 25-26

wrapper, 229-230, 234

G

game(s), 224. See also Pygame

Colossal Cave Adventure, 178

Crazy Driver

adding multiple enemies, 357-358

collision detection, 330-331, 350-351

displaying the high score, 354-356

frame rate, 293

game area, 294

game concept, 286-288

game loop, 295-299

Game Over! screen, 338-341

ice cubes, adding, 348-351

increasing the difficulty, 334-336

initializing Pygame, 290-294

moving the enemy, 320-322

moving the player, 323-326

obtaining images, 289

oil slicks, 356-357

pausing, 341-343

placing the cars, 310-317

setting the background, 305-309

tracking the score, 332-334

varying enemies, 343-348

work folders, 288-289

development, 364

dynamic access to files, 302-305

files and, 302

folder structure, 302

graphics

antialiasing, 340

frame rate, 292-293

pixels, 294

sprites, 313-317

updating the display, 295

Hangman, 124, 125, 138-141

displaying lists, 129-131

displaying remaining lives, 147

loops, 143-145

masking characters, 131-136, 143

restricting user input, 125-128

storing user guesses, 128-129

inventory system, 233-237, 242-243

creating, 230-232

displaying, 238

planning, 224-225

wrapper functions, 229-230

Mad Libs, 30-33

number guessing, 111-120

player management system, 242-243

Pygame and, 286, 287

splash screens, 354

surface, 294

text-based adventure, 178, 184-188

addHealth() function, 270-271

addLife() function, 267-269

battling enemies, 277-279

creating, 180-181

getHealth() function, 269-270

health property, 266

loseHealth() function, 270-271

maxhealth property, 266

processing options, 182-183

prompting for options, 181-182

random events, 275-277

saving and restoring, 280-282

shopping for items, 271-275

testing, 189-190

Zork, 178

generating random numbers, 37-38, 46

number guessing game, 111-120

get() function, 199, 201, 233

getUserChoice() function, 213-217, 236

graphics

antialiasing, 340

frame rate, 292-293

pixels, 294

sprites, 313-317

cleaning up, 340-341

moving, 320-322, 323-326

updating the display, 295

H

Hangman, 124, 125, 138-141

displaying lists, 129-131

displaying remaining lives, 147

loops, 143-145

masking characters, 131-136, 143

restricting user input, 125-128

storing user guesses, 128-129

hard-coded values, 335

I

IDEs (integrated development environments), VS Code, 9

errors, 18

installing, 10-13

if statement, 56-58, 65, 66, 67, 127, 132

conditions, 57, 59, 60, 61, 115

elif and, 62

in Hangman, 145-146

indentation and, 58

inline, 145, 249

multiple tests and, 59-61

nested, 77

in operator, 62-63

Rock, Paper, Scissors game, 74, 75

while statement and, 107

import statements, combining, 218, 307

incrementing variables, 119

indentation, 58, 77

loops and, 91-92, 106-107

index values, 81, 82-83

initializing

classes, 245, 250-251

lists, 82

Pygame, 290-294

inline if statement, 145, 249

input() function, 28, 38, 65, 102, 126. See also user input

numeric input and, 63-64

inputYesNo() function, 221

installing

VS Code, 10-13

Pygame, 288

Python, 9-10

third-party libraries, 258-259

instantiation, 246

int() function, 64, 66

inventory system, 233-237, 242-243. See also player management system

creating, 230-232

displaying, 238

planning, 224-225

wrapper functions, 229-230

iteration, 91, 94

J-K-L

JavaScript, 363

join() function, 305

len() function, 81, 89, 110, 126, 212

libraries, 36

colorama, 259-260

combining, 218

datetime, 52-54

Flask, 363

naming, 200

os, 304

pickle, 280-281

random, 36-37, 73, 141

SDL, 287

string, 155

third-party, installing, 258-259

lists, 40, 41, 80, 125, 212

accessing, 82-83

adding and removing items, 84-85

changing list items, 83-84

creating, 80-82

of dictionaries, 228

displaying, 129-131

finding items in, 85-86

initializing, 82

of lists, 213

looping through items, 90-92

multiline, 142

sorting, 86-88

storing user guesses, 128-129

syntax, 81

tuples and, 292

for loops, 101

loops, 89, 90. See also if statement

conditional, 106-110

Crazy Driver and, 295-299

for, 101

in Hangman, 143-145

indentation and, 91-92

iteration, 91, 94

lists and, 90-92

nested, 93-95

numbers and, 92-93

while statement, 106-107, 108, 109, 110, 113, 143, 146

lower() method, 71

M

Mac users, creating a work folder, 14-15

Mad Libs, 30, 31, 33

user input, 32

variables, 30-31

masking characters, 125, 143

methods, 54, 164

append(), 345

choice(), 73

constructors, 250-251

creating, 247-250

fill(), 295

lower(), 71

properties and, 55

self argument, 247-248

strip(), 71

update(), 227

upper(), 71

microprocessors, 4

Microsoft Visual Studio Code. See VS Code

Minecraft, 122

mobile app development, 364

modulus operator, 97-98

encryption and, 48

move_ip() function, 324

multiline

lists, 142

text, 200

N

naming

arguments, 168

files, 27

libraries, 200

variables, 26

nested if statement, 77

nested loops, 93-95

now() function, 53, 54

numbers

ASCII code, 96

looping through, 92-93

O

open source software, 286

in operator, 62-63

operators, 48, 60

addition, 47-48

assignment, 57

division, 48

equality comparison, 57

in, 62-63

modulus, 48, 97-98

multiplication, 48

subtraction, 48

ternary conditional, 249

optimizing your code, 194-195

ord() function, 97, 101

os library, 304

Overwatch, 122

P

parentheses, calling a function, 53

passing arguments, 22-23

passthrough variable, 173

password generator, 156

program flow, 155

requirements, 154

path, dynamic access to game files, 302-305

pickle library, 280-281

pixels, 294

plain text, 42

player management system, 242-243

classes and, 251-255

pop() function, 85

pound sign (#), 214

print() function, 28, 29, 30, 31, 32, 46, 47, 55, 66, 81, 84, 132-133

programming languages, 5, 364. See also code(ing); IDEs (integrated development environments); Python

C#, 364

editors, 7

JavaScript, 363

Python, 9

creating a new file, 17

installing, 9-10

running code, 19

syntax, 8

spoken languages and, 6-7

syntax, 6, 7

programs. See also game(s)

birthday countdown

program flow, 150

requirements, 150

password generator, 156

program flow, 155

requirements, 154

tip calculator

program flow, 153

requirements, 152

properties, 244-246. See also variables

displaying, 246

initializing, 245

methods and, 55

pseudocode, 197

Pygame, 286, 287

displaying text, 339-341

initializing, 290

installing, 288

updating the display, 326

working with images, 308-309

Python. See also; classes; functions; methods; VS Code, 9

classes, datetime, 55

comments, 43-45

creating a new file, 17

creating a work folder

for Mac users, 14-15

for Windows users, 13-14

functions, 27

arguments, 22-23

calling, 23

now(), 53

returning a value, 28

type(), 54

user input, 28-29

variables, 24, 25-26

if statement, conditions, 57

installing, 9-10

libraries, 36

datetime, 52-54

installing, 258-259

string, 155

lists, 40, 41

accessing, 82-83

adding and removing items, 84-85

changing list items, 83-84

creating, 80-82

finding items in, 85-86

initializing, 82

looping through items, 90-92

sorting, 86-88

running code, 19

serializing/deserializing data, 280

syntax, 8

variables, 43

writing your first program, 15

selecting your work folder, 16-17

Q–R

QR codes, 9

quotes, 31, 42

random items

choosing, 38-39

numbers

generating, 37-38, 46

number guessing game, 111-120

randrange() function, 38, 46, 346

range() function, 93

recursion, 238, 239

refactoring, 204-206, 221

render() function, 340

restoring your game, 280-282

restricting user input, 125-128

returning a value, 28

reusability

classes and, 243

creating a user choice component, 207-208

functions and, 208-212

getUserChoice() function, 213-217

RGB (Red, Green, Blue) values, 291

Rock, Paper, Scissors, 72-74, 75, 76

rolling dice, 47

12-sided, 48

S

saving files, 27

saving your game, 280-282

scope, 174

SDL (Simple DirectMedia Layer) library, 287

serializing/deserializing data, 280

sleep() function, 338

sorting, lists, 86-88

splash screens, 354

spoken languages, programming languages and, 6-7

sprites, 313-317

cleaning up, 340-341

moving, 320-322, 323-326

SQL, 363

storage, 224

dictionaries, 225

string, 201

str() function, 100

string library, 155

strings, 42, 70, 71

adding to, 158

case and, 71

converting to numbers, 65-66, 115

encryption and, 100-102

externalization, 196-201

numbers and, 64

storage, 201

whitespace, stripping, 72

Stringtest.py, 70

strip() method, 71

stripping whitespace, 72

surface, 294

syntax, 6, 7, 142

[ ] notation, 127

colons, 57

commas, 31

indentation and, 58

lists, 81

Python, 8

quotes, 31, 42

T

ternary conditional operator, 249

test files, 96

testing

classes, 245-246

code, 73

for conditions, 59-62

getUserChoice() function, 215-217

text-based adventure game, 189-190

unit, 125

text

externalizing, 196

multiline, 200

text-based adventure game(s), 178, 179, 184-188

battling enemies, 277-279

Colossal Cave Adventure, 178

creating, 180-181

health and lives

addHealth() function, 270-271

addLife() function, 267-269

getHealth() function, 269-270

health property, 266

loseHealth() function, 270-271

maxhealth property, 266

processing options, 182-183

prompting for options, 181-182

random events, 275-277

saving and restoring, 280-282

shopping for items, 271-275

testing, 189

work folders, 183-184

Zork, 178

third-party libraries, installing, 258-259

three-dimensional arrays, 212

tip calculator

program flow, 153

requirements, 152

tuples, 292

two-dimensional arrays, 212

type() function, 54

U

unit testing, 125. See also testing

Unity, 364

update() method, 227

updating

code, 218-220

dictionaries, 227

upper() method, 71

user choice component, creating, 207-208

user input, 28-29, 146

Mad Libs, 32

restricting, 125-128

user-defined functions, 165-167

def statement, 166-167

passing arguments, 167-170

returning values, 171-174

V

values

constant, 156

constants, 157

hard-coded, 335

RGB (Red, Green, Blue), 291

user-defined functions and, 171-174

variables, 23-24, 30, 39, 40, 42, 43, 46

__file__, 303

case sensitivity, 26, 291

concatenation, 28

creating, 24

data types, 43

datetime, 151

functions and, 53

importing, 299

incrementing, 119

initializing, 108

instantiation, 246

lists, 80

accessing, 82-83

adding and removing items, 84-85

changing list items, 83-84

creating, 80-82

finding items in, 85-86

looping through items, 90-92

sorting, 86-88

Mad Libs, 30-31

moveSpeed, 334-335

naming, 26

passthrough, 173

QUIT, 299

rules, 25-26

scope, 174

user-defined functions and, 170

values, 27, 41-42, 119

whitespace, 25

VS Code. See also Colorama

colors, 25

comments, 45

creating a work folder, 13-15, 183-184

errors, 18

Extensions panel, 12-13

installing, 10-13

Terminal window, 19, 258-259

coloring your output, 260-264

W

web development, 362-363

while loops, 106-107, 108, 109, 110, 113, 143, 146. See also conditional loops

Crazy Driver, 296-297

if statement and, 107

whitespace, 25, 72

Windows, 122

creating a work folder, 13-14

installing Python, 9

work folder

creating, 183-184

for Mac users, 14-15

for Windows users, 13-14

selecting, 16-17

wrapper functions, 229-230, 234

writing your first program, 15

selecting your work folder, 15

X-Y-Z

x,y coordinate, 309

Zork, 178

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset