Compare commits
21 Commits
b8e20199af
...
0.1
Author | SHA1 | Date | |
---|---|---|---|
abaeb3be9a | |||
dff4ae487a | |||
5c830fd828 | |||
a46c07af8b | |||
338371f443 | |||
a95463438e | |||
06fe72d8db | |||
4a69c12349 | |||
2bd75be892 | |||
3015a36984 | |||
7fc342e061 | |||
0e68ea4e51 | |||
b95478ea8d | |||
df8257c4da | |||
0b3dd847d3 | |||
2a7900586c | |||
be66bada11 | |||
02e4aa066d | |||
5b6cfd6512 | |||
f1ffb1a7c6 | |||
dda475a584 |
11
README.md
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
Tetris clone made with Python and Arcade graphic library
|
Tetris clone made with Python and Arcade graphic library
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* [Python](https://www.python.org/)
|
* [Python](https://www.python.org/) 3.6 or upper
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
@ -26,3 +28,10 @@ python tetrarcade.py
|
|||||||
* Linux: Edit `~/.local/share/Tetrarcade/TetrArcade.ini`
|
* Linux: Edit `~/.local/share/Tetrarcade/TetrArcade.ini`
|
||||||
|
|
||||||
Use key name from [arcade.key package](http://arcade.academy/arcade.key.html).
|
Use key name from [arcade.key package](http://arcade.academy/arcade.key.html).
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python -m pip install -r build-requirements.txt
|
||||||
|
python setup.py bdist
|
||||||
|
```
|
||||||
|
186
TetrArcade.py
@ -3,21 +3,21 @@ import sys
|
|||||||
import locale
|
import locale
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
try:
|
|
||||||
import configparser
|
import configparser
|
||||||
except ImportError:
|
|
||||||
import ConfigParser as configparser
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import arcade
|
import arcade
|
||||||
except ImportError:
|
except ImportError as e:
|
||||||
sys.exit(
|
sys.exit(
|
||||||
"""This game require arcade library.
|
str(e)
|
||||||
|
+ """
|
||||||
|
This game require arcade library.
|
||||||
You can install it with:
|
You can install it with:
|
||||||
python -m pip install --user arcade"""
|
python -m pip install --user arcade"""
|
||||||
)
|
)
|
||||||
|
|
||||||
import tetrislogic
|
from tetrislogic import TetrisLogic, Color, State
|
||||||
|
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
@ -27,7 +27,6 @@ WINDOW_HEIGHT = 600
|
|||||||
WINDOW_MIN_WIDTH = 517
|
WINDOW_MIN_WIDTH = 517
|
||||||
WINDOW_MIN_HEIGHT = 388
|
WINDOW_MIN_HEIGHT = 388
|
||||||
WINDOW_TITLE = "TETRARCADE"
|
WINDOW_TITLE = "TETRARCADE"
|
||||||
MINO_SIZE = 20
|
|
||||||
BG_COLOR = (7, 11, 21)
|
BG_COLOR = (7, 11, 21)
|
||||||
|
|
||||||
# Delays (seconds)
|
# Delays (seconds)
|
||||||
@ -38,19 +37,31 @@ NORMAL_ALPHA = 200
|
|||||||
PRELOCKED_ALPHA = 100
|
PRELOCKED_ALPHA = 100
|
||||||
GHOST_ALPHA = 30
|
GHOST_ALPHA = 30
|
||||||
MATRIX_BG_ALPHA = 100
|
MATRIX_BG_ALPHA = 100
|
||||||
|
BAR_ALPHA = 75
|
||||||
|
|
||||||
# Sprites
|
# Sprites
|
||||||
WINDOW_BG_PATH = "images/bg.jpg"
|
WINDOW_BG_PATH = "res/bg.jpg"
|
||||||
MATRIX_SPRITE_PATH = "images/matrix.png"
|
MATRIX_BG_PATH = "res/matrix.png"
|
||||||
MINOES_SPRITES_PATHS = {
|
HELD_BG_PATH = "res/held.png"
|
||||||
"orange": "images/orange_mino.png",
|
NEXT_BG_PATH = "res/next.png"
|
||||||
"blue": "images/blue_mino.png",
|
MINOES_SPRITES_PATH = "res/minoes.png"
|
||||||
"yellow": "images/yellow_mino.png",
|
Color.PRELOCKED = 7
|
||||||
"cyan": "images/cyan_mino.png",
|
MINOES_COLOR_ID = {
|
||||||
"green": "images/green_mino.png",
|
Color.BLUE: 0,
|
||||||
"red": "images/red_mino.png",
|
Color.CYAN: 1,
|
||||||
"magenta": "images/magenta_mino.png"
|
Color.GREEN: 2,
|
||||||
|
Color.MAGENTA: 3,
|
||||||
|
Color.ORANGE: 4,
|
||||||
|
Color.RED: 5,
|
||||||
|
Color.YELLOW: 6,
|
||||||
|
Color.PRELOCKED: 7,
|
||||||
}
|
}
|
||||||
|
MINO_SIZE = 20
|
||||||
|
MINO_SPRITE_SIZE = 21
|
||||||
|
TEXTURES = arcade.load_textures(
|
||||||
|
MINOES_SPRITES_PATH, ((i * MINO_SPRITE_SIZE, 0, MINO_SPRITE_SIZE, MINO_SPRITE_SIZE) for i in range(8))
|
||||||
|
)
|
||||||
|
TEXTURES = {color: TEXTURES[i] for color, i in MINOES_COLOR_ID.items()}
|
||||||
|
|
||||||
# User profile path
|
# User profile path
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
@ -63,7 +74,7 @@ CONF_PATH = os.path.join(USER_PROFILE_DIR, "TetrArcade.ini")
|
|||||||
|
|
||||||
# Text
|
# Text
|
||||||
TEXT_COLOR = arcade.color.BUBBLES
|
TEXT_COLOR = arcade.color.BUBBLES
|
||||||
FONT_NAME = "joystix monospace.ttf"
|
FONT_NAME = "res/joystix monospace.ttf"
|
||||||
STATS_TEXT_MARGIN = 40
|
STATS_TEXT_MARGIN = 40
|
||||||
STATS_TEXT_SIZE = 14
|
STATS_TEXT_SIZE = 14
|
||||||
STATS_TEXT_WIDTH = 150
|
STATS_TEXT_WIDTH = 150
|
||||||
@ -72,20 +83,23 @@ HIGHLIGHT_TEXT_SIZE = 20
|
|||||||
|
|
||||||
|
|
||||||
class MinoSprite(arcade.Sprite):
|
class MinoSprite(arcade.Sprite):
|
||||||
|
|
||||||
def __init__(self, mino, window, alpha):
|
def __init__(self, mino, window, alpha):
|
||||||
super().__init__(MINOES_SPRITES_PATHS[mino.color], window.scale)
|
super().__init__()
|
||||||
self.alpha = alpha
|
self.alpha = alpha
|
||||||
self.window = window
|
self.window = window
|
||||||
|
self.append_texture(TEXTURES[mino.color])
|
||||||
|
self.append_texture(TEXTURES[Color.PRELOCKED])
|
||||||
|
self.set_texture(0)
|
||||||
|
|
||||||
def set_position(self, x, y):
|
def refresh(self, x, y, prelocked=False):
|
||||||
|
self.scale = self.window.scale
|
||||||
size = MINO_SIZE * self.scale
|
size = MINO_SIZE * self.scale
|
||||||
self.left = self.window.matrix_bg.left + x * size
|
self.left = self.window.matrix_bg.left + x * size
|
||||||
self.bottom = self.window.matrix_bg.bottom + y * size
|
self.bottom = self.window.matrix_bg.bottom + y * size
|
||||||
|
self.set_texture(prelocked)
|
||||||
|
|
||||||
|
|
||||||
class MinoesSprites(arcade.SpriteList):
|
class MinoesSprites(arcade.SpriteList):
|
||||||
|
|
||||||
def resize(self, scale):
|
def resize(self, scale):
|
||||||
for sprite in self:
|
for sprite in self:
|
||||||
sprite.scale = scale
|
sprite.scale = scale
|
||||||
@ -93,7 +107,6 @@ class MinoesSprites(arcade.SpriteList):
|
|||||||
|
|
||||||
|
|
||||||
class TetrominoSprites(MinoesSprites):
|
class TetrominoSprites(MinoesSprites):
|
||||||
|
|
||||||
def __init__(self, tetromino, window, alpha=NORMAL_ALPHA):
|
def __init__(self, tetromino, window, alpha=NORMAL_ALPHA):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.tetromino = tetromino
|
self.tetromino = tetromino
|
||||||
@ -103,18 +116,12 @@ class TetrominoSprites(MinoesSprites):
|
|||||||
self.append(mino.sprite)
|
self.append(mino.sprite)
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
if self.tetromino.prelocked:
|
|
||||||
alpha = PRELOCKED_ALPHA
|
|
||||||
else:
|
|
||||||
alpha = self.alpha
|
|
||||||
for mino in self.tetromino:
|
for mino in self.tetromino:
|
||||||
coord = mino.coord + self.tetromino.coord
|
coord = mino.coord + self.tetromino.coord
|
||||||
mino.sprite.set_position(coord.x, coord.y)
|
mino.sprite.refresh(coord.x, coord.y, self.tetromino.prelocked)
|
||||||
mino.sprite.alpha = alpha
|
|
||||||
|
|
||||||
|
|
||||||
class MatrixSprites(MinoesSprites):
|
class MatrixSprites(MinoesSprites):
|
||||||
|
|
||||||
def __init__(self, matrix):
|
def __init__(self, matrix):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.matrix = matrix
|
self.matrix = matrix
|
||||||
@ -124,14 +131,13 @@ class MatrixSprites(MinoesSprites):
|
|||||||
for y, line in enumerate(self.matrix):
|
for y, line in enumerate(self.matrix):
|
||||||
for x, mino in enumerate(line):
|
for x, mino in enumerate(line):
|
||||||
if mino:
|
if mino:
|
||||||
mino.sprite.set_position(x, y)
|
mino.sprite.refresh(x, y)
|
||||||
self.append(mino.sprite)
|
self.append(mino.sprite)
|
||||||
|
|
||||||
|
|
||||||
class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
class TetrArcade(TetrisLogic, arcade.Window):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
locale.setlocale(locale.LC_ALL, '')
|
locale.setlocale(locale.LC_ALL, "")
|
||||||
self.highlight_texts = []
|
self.highlight_texts = []
|
||||||
self.tasks = {}
|
self.tasks = {}
|
||||||
|
|
||||||
@ -154,26 +160,23 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
|||||||
title=WINDOW_TITLE,
|
title=WINDOW_TITLE,
|
||||||
resizable=True,
|
resizable=True,
|
||||||
antialiasing=False,
|
antialiasing=False,
|
||||||
fullscreen = self.init_fullscreen
|
fullscreen=self.init_fullscreen,
|
||||||
)
|
)
|
||||||
|
|
||||||
arcade.set_background_color(BG_COLOR)
|
arcade.set_background_color(BG_COLOR)
|
||||||
self.set_minimum_size(WINDOW_MIN_WIDTH, WINDOW_MIN_HEIGHT)
|
self.set_minimum_size(WINDOW_MIN_WIDTH, WINDOW_MIN_HEIGHT)
|
||||||
self.bg = arcade.Sprite(WINDOW_BG_PATH)
|
self.bg = arcade.Sprite(WINDOW_BG_PATH)
|
||||||
self.matrix_bg = arcade.Sprite(MATRIX_SPRITE_PATH)
|
self.matrix_bg = arcade.Sprite(MATRIX_BG_PATH)
|
||||||
self.matrix_bg.alpha = MATRIX_BG_ALPHA
|
self.matrix_bg.alpha = MATRIX_BG_ALPHA
|
||||||
self.held_bg = arcade.Sprite("images/held.png")
|
self.held_bg = arcade.Sprite(HELD_BG_PATH)
|
||||||
self.held_bg.alpha = MATRIX_BG_ALPHA
|
self.held_bg.alpha = BAR_ALPHA
|
||||||
self.next_bg = arcade.Sprite("images/next.png")
|
self.next_bg = arcade.Sprite(NEXT_BG_PATH)
|
||||||
self.next_bg.alpha = MATRIX_BG_ALPHA
|
self.next_bg.alpha = BAR_ALPHA
|
||||||
self.matrix.sprites = MatrixSprites(self.matrix)
|
self.matrix.sprites = MatrixSprites(self.matrix)
|
||||||
self.on_resize(self.init_width, self.init_height)
|
self.on_resize(self.init_width, self.init_height)
|
||||||
|
|
||||||
def new_conf(self):
|
def new_conf(self):
|
||||||
self.conf["WINDOW"] = {
|
self.conf["WINDOW"] = {"width": WINDOW_WIDTH, "height": WINDOW_HEIGHT, "fullscreen": False}
|
||||||
"width": WINDOW_WIDTH,
|
|
||||||
"height": WINDOW_HEIGHT,
|
|
||||||
"fullscreen": False
|
|
||||||
}
|
|
||||||
self.conf["KEYBOARD"] = {
|
self.conf["KEYBOARD"] = {
|
||||||
"start": "ENTER",
|
"start": "ENTER",
|
||||||
"move left": "LEFT",
|
"move left": "LEFT",
|
||||||
@ -184,12 +187,13 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
|||||||
"rotate counter": "Z",
|
"rotate counter": "Z",
|
||||||
"hold": "C",
|
"hold": "C",
|
||||||
"pause": "ESCAPE",
|
"pause": "ESCAPE",
|
||||||
"fullscreen": "F11"
|
"fullscreen": "F11",
|
||||||
}
|
}
|
||||||
|
self.conf["AUTO-REPEAT"] = {"delay": 0.3, "period": 0.01}
|
||||||
self.load_conf()
|
self.load_conf()
|
||||||
if not os.path.exists(USER_PROFILE_DIR):
|
if not os.path.exists(USER_PROFILE_DIR):
|
||||||
os.makedirs(USER_PROFILE_DIR)
|
os.makedirs(USER_PROFILE_DIR)
|
||||||
with open(CONF_PATH, 'w') as f:
|
with open(CONF_PATH, "w") as f:
|
||||||
self.conf.write(f)
|
self.conf.write(f)
|
||||||
|
|
||||||
def load_conf(self):
|
def load_conf(self):
|
||||||
@ -197,12 +201,14 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
|||||||
self.init_height = int(self.conf["WINDOW"]["height"])
|
self.init_height = int(self.conf["WINDOW"]["height"])
|
||||||
self.init_fullscreen = self.conf["WINDOW"].getboolean("fullscreen")
|
self.init_fullscreen = self.conf["WINDOW"].getboolean("fullscreen")
|
||||||
|
|
||||||
|
for action, key in self.conf["KEYBOARD"].items():
|
||||||
|
self.conf["KEYBOARD"][action] = key.upper()
|
||||||
self.key_map = {
|
self.key_map = {
|
||||||
tetrislogic.State.STARTING: {
|
State.STARTING: {
|
||||||
getattr(arcade.key, self.conf["KEYBOARD"]["start"]): self.new_game,
|
getattr(arcade.key, self.conf["KEYBOARD"]["start"]): self.new_game,
|
||||||
getattr(arcade.key, self.conf["KEYBOARD"]["fullscreen"]): self.toggle_fullscreen
|
getattr(arcade.key, self.conf["KEYBOARD"]["fullscreen"]): self.toggle_fullscreen,
|
||||||
},
|
},
|
||||||
tetrislogic.State.PLAYING: {
|
State.PLAYING: {
|
||||||
getattr(arcade.key, self.conf["KEYBOARD"]["move left"]): self.move_left,
|
getattr(arcade.key, self.conf["KEYBOARD"]["move left"]): self.move_left,
|
||||||
getattr(arcade.key, self.conf["KEYBOARD"]["move right"]): self.move_right,
|
getattr(arcade.key, self.conf["KEYBOARD"]["move right"]): self.move_right,
|
||||||
getattr(arcade.key, self.conf["KEYBOARD"]["soft drop"]): self.soft_drop,
|
getattr(arcade.key, self.conf["KEYBOARD"]["soft drop"]): self.soft_drop,
|
||||||
@ -211,28 +217,31 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
|||||||
getattr(arcade.key, self.conf["KEYBOARD"]["rotate counter"]): self.rotate_counter,
|
getattr(arcade.key, self.conf["KEYBOARD"]["rotate counter"]): self.rotate_counter,
|
||||||
getattr(arcade.key, self.conf["KEYBOARD"]["hold"]): self.swap,
|
getattr(arcade.key, self.conf["KEYBOARD"]["hold"]): self.swap,
|
||||||
getattr(arcade.key, self.conf["KEYBOARD"]["pause"]): self.pause,
|
getattr(arcade.key, self.conf["KEYBOARD"]["pause"]): self.pause,
|
||||||
getattr(arcade.key, self.conf["KEYBOARD"]["fullscreen"]): self.toggle_fullscreen
|
getattr(arcade.key, self.conf["KEYBOARD"]["fullscreen"]): self.toggle_fullscreen,
|
||||||
},
|
},
|
||||||
tetrislogic.State.PAUSED: {
|
State.PAUSED: {
|
||||||
getattr(arcade.key, self.conf["KEYBOARD"]["pause"]): self.resume,
|
getattr(arcade.key, self.conf["KEYBOARD"]["pause"]): self.resume,
|
||||||
getattr(arcade.key, self.conf["KEYBOARD"]["fullscreen"]): self.toggle_fullscreen
|
getattr(arcade.key, self.conf["KEYBOARD"]["fullscreen"]): self.toggle_fullscreen,
|
||||||
},
|
},
|
||||||
tetrislogic.State.OVER: {
|
State.OVER: {
|
||||||
getattr(arcade.key, self.conf["KEYBOARD"]["start"]): self.new_game,
|
getattr(arcade.key, self.conf["KEYBOARD"]["start"]): self.new_game,
|
||||||
getattr(arcade.key, self.conf["KEYBOARD"]["fullscreen"]): self.toggle_fullscreen
|
getattr(arcade.key, self.conf["KEYBOARD"]["fullscreen"]): self.toggle_fullscreen,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
controls_text = "\n\n\nCONTROLS\n\n" + "\n".join(
|
self.AUTOREPEAT_DELAY = float(self.conf["AUTO-REPEAT"]["delay"])
|
||||||
|
self.AUTOREPEAT_PERIOD = float(self.conf["AUTO-REPEAT"]["period"])
|
||||||
|
|
||||||
|
controls_text = (
|
||||||
|
"\n\n\nCONTROLS\n\n"
|
||||||
|
+ "\n".join(
|
||||||
"{:<16s}{:>6s}".format(key, action)
|
"{:<16s}{:>6s}".format(key, action)
|
||||||
for key, action in tuple(self.conf["KEYBOARD"].items()) + (("QUIT", "ALT+F4"),)
|
for key, action in tuple(self.conf["KEYBOARD"].items()) + (("QUIT", "ALT+F4"),)
|
||||||
) + "\n\n\n"
|
|
||||||
self.start_text = "TETRARCADE" + controls_text + "PRESS [{}] TO START".format(
|
|
||||||
self.conf["KEYBOARD"]["start"]
|
|
||||||
)
|
)
|
||||||
self.pause_text = "PAUSE" + controls_text + "PRESS [{}] TO RESUME".format(
|
+ "\n\n\n"
|
||||||
self.conf["KEYBOARD"]["pause"]
|
|
||||||
)
|
)
|
||||||
|
self.start_text = "TETRARCADE" + controls_text + "PRESS [{}] TO START".format(self.conf["KEYBOARD"]["start"])
|
||||||
|
self.pause_text = "PAUSE" + controls_text + "PRESS [{}] TO RESUME".format(self.conf["KEYBOARD"]["pause"])
|
||||||
self.game_over_text = """GAME
|
self.game_over_text = """GAME
|
||||||
OVER
|
OVER
|
||||||
|
|
||||||
@ -317,7 +326,7 @@ AGAIN""".format(
|
|||||||
arcade.start_render()
|
arcade.start_render()
|
||||||
self.bg.draw()
|
self.bg.draw()
|
||||||
|
|
||||||
if self.state in (tetrislogic.State.PLAYING, tetrislogic.State.OVER):
|
if self.state in (State.PLAYING, State.OVER):
|
||||||
self.matrix_bg.draw()
|
self.matrix_bg.draw()
|
||||||
self.held_bg.draw()
|
self.held_bg.draw()
|
||||||
self.next_bg.draw()
|
self.next_bg.draw()
|
||||||
@ -329,36 +338,25 @@ AGAIN""".format(
|
|||||||
|
|
||||||
t = time.localtime(self.time)
|
t = time.localtime(self.time)
|
||||||
font_size = STATS_TEXT_SIZE * self.scale
|
font_size = STATS_TEXT_SIZE * self.scale
|
||||||
for y, text in enumerate(
|
for y, text in enumerate(("TIME", "LINES", "GOAL", "LEVEL", "HIGH SCORE", "SCORE")):
|
||||||
(
|
|
||||||
"TIME",
|
|
||||||
"LINES",
|
|
||||||
"GOAL",
|
|
||||||
"LEVEL",
|
|
||||||
"HIGH SCORE",
|
|
||||||
"SCORE"
|
|
||||||
)
|
|
||||||
):
|
|
||||||
arcade.draw_text(
|
arcade.draw_text(
|
||||||
text=text,
|
text=text,
|
||||||
start_x=self.matrix_bg.left - self.scale * (STATS_TEXT_MARGIN + STATS_TEXT_WIDTH),
|
start_x=self.matrix_bg.left - self.scale * (STATS_TEXT_MARGIN + STATS_TEXT_WIDTH),
|
||||||
start_y=self.matrix_bg.bottom + 1.5 * (2 * y + 1) * font_size,
|
start_y=self.matrix_bg.bottom + 1.5 * (2 * y + 1) * font_size,
|
||||||
color=TEXT_COLOR,
|
color=TEXT_COLOR,
|
||||||
font_size=font_size,
|
font_size=font_size,
|
||||||
align = 'right',
|
align="right",
|
||||||
font_name=FONT_NAME,
|
font_name=FONT_NAME,
|
||||||
anchor_x = 'left'
|
anchor_x="left",
|
||||||
)
|
)
|
||||||
for y, text in enumerate(
|
for y, text in enumerate(
|
||||||
(
|
(
|
||||||
"{:02d}:{:02d}:{:02d}".format(
|
"{:02d}:{:02d}:{:02d}".format(t.tm_hour - 1, t.tm_min, t.tm_sec),
|
||||||
t.tm_hour-1, t.tm_min, t.tm_sec
|
|
||||||
),
|
|
||||||
"{:n}".format(self.nb_lines_cleared),
|
"{:n}".format(self.nb_lines_cleared),
|
||||||
"{:n}".format(self.goal),
|
"{:n}".format(self.goal),
|
||||||
"{:n}".format(self.level),
|
"{:n}".format(self.level),
|
||||||
"{:n}".format(self.high_score),
|
"{:n}".format(self.high_score),
|
||||||
"{:n}".format(self.score)
|
"{:n}".format(self.score),
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
arcade.draw_text(
|
arcade.draw_text(
|
||||||
@ -367,16 +365,16 @@ AGAIN""".format(
|
|||||||
start_y=self.matrix_bg.bottom + 3 * y * font_size,
|
start_y=self.matrix_bg.bottom + 3 * y * font_size,
|
||||||
color=TEXT_COLOR,
|
color=TEXT_COLOR,
|
||||||
font_size=font_size,
|
font_size=font_size,
|
||||||
align = 'right',
|
align="right",
|
||||||
font_name=FONT_NAME,
|
font_name=FONT_NAME,
|
||||||
anchor_x = 'right'
|
anchor_x="right",
|
||||||
)
|
)
|
||||||
|
|
||||||
highlight_text = {
|
highlight_text = {
|
||||||
tetrislogic.State.STARTING: self.start_text,
|
State.STARTING: self.start_text,
|
||||||
tetrislogic.State.PLAYING: self.highlight_texts[0] if self.highlight_texts else "",
|
State.PLAYING: self.highlight_texts[0] if self.highlight_texts else "",
|
||||||
tetrislogic.State.PAUSED: self.pause_text,
|
State.PAUSED: self.pause_text,
|
||||||
tetrislogic.State.OVER: self.game_over_text
|
State.OVER: self.game_over_text,
|
||||||
}.get(self.state, "")
|
}.get(self.state, "")
|
||||||
if highlight_text:
|
if highlight_text:
|
||||||
arcade.draw_text(
|
arcade.draw_text(
|
||||||
@ -385,10 +383,10 @@ AGAIN""".format(
|
|||||||
start_y=self.matrix_bg.center_y,
|
start_y=self.matrix_bg.center_y,
|
||||||
color=HIGHLIGHT_TEXT_COLOR,
|
color=HIGHLIGHT_TEXT_COLOR,
|
||||||
font_size=HIGHLIGHT_TEXT_SIZE * self.scale,
|
font_size=HIGHLIGHT_TEXT_SIZE * self.scale,
|
||||||
align = 'center',
|
align="center",
|
||||||
font_name=FONT_NAME,
|
font_name=FONT_NAME,
|
||||||
anchor_x = 'center',
|
anchor_x="center",
|
||||||
anchor_y = 'center'
|
anchor_y="center",
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_hide(self):
|
def on_hide(self):
|
||||||
@ -439,14 +437,17 @@ AGAIN""".format(
|
|||||||
try:
|
try:
|
||||||
if not os.path.exists(USER_PROFILE_DIR):
|
if not os.path.exists(USER_PROFILE_DIR):
|
||||||
os.makedirs(USER_PROFILE_DIR)
|
os.makedirs(USER_PROFILE_DIR)
|
||||||
with open(HIGH_SCORE_PATH, mode='wb') as f:
|
with open(HIGH_SCORE_PATH, mode="wb") as f:
|
||||||
crypted_high_score = super().save_high_score()
|
crypted_high_score = super().save_high_score()
|
||||||
f.write(crypted_high_score)
|
f.write(crypted_high_score)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.exit(
|
sys.exit(
|
||||||
"""High score: {:n}
|
"""High score: {:n}
|
||||||
High score could not be saved:
|
High score could not be saved:
|
||||||
""".format(self.high_score) + str(e)
|
""".format(
|
||||||
|
self.high_score
|
||||||
|
)
|
||||||
|
+ str(e)
|
||||||
)
|
)
|
||||||
|
|
||||||
def start(self, task, period):
|
def start(self, task, period):
|
||||||
@ -477,9 +478,14 @@ High score could not be saved:
|
|||||||
self.save_high_score()
|
self.save_high_score()
|
||||||
super().on_close()
|
super().on_close()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
try:
|
||||||
TetrArcade()
|
TetrArcade()
|
||||||
arcade.run()
|
arcade.run()
|
||||||
|
except Exception as e:
|
||||||
|
sys.exit(e)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
1
build-requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
arcade cx-freeze
|
BIN
icon48.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 165 B |
Before Width: | Height: | Size: 151 B |
Before Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 165 B |
Before Width: | Height: | Size: 165 B |
Before Width: | Height: | Size: 165 B |
Before Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 153 KiB After Width: | Height: | Size: 153 KiB |
Before Width: | Height: | Size: 499 B After Width: | Height: | Size: 499 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
BIN
res/minoes.png
Normal file
After Width: | Height: | Size: 389 B |
Before Width: | Height: | Size: 475 B After Width: | Height: | Size: 475 B |
43
setup.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import sys
|
||||||
|
from cx_Freeze import setup, Executable
|
||||||
|
|
||||||
|
if sys.platform == "win32":
|
||||||
|
base = "Win32GUI"
|
||||||
|
icon = "icon.ico"
|
||||||
|
else:
|
||||||
|
base = None
|
||||||
|
icon = None
|
||||||
|
|
||||||
|
excludes = [
|
||||||
|
"tkinter",
|
||||||
|
"PyQt4",
|
||||||
|
"PyQt5",
|
||||||
|
"PySide",
|
||||||
|
"PySide2"
|
||||||
|
]
|
||||||
|
|
||||||
|
executable = Executable(
|
||||||
|
script = "TetrArcade.py",
|
||||||
|
icon = icon,
|
||||||
|
base = base,
|
||||||
|
shortcutName="TetrArcade",
|
||||||
|
shortcutDir="DesktopFolder"
|
||||||
|
)
|
||||||
|
|
||||||
|
options = {
|
||||||
|
"build_exe": {
|
||||||
|
"packages": ["arcade", "pyglet"],
|
||||||
|
"excludes": excludes,
|
||||||
|
"include_files": "res",
|
||||||
|
"silent": True
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setup(
|
||||||
|
name = "TetrArcade",
|
||||||
|
version = "0.1",
|
||||||
|
description = "Tetris clone",
|
||||||
|
author = "AdrienMalin",
|
||||||
|
executables = [executable],
|
||||||
|
options = options,
|
||||||
|
)
|
4
test.py
@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from TetrArcade import TetrArcade, tetrislogic
|
from TetrArcade import TetrArcade, State
|
||||||
|
|
||||||
game = TetrArcade()
|
game = TetrArcade()
|
||||||
game.new_game()
|
game.new_game()
|
||||||
@ -11,5 +11,5 @@ game.rotate_counter()
|
|||||||
for i in range(12):
|
for i in range(12):
|
||||||
game.soft_drop()
|
game.soft_drop()
|
||||||
game.on_draw()
|
game.on_draw()
|
||||||
while game.state != tetrislogic.State.OVER:
|
while game.state != State.OVER:
|
||||||
game.hard_drop()
|
game.hard_drop()
|
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from .consts import NB_LINES, NB_COLS, NB_NEXT
|
from .consts import NB_LINES, NB_COLS, NB_NEXT
|
||||||
from .utils import Movement, Rotation
|
from .utils import Movement, Rotation, Color
|
||||||
from .tetromino import Mino, Tetromino
|
from .tetromino import Mino, Tetromino
|
||||||
from .tetrislogic import TetrisLogic, State, Matrix
|
from .tetrislogic import TetrisLogic, State, Matrix
|
||||||
|
@ -16,8 +16,5 @@ AUTOREPEAT_PERIOD = 0.010 # Official : 0.010
|
|||||||
|
|
||||||
# Piece init coord
|
# Piece init coord
|
||||||
CURRENT_COORD = Coord(4, NB_LINES)
|
CURRENT_COORD = Coord(4, NB_LINES)
|
||||||
NEXT_COORDS = [
|
NEXT_COORDS = [Coord(NB_COLS + 4, NB_LINES - 4 * n - 3) for n in range(NB_NEXT)]
|
||||||
Coord(NB_COLS+4, NB_LINES-4*n-3)
|
|
||||||
for n in range(NB_NEXT)
|
|
||||||
]
|
|
||||||
HELD_COORD = Coord(-5, NB_LINES - 3)
|
HELD_COORD = Coord(-5, NB_LINES - 3)
|
@ -2,13 +2,19 @@
|
|||||||
import random
|
import random
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
from .utils import Coord, Movement, Rotation, T_Spin, Line
|
from .utils import Coord, Movement, Rotation, T_Spin
|
||||||
from .tetromino import Tetromino, T, I
|
from .tetromino import Tetromino, T, I
|
||||||
from .consts import (
|
from .consts import (
|
||||||
NB_LINES, NB_COLS, NB_NEXT,
|
NB_LINES,
|
||||||
LOCK_DELAY, FALL_DELAY,
|
NB_COLS,
|
||||||
AUTOREPEAT_DELAY, AUTOREPEAT_PERIOD,
|
NB_NEXT,
|
||||||
CURRENT_COORD, NEXT_COORDS, HELD_COORD
|
LOCK_DELAY,
|
||||||
|
FALL_DELAY,
|
||||||
|
AUTOREPEAT_DELAY,
|
||||||
|
AUTOREPEAT_PERIOD,
|
||||||
|
CURRENT_COORD,
|
||||||
|
NEXT_COORDS,
|
||||||
|
HELD_COORD,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -25,16 +31,11 @@ class State:
|
|||||||
|
|
||||||
|
|
||||||
class Matrix(list):
|
class Matrix(list):
|
||||||
|
|
||||||
def cell_is_free(self, coord):
|
def cell_is_free(self, coord):
|
||||||
return (
|
return 0 <= coord.x < NB_COLS and 0 <= coord.y and not self[coord.y][coord.x]
|
||||||
0 <= coord.x < NB_COLS
|
|
||||||
and 0 <= coord.y
|
|
||||||
and not self[coord.y][coord.x]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TetrisLogic():
|
class TetrisLogic:
|
||||||
|
|
||||||
NB_LINES = NB_LINES
|
NB_LINES = NB_LINES
|
||||||
NB_COLS = NB_COLS
|
NB_COLS = NB_COLS
|
||||||
@ -101,7 +102,7 @@ class TetrisLogic():
|
|||||||
return self.random_bag.pop()()
|
return self.random_bag.pop()()
|
||||||
|
|
||||||
def append_new_line_to_matrix(self):
|
def append_new_line_to_matrix(self):
|
||||||
self.matrix.append(Line(None for x in range(self.NB_COLS)))
|
self.matrix.append([None for x in range(self.NB_COLS)])
|
||||||
|
|
||||||
def new_level(self):
|
def new_level(self):
|
||||||
self.level += 1
|
self.level += 1
|
||||||
@ -125,10 +126,7 @@ class TetrisLogic():
|
|||||||
for tetromino, coord in zip(self.next, self.NEXT_COORDS):
|
for tetromino, coord in zip(self.next, self.NEXT_COORDS):
|
||||||
tetromino.coord = coord
|
tetromino.coord = coord
|
||||||
|
|
||||||
if not self.can_move(
|
if not self.can_move(self.current.coord, (mino.coord for mino in self.current)):
|
||||||
self.current.coord,
|
|
||||||
(mino.coord for mino in self.current)
|
|
||||||
):
|
|
||||||
self.game_over()
|
self.game_over()
|
||||||
|
|
||||||
def move_left(self):
|
def move_left(self):
|
||||||
@ -147,10 +145,7 @@ class TetrisLogic():
|
|||||||
self.ghost.coord = self.current.coord
|
self.ghost.coord = self.current.coord
|
||||||
for ghost_mino, current_mino in zip(self.ghost, self.current):
|
for ghost_mino, current_mino in zip(self.ghost, self.current):
|
||||||
ghost_mino.coord = current_mino.coord
|
ghost_mino.coord = current_mino.coord
|
||||||
while self.can_move(
|
while self.can_move(self.ghost.coord + Movement.DOWN, (mino.coord for mino in self.ghost)):
|
||||||
self.ghost.coord + Movement.DOWN,
|
|
||||||
(mino.coord for mino in self.ghost)
|
|
||||||
):
|
|
||||||
self.ghost.coord += Movement.DOWN
|
self.ghost.coord += Movement.DOWN
|
||||||
|
|
||||||
def soft_drop(self):
|
def soft_drop(self):
|
||||||
@ -169,10 +164,7 @@ class TetrisLogic():
|
|||||||
|
|
||||||
def move(self, movement, prelock=True):
|
def move(self, movement, prelock=True):
|
||||||
potential_coord = self.current.coord + movement
|
potential_coord = self.current.coord + movement
|
||||||
if self.can_move(
|
if self.can_move(potential_coord, (mino.coord for mino in self.current)):
|
||||||
potential_coord,
|
|
||||||
(mino.coord for mino in self.current)
|
|
||||||
):
|
|
||||||
if self.current.prelocked:
|
if self.current.prelocked:
|
||||||
self.restart(self.lock, self.lock_delay)
|
self.restart(self.lock, self.lock_delay)
|
||||||
self.current.coord = potential_coord
|
self.current.coord = potential_coord
|
||||||
@ -181,23 +173,14 @@ class TetrisLogic():
|
|||||||
self.move_ghost()
|
self.move_ghost()
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
if (
|
if prelock and not self.current.prelocked and movement == Movement.DOWN:
|
||||||
prelock and not self.current.prelocked
|
|
||||||
and movement == Movement.DOWN
|
|
||||||
):
|
|
||||||
self.current.prelocked = True
|
self.current.prelocked = True
|
||||||
self.start(self.lock, self.lock_delay)
|
self.start(self.lock, self.lock_delay)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def rotate(self, rotation):
|
def rotate(self, rotation):
|
||||||
rotated_coords = tuple(
|
rotated_coords = tuple(Coord(rotation * mino.coord.y, -rotation * mino.coord.x) for mino in self.current)
|
||||||
Coord(rotation*mino.coord.y, -rotation*mino.coord.x)
|
for rotation_point, liberty_degree in enumerate(self.current.SRS[rotation][self.current.orientation], start=1):
|
||||||
for mino in self.current
|
|
||||||
)
|
|
||||||
for rotation_point, liberty_degree in enumerate(
|
|
||||||
self.current.SRS[rotation][self.current.orientation],
|
|
||||||
start = 1
|
|
||||||
):
|
|
||||||
potential_coord = self.current.coord + liberty_degree
|
potential_coord = self.current.coord + liberty_degree
|
||||||
if self.can_move(potential_coord, rotated_coords):
|
if self.can_move(potential_coord, rotated_coords):
|
||||||
if self.current.prelocked:
|
if self.current.prelocked:
|
||||||
@ -205,9 +188,7 @@ class TetrisLogic():
|
|||||||
self.current.coord = potential_coord
|
self.current.coord = potential_coord
|
||||||
for mino, coord in zip(self.current, rotated_coords):
|
for mino, coord in zip(self.current, rotated_coords):
|
||||||
mino.coord = coord
|
mino.coord = coord
|
||||||
self.current.orientation = (
|
self.current.orientation = (self.current.orientation + rotation) % 4
|
||||||
(self.current.orientation + rotation) % 4
|
|
||||||
)
|
|
||||||
self.current.last_rotation_point = rotation_point
|
self.current.last_rotation_point = rotation_point
|
||||||
self.move_ghost()
|
self.move_ghost()
|
||||||
return True
|
return True
|
||||||
@ -219,7 +200,7 @@ class TetrisLogic():
|
|||||||
{LINES_CLEAR_NAME: "SINGLE", T_Spin.NONE: 1, T_Spin.MINI: 2, T_Spin.T_SPIN: 8},
|
{LINES_CLEAR_NAME: "SINGLE", T_Spin.NONE: 1, T_Spin.MINI: 2, T_Spin.T_SPIN: 8},
|
||||||
{LINES_CLEAR_NAME: "DOUBLE", T_Spin.NONE: 3, T_Spin.T_SPIN: 12},
|
{LINES_CLEAR_NAME: "DOUBLE", T_Spin.NONE: 3, T_Spin.T_SPIN: 12},
|
||||||
{LINES_CLEAR_NAME: "TRIPLE", T_Spin.NONE: 5, T_Spin.T_SPIN: 16},
|
{LINES_CLEAR_NAME: "TRIPLE", T_Spin.NONE: 5, T_Spin.T_SPIN: 16},
|
||||||
{LINES_CLEAR_NAME: "TETRIS", T_Spin.NONE: 8}
|
{LINES_CLEAR_NAME: "TETRIS", T_Spin.NONE: 8},
|
||||||
)
|
)
|
||||||
|
|
||||||
def lock(self):
|
def lock(self):
|
||||||
@ -227,17 +208,11 @@ class TetrisLogic():
|
|||||||
self.stop(self.lock)
|
self.stop(self.lock)
|
||||||
|
|
||||||
# Piece unlocked
|
# Piece unlocked
|
||||||
if self.can_move(
|
if self.can_move(self.current.coord + Movement.DOWN, (mino.coord for mino in self.current)):
|
||||||
self.current.coord + Movement.DOWN,
|
|
||||||
(mino.coord for mino in self.current)
|
|
||||||
):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Game over
|
# Game over
|
||||||
if all(
|
if all((mino.coord + self.current.coord).y >= self.NB_LINES for mino in self.current):
|
||||||
(mino.coord + self.current.coord).y >= self.NB_LINES
|
|
||||||
for mino in self.current
|
|
||||||
):
|
|
||||||
self.game_over()
|
self.game_over()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -246,17 +221,12 @@ class TetrisLogic():
|
|||||||
self.restart(self.repeat_action, self.AUTOREPEAT_DELAY)
|
self.restart(self.repeat_action, self.AUTOREPEAT_DELAY)
|
||||||
|
|
||||||
# T-Spin
|
# T-Spin
|
||||||
if (
|
if type(self.current) == T and self.current.last_rotation_point is not None:
|
||||||
type(self.current) == T
|
|
||||||
and self.current.last_rotation_point is not None
|
|
||||||
):
|
|
||||||
a = self.is_t_slot(0)
|
a = self.is_t_slot(0)
|
||||||
b = self.is_t_slot(1)
|
b = self.is_t_slot(1)
|
||||||
c = self.is_t_slot(3)
|
c = self.is_t_slot(3)
|
||||||
d = self.is_t_slot(2)
|
d = self.is_t_slot(2)
|
||||||
if self.current.last_rotation_point == 5 or (
|
if self.current.last_rotation_point == 5 or (a and b and (c or d)):
|
||||||
a and b and (c or d)
|
|
||||||
):
|
|
||||||
t_spin = T_Spin.T_SPIN
|
t_spin = T_Spin.T_SPIN
|
||||||
elif c and d and (a or b):
|
elif c and d and (a or b):
|
||||||
t_spin = T_Spin.MINI
|
t_spin = T_Spin.MINI
|
||||||
@ -267,7 +237,7 @@ class TetrisLogic():
|
|||||||
|
|
||||||
for mino in self.current:
|
for mino in self.current:
|
||||||
coord = mino.coord + self.current.coord
|
coord = mino.coord + self.current.coord
|
||||||
del(mino.coord)
|
del mino.coord
|
||||||
if coord.y <= self.NB_LINES + 3:
|
if coord.y <= self.NB_LINES + 3:
|
||||||
self.matrix[coord.y][coord.x] = mino
|
self.matrix[coord.y][coord.x] = mino
|
||||||
|
|
||||||
@ -314,22 +284,12 @@ class TetrisLogic():
|
|||||||
self.new_current()
|
self.new_current()
|
||||||
|
|
||||||
def can_move(self, potential_coord, minoes_coords):
|
def can_move(self, potential_coord, minoes_coords):
|
||||||
return all(
|
return all(self.matrix.cell_is_free(potential_coord + mino_coord) for mino_coord in minoes_coords)
|
||||||
self.matrix.cell_is_free(potential_coord+mino_coord)
|
|
||||||
for mino_coord in minoes_coords
|
|
||||||
)
|
|
||||||
|
|
||||||
T_SLOT_COORDS = (
|
T_SLOT_COORDS = (Coord(-1, 1), Coord(1, 1), Coord(-1, 1), Coord(-1, -1))
|
||||||
Coord(-1, 1),
|
|
||||||
Coord( 1, 1),
|
|
||||||
Coord(-1, 1),
|
|
||||||
Coord(-1, -1)
|
|
||||||
)
|
|
||||||
|
|
||||||
def is_t_slot(self, n):
|
def is_t_slot(self, n):
|
||||||
t_slot_coord = self.current.coord + self.T_SLOT_COORDS[
|
t_slot_coord = self.current.coord + self.T_SLOT_COORDS[(self.current.orientation + n) % 4]
|
||||||
(self.current.orientation + n) % 4
|
|
||||||
]
|
|
||||||
return not self.matrix.cell_is_free(t_slot_coord)
|
return not self.matrix.cell_is_free(t_slot_coord)
|
||||||
|
|
||||||
def swap(self):
|
def swap(self):
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from .utils import Coord, Rotation
|
from .utils import Coord, Rotation, Color
|
||||||
|
|
||||||
|
|
||||||
class Mino:
|
class Mino:
|
||||||
|
|
||||||
def __init__(self, color, coord):
|
def __init__(self, color, coord):
|
||||||
self.color = color
|
self.color = color
|
||||||
self.coord = coord
|
self.coord = coord
|
||||||
|
|
||||||
|
|
||||||
class MetaTetromino(type):
|
class MetaTetromino(type):
|
||||||
|
|
||||||
def __init__(cls, name, bases, dct):
|
def __init__(cls, name, bases, dct):
|
||||||
super().__init__(name, bases, dct)
|
super().__init__(name, bases, dct)
|
||||||
Tetromino.shapes.append(cls)
|
Tetromino.shapes.append(cls)
|
||||||
@ -35,10 +34,7 @@ class Tetromino(list):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(
|
super().__init__(Mino(self.MINOES_COLOR, coord) for coord in self.MINOES_COORDS)
|
||||||
Mino(self.MINOES_COLOR, coord)
|
|
||||||
for coord in self.MINOES_COORDS
|
|
||||||
)
|
|
||||||
self.orientation = 0
|
self.orientation = 0
|
||||||
self.last_rotation_point = None
|
self.last_rotation_point = None
|
||||||
self.hold_enabled = True
|
self.hold_enabled = True
|
||||||
@ -47,6 +43,7 @@ class Tetromino(list):
|
|||||||
def ghost(self):
|
def ghost(self):
|
||||||
return type(self)()
|
return type(self)()
|
||||||
|
|
||||||
|
|
||||||
class O(Tetromino, metaclass=MetaTetromino):
|
class O(Tetromino, metaclass=MetaTetromino):
|
||||||
|
|
||||||
SRS = {
|
SRS = {
|
||||||
@ -54,7 +51,7 @@ class O(Tetromino, metaclass=MetaTetromino):
|
|||||||
Rotation.COUNTER: (tuple(), tuple(), tuple(), tuple()),
|
Rotation.COUNTER: (tuple(), tuple(), tuple(), tuple()),
|
||||||
}
|
}
|
||||||
MINOES_COORDS = (Coord(0, 0), Coord(1, 0), Coord(0, 1), Coord(1, 1))
|
MINOES_COORDS = (Coord(0, 0), Coord(1, 0), Coord(0, 1), Coord(1, 1))
|
||||||
MINOES_COLOR = "yellow"
|
MINOES_COLOR = Color.YELLOW
|
||||||
|
|
||||||
def rotate(self, direction):
|
def rotate(self, direction):
|
||||||
return False
|
return False
|
||||||
@ -77,34 +74,34 @@ class I(Tetromino, metaclass=MetaTetromino):
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(1, 0), Coord(2, 0))
|
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(1, 0), Coord(2, 0))
|
||||||
MINOES_COLOR = "cyan"
|
MINOES_COLOR = Color.CYAN
|
||||||
|
|
||||||
|
|
||||||
class T(Tetromino, metaclass=MetaTetromino):
|
class T(Tetromino, metaclass=MetaTetromino):
|
||||||
|
|
||||||
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(0, 1), Coord(1, 0))
|
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(0, 1), Coord(1, 0))
|
||||||
MINOES_COLOR = "magenta"
|
MINOES_COLOR = Color.MAGENTA
|
||||||
|
|
||||||
|
|
||||||
class L(Tetromino, metaclass=MetaTetromino):
|
class L(Tetromino, metaclass=MetaTetromino):
|
||||||
|
|
||||||
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(1, 0), Coord(1, 1))
|
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(1, 0), Coord(1, 1))
|
||||||
MINOES_COLOR = "orange"
|
MINOES_COLOR = Color.ORANGE
|
||||||
|
|
||||||
|
|
||||||
class J(Tetromino, metaclass=MetaTetromino):
|
class J(Tetromino, metaclass=MetaTetromino):
|
||||||
|
|
||||||
MINOES_COORDS = (Coord(-1, 1), Coord(-1, 0), Coord(0, 0), Coord(1, 0))
|
MINOES_COORDS = (Coord(-1, 1), Coord(-1, 0), Coord(0, 0), Coord(1, 0))
|
||||||
MINOES_COLOR = "blue"
|
MINOES_COLOR = Color.BLUE
|
||||||
|
|
||||||
|
|
||||||
class S(Tetromino, metaclass=MetaTetromino):
|
class S(Tetromino, metaclass=MetaTetromino):
|
||||||
|
|
||||||
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(0, 1), Coord(1, 1))
|
MINOES_COORDS = (Coord(-1, 0), Coord(0, 0), Coord(0, 1), Coord(1, 1))
|
||||||
MINOES_COLOR = "green"
|
MINOES_COLOR = Color.GREEN
|
||||||
|
|
||||||
|
|
||||||
class Z(Tetromino, metaclass=MetaTetromino):
|
class Z(Tetromino, metaclass=MetaTetromino):
|
||||||
|
|
||||||
MINOES_COORDS = (Coord(-1, 1), Coord(0, 1), Coord(0, 0), Coord(1, 0))
|
MINOES_COORDS = (Coord(-1, 1), Coord(0, 1), Coord(0, 0), Coord(1, 0))
|
||||||
MINOES_COLOR = "red"
|
MINOES_COLOR = Color.RED
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
class Coord:
|
class Coord:
|
||||||
|
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
@ -29,6 +28,12 @@ class T_Spin:
|
|||||||
T_SPIN = "T-SPIN"
|
T_SPIN = "T-SPIN"
|
||||||
|
|
||||||
|
|
||||||
class Line(list):
|
class Color:
|
||||||
pass
|
|
||||||
|
|
||||||
|
BLUE = 0
|
||||||
|
CYAN = 1
|
||||||
|
GREEN = 2
|
||||||
|
MAGENTA = 3
|
||||||
|
ORANGE = 4
|
||||||
|
RED = 5
|
||||||
|
YELLOW = 6
|
||||||
|