CONTENTS IN DETAIL

ACKNOWLEDGMENTS

INTRODUCTION

Why Learn to Program?

Why Python?

Why Minecraft?

What’s in This Book?

Online Resources

Let the Adventure Begin!

1
SETTING UP FOR YOUR ADVENTURE

Setting Up Your Windows PC

Installing Minecraft

Installing Python

Installing Java

Installing the Minecraft Python API and Spigot

Running Spigot and Creating a Game

Starting Over with a New World

Playing Offline

Switching to Survival Mode

Setting Up Your Mac

Installing Minecraft

Installing Python

Installing Java

Installing the Minecraft Python API and Spigot

Running Spigot and Creating a Game

Starting Over with a New World

Playing Offline

Switching to Survival Mode

Setting Up Your Raspberry Pi

Getting to Know IDLE

Getting to Know the Python Shell

Say Hello to IDLE’s Text Editor

When to Use the Python Shell and When to Use the Text Editor

The Prompts Used in This Book

Testing Your Minecraft Python Setup

2
TELEPORTING WITH VARIABLES

What Is a Program?

Storing Data with Variables

The Structure of Programming Languages

Syntax Rules for Variables

Changing the Values of Variables

Integers

Mission #1: Teleport the Player

Floats

Mission #2: Go Exactly Where You Want

Slowing Down Teleportation Using the time Module

Mission #3: Teleportation Tour

Debugging

Mission #4: Fix the Buggy Teleportation

What You Learned

3
BUILDING QUICKLY AND TRAVELING FAR WITH MATH

Expressions and Statements

Operators

Addition

Mission #5: Stack Blocks

Mission #6: Super Jump

Subtraction

Mission #7: Change the Blocks Under You

Using Math Operators in Arguments

Mission #8: Speed Building

Multiplication

Division

Mission #9: Spectacular Spires

Exponents

Parentheses and Order of Operations

Handy Math Tricks

Shorthand Operators

Playing with Random Numbers

Mission #10: Super Jump Somewhere New!

What You Learned

4
CHATTING WITH STRINGS

What Are Strings?

The print() Function

Mission #11: Hello, Minecraft World

The input() Function

Mission #12: Write Your Own Chat Message

Joining Strings

Converting Numbers to Strings

Concatenating Integers and Floats

Mission #13: Add Usernames to Chat

Converting Strings to Integers with int()

Mission #14: Create a Block with input

Bounce Back from Errors

Mission #15: Only Numbers Allowed

Mission #16: Sprint Record

What You Learned

5
FIGURING OUT WHAT’S TRUE AND FALSE WITH BOOLEANS

Boolean Basics

Mission #17: Stop Smashing Blocks!

Concatenating Booleans

Comparators

Equal To

Mission #18: Am I Swimming?

Not Equal To

Mission #19: Am I Standing in Something Other Than Air?

Greater Than and Less Than

Greater Than or Equal To and Less Than or Equal To

Mission #20: Am I Above the Ground?

Mission #21: Am I Close to Home?

Logical Operators

and

Mission #22: Am I Entirely Underwater?

or

Mission #23: Am I in a Tree?

not

Mission #24: Is This Block Not a Melon?

Logical Operator Order

Is My Number Between Two Others?

Mission #25: Am I in the House?

What You Learned

6
MAKING MINI-GAMES WITH IF STATEMENTS

Using if Statements

Mission #26: Blast a Crater

else Statements

Mission #27: Prevent Smashing, or Not

elif Statements

Mission #28: Offer a Gift

Chaining Together elif Statements

Mission #29: Teleport to the Right Place

Nested if Statements

Mission #30: Open a Secret Passage

Using if Statements to Test a Range of Values

Mission #31: Restrict Teleport Locations

Boolean Operators and if Statements

Mission #32: Take a Shower

What You Learned

7
DANCE PARTIES AND FLOWER PARADES WITH WHILE LOOPS

A Simple while Loop

Mission #33: A Random Teleportation Tour

Controlling Loops with a Count Variable

Mission #34: The Watery Curse

Infinite while Loops

Mission #35: Flower Trail

Fancy Conditions

Mission #36: Diving Contest

