diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..396b80f --- /dev/null +++ b/.gitignore @@ -0,0 +1,161 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# CMake +CMakeFiles/ +CMakeCache.txt +CMakeScripts/ +CTestTestfile.cmake +cmake_install.cmake +compile_commands.json +Makefile +Testing/ + +# Poetry +# According to https://python-poetry.org/docs/glossary/#lock-file +# it is recommended to include poetry.lock in version control. +# However, in case of collaboration, if having a large number of +# developers, it may be better to keep the file out of version control. +#poetry.lock + +# Pylance (https://github.com/microsoft/pylance-release) +.pyright + +# PyInstaller +# It's not generally necessary to include this in version control if you +# are using PyInstaller to generate your executables. +# https://pyinstaller.readthedocs.io/en/stable/operating-mode.html#how-the-one-file-program-works +#dist/ +#build/ +#*.exe +#*.spec + +# End of https://www.toptal.com/developers/gitignore/api/python diff --git a/Python/Tetris/GameBoard.py b/Python/Tetris/GameBoard.py index 66c9374..1becb49 100644 --- a/Python/Tetris/GameBoard.py +++ b/Python/Tetris/GameBoard.py @@ -1,5 +1,23 @@ from tkinter import * +class CycleList(list): + """List that cycles through elements when indexing""" + + def __init__(self, *args): + super().__init__(*args) + self._index = 0 + + def __getitem__(self, index): + return super().__getitem__(index % len(self)) + + def __setitem__(self, index, value): + super().__setitem__(index % len(self), value) + + def __next__(self): + next_item = self[self._index] + self._index += 1 + return next_item + class Wrapper: pass class Coords: @@ -156,13 +174,14 @@ def bump(self, newXY): def kick(self, newXY): pass +EMPTY_GRID = object() class GameGrid: # List of X coordinates, containing lists of y coordinates # Origin is @ top left # 10 x 20 default - board: list[list[Block]] = [[]] + board: list[list[Block]] = EMPTY_GRID xSize = int ySize = int @@ -171,11 +190,9 @@ class GameGrid: def __init__(self, xSize: int=10, ySize: int=20): self.xSize = xSize self.ySize = ySize - self.board = [ - [None for y in range(self.ySize)] - for x in range(self.xSize) - ] - + if self.board is EMPTY_GRID: + self.board = [[None]*self.ySize]*self.xSize + def __repr__(self): string = "