Programming an Adventure Game with Snap! and Python, with Dave Briccetti

In this class, for beginning and experienced programmers, you’ll create your own adventure game using one or two different programming languages, while strengthening your programming skills, and being exposed to the big ideas of computer science.

Snap! is a blocks-based language used by many educators to teach solid computer science principles. It’s like Scratch, but with many more advanced features. Universities, high schools, and now middle schools use Snap! in computer science courses. With it you can make an adventure game with graphics and sound.

Python is one of the most popular programming languages, and it’s suitable for beginning programmers as well as professionals. Those who want to focus on Python more than Snap! will spend most of their time making a text adventure game in Python. (In this video, Dave walks you through creating one such game.)

Dave Briccetti is a highly skilled programmer and experienced computer science teacher. Watch him teach on his YouTube channel.

See a detailed log from a very successful related class by Dave from Summer 2019.

Bring your own laptop computer running macOS, Windows, or Linux, or use one provided by the school.

Resources

Python Adventure Game Explanation

You might watch this outside of class.

Day One, 2021-10-12

Let’s get acquainted and assess our current abilities. Please answer a few questions.

Python Introduction

The Python Game Engine with Sample Games

Snap! Introduction

Snap! Starter Project

Starter project

Day Two, 2021-10-19

Computing in the News

IoT Hacking and Rickrolling My High School District (Don’t try this.)

Let’s Port Scan (with Permission) Part of Athenian’s Guest Network

We’ll use nmap. If you like, try it at home with your parents’ permission.

Complete Setup

Finish any remaining items:

  • create an account on the Snap! web site, and remember or bring a reminder of your username and password
  • create an account on https://replit.com/
  • spend some time playing with Snap!, and reading the Crash Course
  • Watch my YouTube video explaining the Python adventure game engine we’ll be using
    • For those new to Python this may be confusing, but that’s OK
  • Start designing the content of your game. See the section, Planning Your Game

Snap! Intro

  • Sprites
  • Stage
    • 480 × 360
  • Costumes
  • Editing images (crop, scale, etc.)
    • Pixlr or whatever you prefer

Python Intro

  • print
  • input
  • if
  • variables

Day Three, 2021-10-21

Binary Numbers “Unplugged” Activity

Introduction

  • Number Systems
    • What different number systems do we know about? (Roman Numerals; Tally marks; Number bases like binary and decimal.)
    • Why do we normally use 10 digits? (10 fingers, plus it’s a fairly efficient way to write things compared with, say, tally marks.)
    • Why do we have different number systems? (Humans use base ten, computers use base 2 because of their on/off circuitry)
  • Bit (Binary Digit)
    • Can have the values 0 or 1 (also thought of as off or on))
      • Decimal digits can be any of the ten values 0 to 9
    • Computer circuitry works with binary numbers (made up of bits)

“Unplugged” Activity

  • Place five volunteers at front
  • Hand out cards from right to left, with students predicting what comes next
  • Repeat a few times
    • Students think of decimal number from 1–31
    • Show them in binary
      • all bits on, then from left to right, see if bits should be on and turn off as needed
  • Count starting at 0
  • How might binary numbers represent letters?
  • Kids decode a message: 01000 01001
  • Letters are actually represented using ASCII
  • What else can be represented in binary?
    • images
    • sounds
    • movies

Show and Tell from Students Already Having Python Experience

Review Frameworks

You can use my Python adventure game engine and my Snap! starter project, or create your games entirely from scratch if you like.

Big Ideas of Computer Science

Abstraction

Part of an abstraction is removing details. I explained how we can think of “Starting the car” as hiding these details:

  • fasten seatbelt
  • press brake
  • insert key
  • turn key to start position
  • wait for car to start
  • turn key back

Day Four, 2021-10-26

“Unplugged” Activity: Sorting and Searching

We have cards with the names of fruits on them. We will explore sorting and searching strategies.

  • Shuffle the cards and pass them to a row of students who hold them blank side forward
  • Have another person be the searcher
  • The searcher tries to find the card with a certain fruit
    • What strategies are available?
  • Now let’s sort the cards by fruit names (in alphabetical order) using a bubble sort
  • The searcher searches again for a different fruit name
    • Is there a new strategy available now?

Hungarian Bubble Sort Dance

Watch this if you want to see Hungarians “dancing” a bubble sort.

Big Ideas of Computer Science

Abstraction

Exercise

