Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
36 changes: 25 additions & 11 deletions Python/Tetris/GameBoard.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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 = "<GameBoard grid object:"
for x, xList in enumerate(self.board):
Expand All @@ -190,7 +207,8 @@ def __repr__(self):
def __getitem__(self, xy: Coords):
x, y = (xy.x, xy.y)
return self.board[x][y]
def __setitem__(self, xy, newBlock):

def __setitem__(self, xy: Coords, newBlock: Block):
x, y = (xy.x, xy.y)
self.board[x][y] = newBlock

Expand Down Expand Up @@ -242,7 +260,6 @@ def draw(self, canvas: Canvas, scale):

canvas.pack(expand = True, fill = BOTH)


class Game:

"""Game class to run alongside main loop"""
Expand Down Expand Up @@ -271,13 +288,10 @@ def __init__(self, frame: Frame, scale: int=40):

def loop(self):
self._canvas.delete("all")

self._grid.draw(self._canvas, self._scale)

self._grid.activeTetromino.xy.y += 1

def key_press(self, event: Event):
key = event.keysym

if key == "Up":
self._grid.activeTetromino.rotate()
Binary file removed Python/Tetris/__pycache__/GameBoard.cpython-312.pyc
Binary file not shown.
Binary file removed Python/Tetris/__pycache__/GameBoard.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.