Tetris For Intro/Intermediate Programmers (Spring 2015 update)

David Kosbie
Carnegie Mellon University
koz@cmu.edu

Abstract

These notes are an updated version of these earlier notes. The changes are just to bring those notes into conformity with 15-112-s15 and in particular its event-based animation framework.

These notes are designed for intro/intermediate programmers (specifically, students who have completed about 6-to-8 weeks of 15-112 at CMU).  The notes are adapted from three earlier sets of notes, and may contain some peculiarities due to this history.

Note that this design for Tetris is somewhat simplified for these purposes, though the end result is indeed a reasonably functional game of Tetris.  Also, note that the Python code accompanying these notes is not fully tested and is not necessarily designed to exacting standards.

Finally:  the techniques used to create this game can be used to create many other popular arcade games.  Have fun!

Contents

  1. Prerequisites (Python, Tkinter, and Event-Based Animations)
  2. Building Tetris
    1. Design overview
    2. Creating and drawing the board
    3. Creating and drawing the fallingPiece
    4. Moving the fallingPiece left/right/down
    5. Rotating the fallingPiece
    6. Dropping and Placing the fallingPiece and handling Game-Over
    7. Removing full rows, keeping score, and playing MIDI
    8. More ideas