Boolean Operators and while Loops

Checking a Range of Values in while Loops

Mission #37: Make a Dance Floor

Nested if Statements and while Loops

Mission #38: The Midas Touch

Ending a while Loop with break

Mission #39: Create a Persistent Chat with a Loop

while-else Statements

Mission #40: Hot and Cold

What You Learned

8
FUNCTIONS GIVE YOU SUPERPOWERS

Defining Your Own Functions

Calling a Function

Functions Take Arguments

Mission #41: Build a Forest

Refactoring a Program

Mission #42: Refactor Away

Commenting with Docstrings

Line Breaks in Arguments

Function Return Values

Mission #43: Block ID Reminder

Using if Statements and while Loops in Functions

if Statements

Mission #44: Wool Color Helper

while Loops

Mission #45: Blocks, Everywhere

Global and Local Variables

Mission #46: A Moving Block

What You Learned

9
HITTING THINGS WITH LISTS AND DICTIONARIES

Using Lists

Accessing a List Item

Changing a List Item

Mission #47: High and Low

Manipulating Lists

Adding an Item

Inserting an Item

Deleting an Item

Mission #48: Progress Bar

Treating Strings like Lists

Tuples

Setting Variables with Tuples

Mission #49: Sliding

Returning a Tuple

Other Useful Features of Lists

List Length

Mission #50: Block Hits

Randomly Choosing an Item

Mission #51: Random Block

Copying a List

Items and if Statements

Mission #52: Night Vision Sword

Dictionaries

Defining a Dictionary

Accessing Items in Dictionaries

Mission #53: Sightseeing Guide

Changing or Adding an Item in a Dictionary

Deleting Items in Dictionaries

Mission #54: Block Hits Score

What You Learned

10
MINECRAFT MAGIC WITH FOR LOOPS

A Simple for Loop

Mission #55: Magic Wand

The range() Function

Mission #56: Magic Stairs

Playing Around with range()

Other List Functions

Mission #57: Pillars

Mission #58: Pyramid

Looping Over a Dictionary

Mission #59: Scoreboard

for-else Loops

Breaking a for-else Loop

Mission #60: The Diamond Prospector

Nested for Loops and Multidimensional Lists

Thinking in Two Dimensions

Accessing Values in 2D Lists

Mission #61: Pixel Art

Generating 2D Lists with Loops

Mission #62: A Weather-Worn Wall

Thinking in Three Dimensions

Outputting 3D Lists

Accessing Values in 3D Lists

Mission #63: Duplicate a Building

What You Learned

11
SAVING AND LOADING BUILDINGS WITH FILES AND MODULES

Using Files

Opening a File

Writing to and Saving a File

Reading a File

Reading a Line of a File

Mission #64: To-Do List

Part 1: Writing the To-Do List

Part 2: Displaying the To-Do List

Using Modules

The pickle Module

Importing pickle

Importing One Function with the from Clause

Importing All Functions with *

Giving a Module a Nickname

Mission #65: Save a Building

Part 1: Saving the Building

Part 2: Loading the Building

Storing Lots of Data with the shelve Module

Opening a File with shelve

Adding, Modifying, and Accessing Items with shelve

Mission #66: Save a Collection of Structures

Part 1: Saving a Structure to a Collection

Part 2: Loading a Structure from a Collection

Installing New Modules with pip

Using pip on Windows

Using pip on a Mac or Raspberry Pi

Using a Module from pip: Flask

Mission #67: Position Website

What You Learned

12
GETTING CLASSY WITH OBJECT-ORIENTED PROGRAMMING

Object-Oriented Basics

Creating a Class

Creating an Object

Accessing Attributes

Mission #68: Location Objects

Understanding Methods

Mission #69: Ghost House

Returning Values with Methods

Mission #70: Ghost Castle

Creating Multiple Objects

Mission #71: Ghost Town

Class Attributes

Understanding Inheritance

Inheriting a Class

Adding New Methods to Subclasses

Mission #72: Ghost Hotel

Overriding Methods and Attributes

Mission #73: Ghost Tree

What You Learned

AFTERWORD

BLOCK ID CHEAT SHEET

INDEX

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

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