An open API service indexing awesome lists of open source software.

https://github.com/reeceyang/tetris

tetris in the terminal with python
https://github.com/reeceyang/tetris

Last synced: 3 months ago
JSON representation

tetris in the terminal with python

Awesome Lists containing this project

README

          

# tetris
tetris in the terminal with python

Screen Shot 2023-10-24 at 11 07 23 PM

to run:
```bash
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

Screen Shot 2023-10-24 at 1 12 18 PM

_a screenshot of in-progress tetris development_