tetris in the terminal with python
to run:
python3 tetris.py
controls: left
, right
, and down
to move the current piece. space
to hard drop. z
and x
to rotate. c
to hold.
all pieces are represented by tuples of integers: in binary a 1 indicates the piece is in that cell and a 0 indicates that it isn't. this lets us do many tetris operations through bit operations
the Tetris
object is designed to allow for custom pieces and board sizes.
i used the curses
library for user input and display.
possible extensions:
- game over checking is unimplemented. all the functionality for this theoretically exists but i couldn't get curses to print the game over message
- adding in different colors for different pieces. i had a plan to do this by keeping
$n$ versions of the board for each color, then bitwise-or
ing all the color boards together to do the full board computations - rotating pieces (and input in general) feels somewhat funky compared to "real" tetris
- add in the bag system for choosing the next piece. right now the next piece is chosen at random
- adding in sound effects and music
a screenshot of in-progress tetris development