Skip to content

Commit

Permalink
debug current piece
Browse files Browse the repository at this point in the history
  • Loading branch information
dgomes committed Nov 16, 2021
1 parent e52dfe8 commit 62565b5
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 27 deletions.
1 change: 1 addition & 0 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ async def loop(self):

self._lastkeypress = None

logger.debug("Current piece: %s", self.current_piece)
return {
"game": self.game,
"piece": self.current_piece.positions if self.current_piece else None,
Expand Down
134 changes: 107 additions & 27 deletions shape.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,127 @@
from common import Dimensions
import random

S = [
[".....", ".....", "..11.", ".11..", "....."],
[".....", "..1..", "..11.", "...1.", "....."],
S = "S", [
[".....",
".....",
"..11.",
".11..",
"....."],
[".....",
"..1..",
"..11.",
"...1.",
"....."],
]

Z = [
[".....", ".....", ".11..", "..11.", "....."],
[".....", "..1..", ".11..", ".1...", "....."],
Z = "Z", [
[".....",
".....",
".11..",
"..11.",
"....."],
[".....",
"..1..",
".11..",
".1...",
"....."],
]

I = [
["..1..", "..1..", "..1..", "..1..", "....."],
[".....", "1111.", ".....", ".....", "....."],
I = "I", [
["..1..",
"..1..",
"..1..",
"..1..",
"....."],
[".....",
"1111.",
".....",
".....",
"....."],
]

O = [[".....", ".....", ".11..", ".11..", "....."]]
O = "O", [
[".....",
".....",
".11..",
".11..",
"....."]
]


J = [
[".....", ".1...", ".111.", ".....", "....."],
[".....", "..11.", "..1..", "..1..", "....."],
[".....", ".....", ".111.", "...1.", "....."],
[".....", "..1..", "..1..", ".11..", "....."],
J = "J", [
[".....",
".1...",
".111.",
".....",
"....."],
[".....",
"..11.",
"..1..",
"..1..",
"....."],
[".....",
".....",
".111.",
"...1.",
"....."],
[".....",
"..1..",
"..1..",
".11..",
"....."],
]

L = [
[".....", "...1.", ".111.", ".....", "....."],
[".....", "..1..", "..1..", "..11.", "....."],
[".....", ".....", ".111.", ".1...", "....."],
[".....", ".11..", "..1..", "..1..", "....."],
L = "L", [
[".....",
"...1.",
".111.",
".....",
"....."],
[".....",
"..1..",
"..1..",
"..11.",
"....."],
[".....",
".....",
".111.",
".1...",
"....."],
[".....",
".11..",
"..1..",
"..1..",
"....."],
]

T = [
[".....", "..1..", ".111.", ".....", "....."],
[".....", "..1..", "..11.", "..1..", "....."],
[".....", ".....", ".111.", "..1..", "....."],
[".....", "..1..", ".11..", "..1..", "....."],
T = "T", [
[".....",
"..1..",
".111.",
".....",
"....."],
[".....",
"..1..",
"..11.",
"..1..",
"....."],
[".....",
".....",
".111.",
"..1..",
"....."],
[".....",
"..1..",
".11..",
"..1..",
"....."],
]


class Shape:
def __init__(self, plan) -> None:
self.plan = plan
self.name, self.plan = plan
self.rotation = 0
self.dimensions = Dimensions(5, 5)

Expand Down Expand Up @@ -89,8 +167,10 @@ def y(self, y):
self.set_pos(self._x, y)

def __str__(self) -> str:
return f"Shape({self._x},{self._y}) -> {self.positions}"
return f"Shape < {self.name} > @({self._x},{self._y}) -> {self.positions}"

def __repr__(self) -> str:
return self.__str__()

SHAPES = [Shape(s) for s in [S, Z, I, O, J, T, L]]

Expand Down

0 comments on commit 62565b5

Please sign in to comment.