In Python, we can create abstractions using def to define functions. In Snap!, we can create blocks. The function or block hides the details of what it does.

Work on your Game

Show and Tell

Day Five, 2021-10-28

Collaboration with Graphics Class

Students in the graphics class are willing to make graphics for our games. Can we make a list of what we want, and then present to the graphics class?

Big Ideas of Computer Science: Algorithms

al·go·rithm | ˈælɡəˌrɪðəm |
noun
a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer: a basic algorithm for division.

More on algorithms from Wikipedia

Binary Search Algorithm Exercise

Snap!

Solution

Python

Solution

Notable Women in Computing

Three women in computing playing cards

We’ll divide a deck of Notable Women in Computing playing cards among you, and you will pick a woman in computing and tell us about her.

Work on your Game

Show and Tell

Day Six, 2021-11-02

Computing in the News

Facebook to shut down facial recognition system

Review Questions

  • What is a benefit of abstraction?
  • What are some examples of abstraction?
  • When searching for an item, what’s the advantage of having the items sorted?
  • What is an algorithm?

Work on Your Game

Show and Tell

Technique for getting numeric input in Python

def get_num(prompt: str, low: int, high: int) -> int:
    num = None
    while not num:
        try:
            num = int(input(prompt))
            if num < low or num > high:
                print('Number out of range')
                num = None
        except ValueError:
            print('Oops. That is not a number')
    return num

get_num('Where do you want to go? (1-4)', 1, 4)

This video explains some similar code:

Day Seven, 2021-11-04

Computing in the News: Robots Assemble IDEA Chair

Review Questions

  • Can you explain the get_num function above?
  • Can you explain binary search?
  • Where can you search for public domain graphics and sounds?
  • Must you give credit in your project for CC0-licensed art you use?
  • How does a bubble sort work?
  • What are the first three powers of 10? (10⁰, 10¹, 10²)
  • What are the first three powers of 2? (2⁰, 2¹, 2²)

More Ideas for Snap!

Picture of a simple Snap! adventure game

Work on Your Game

Show and Tell

Dave shows Tower Defense Unity Game

Future Class Ideas

Session 2 Ideas

Day Eight, 2021-11-09

Computing in the News

Drone first to ‘specifically target energy infrastructure,’

Review Questions

  • What Python feature did we learn about that can catch a ValueError from the int function?

Next Session

What would make a good class?

Work on Your Game

Show and Tell

Dave will show a Letter Boxed Game Solver he’s been developing with some private students.

Python Answers

How to implement a “cooldown” feature

from time import time
next_jump_allowed_at = time()

while True:
    cmd = input('Do what? ')
    if not cmd:
        break
    if cmd == 'jump':
        if time() > next_jump_allowed_at:
            next_jump_allowed_at = time() + 10
        else:
            print('Cooling down the jump engine')

How to display a sequence of messages with a delay in between

from time import sleep
from typing import List

def show_for(msg: str, seconds: int) -> None:
    print(msg)
    sleep(seconds)

# triple-quoted strings can span multiple lines
messages: str = '''You walk to the house.
A goblin pops out.
You open the door.
You go into the house.
The floor creaks.'''
lines: List[str] = messages.split('\n')  # split on newline to create a list of strings

for line in lines:
    show_for(line, 1)

Day Nine, 2021-11-11

Computing in the News

Congress mandates new car technology to stop drunken driving

Review Questions (Using Talking Name Picker)

  • Python
    • What are some benefits of using a professional-strength integrated development environment (IDE) for Python programming?
    • Explain the “cooldown” code Dave showed last time
    • Explain the show_for function Dave showed last time
  • Snap!
    • Confirm you know how to paint and import costumes for the stage and for sprites
    • How can you make the background of your scene change?
  • Both
    • What is your plan for your game?
      • What art and sound?
      • What characters?
      • What items to pick up?
      • What events may occur?

Work on Your Game

Show and Tell

Day Ten, 2021-11-16

Computing in the News

Artificial intelligence predicts eye movements

Improving One Student’s Code in 16 Steps

Arjun’s project on Github, with Dave’s recommended changes

Work on Your Game

Show and Tell

Day Eleven, 2021-11-18

Computing in the News

IBM Creates Largest Superconducting Quantum Computer

Dave shows Letter Boxed game solver

Prepare for Demo

Visit Other Classes

Demo

Day Twelve (Last Day), 2021-11-30

Computing in the News

Advent of Code

Improve Code

Learn More Python and Snap!