fix typo in method name

This commit is contained in:
adrienmalin 2019-09-28 15:06:24 +02:00
parent 78613ef615
commit d89a29cce9
2 changed files with 26 additions and 22 deletions

View File

@ -13,7 +13,7 @@ python -m pip install --user arcade
"""
)
from tetrislogic import TetrisLogic, Status, AbstractScheduler
from tetrislogic import TetrisLogic, State, AbstractScheduler
# Constants
@ -129,10 +129,10 @@ class TetrArcade(TetrisLogic, arcade.Window):
locale.setlocale(locale.LC_ALL, '')
self.KEY_MAP = {
Status.STARTING: {
State.STARTING: {
arcade.key.ENTER: self.new_game
},
Status.PLAYING: {
State.PLAYING: {
arcade.key.LEFT: self.move_left,
arcade.key.NUM_4: self.move_left,
arcade.key.RIGHT: self.move_right,
@ -155,11 +155,11 @@ class TetrArcade(TetrisLogic, arcade.Window):
arcade.key.ESCAPE: self.pause,
arcade.key.F1: self.pause,
},
Status.PAUSED: {
State.PAUSED: {
arcade.key.ESCAPE: self.resume,
arcade.key.F1: self.resume
},
Status.OVER: {
State.OVER: {
arcade.key.ENTER: self.new_game
}
}
@ -216,7 +216,7 @@ class TetrArcade(TetrisLogic, arcade.Window):
def on_key_press(self, key, modifiers):
for key_or_modifier in (key, modifiers):
try:
action = self.KEY_MAP[self.status][key_or_modifier]
action = self.KEY_MAP[self.state][key_or_modifier]
except KeyError:
pass
else:
@ -224,7 +224,7 @@ class TetrArcade(TetrisLogic, arcade.Window):
def on_key_release(self, key, modifiers):
try:
action = self.KEY_MAP[self.status][key]
action = self.KEY_MAP[self.state][key]
except KeyError:
pass
else:
@ -291,7 +291,7 @@ class TetrArcade(TetrisLogic, arcade.Window):
arcade.start_render()
self.bg_sprite.draw()
if self.status in (Status.PLAYING, Status.OVER):
if self.state in (State.PLAYING, State.OVER):
self.matrix_sprite.draw()
self.matrix_minoes_sprites.draw()
@ -300,7 +300,11 @@ class TetrArcade(TetrisLogic, arcade.Window):
self.update_piece(self.current_piece, self.current_piece_sprites)
if self.current_piece.prelocked:
alpha = PRELOCKED_ALPHA if self.current_piece.prelocked else NORMAL_ALPHA
alpha = (
PRELOCKED_ALPHA
if self.current_piece.prelocked
else NORMAL_ALPHA
)
for mino_sprite in self.current_piece_sprites:
mino_sprite.alpha = alpha
self.current_piece_sprites.draw()
@ -350,11 +354,11 @@ class TetrArcade(TetrisLogic, arcade.Window):
)
highlight_text = {
Status.STARTING: START_TEXT,
Status.PLAYING: self.highlight_texts[0] if self.highlight_texts else "",
Status.PAUSED: PAUSE_TEXT,
Status.OVER: GAME_OVER_TEXT
}.get(self.status, "")
State.STARTING: START_TEXT,
State.PLAYING: self.highlight_texts[0] if self.highlight_texts else "",
State.PAUSED: PAUSE_TEXT,
State.OVER: GAME_OVER_TEXT
}.get(self.state, "")
if highlight_text:
arcade.draw_text(
text = highlight_text,

View File

@ -34,7 +34,7 @@ HELD_PIECE_POSITION = Coord(-7, NB_LINES-3)
HELD_I_POSITION = Coord(-7, NB_LINES-3)
class Status:
class State:
STARTING = "starting"
PLAYING = "playing"
@ -70,7 +70,7 @@ class AbstractScheduler:
def stop(self, task):
raise NotImplementedError
def restrart(self, task, period):
def restart(self, task, period):
self.stop(task)
self.start(task, period)
@ -197,7 +197,7 @@ class TetrisLogic():
def __init__(self):
self.high_score = 0
self.status = Status.STARTING
self.state = State.STARTING
self.matrix = []
self.next_pieces = []
self.current_piece = None
@ -226,7 +226,7 @@ class TetrisLogic():
self.next_pieces = [Tetromino() for i in range(NB_NEXT_PIECES)]
self.current_piece = None
self.held_piece = None
self.status = Status.PLAYING
self.state = State.PLAYING
self.scheduler.start(self.update_time, 1)
self.new_level()
@ -237,7 +237,7 @@ class TetrisLogic():
self.fall_delay = pow(0.8 - ((self.level-1)*0.007), self.level-1)
if self.level > 15:
self.lock_delay = 0.5 * pow(0.9, self.level-15)
self.show_text("Level\n{:n}".format(self.level))
self.show_text("LEVEL\n{:n}".format(self.level))
self.scheduler.start(self.drop, self.fall_delay)
self.new_current_piece()
@ -457,7 +457,7 @@ class TetrisLogic():
self.new_current_piece()
def pause(self):
self.status = Status.PAUSED
self.state = State.PAUSED
self.scheduler.stop(self.drop)
self.scheduler.stop(self.lock)
self.scheduler.stop(self.update_time)
@ -465,14 +465,14 @@ class TetrisLogic():
self.stop_autorepeat()
def resume(self):
self.status = Status.PLAYING
self.state = State.PLAYING
self.scheduler.start(self.drop, self.fall_delay)
if self.current_piece.prelocked:
self.scheduler.start(self.lock, self.lock_delay)
self.scheduler.start(self.update_time, 1)
def game_over(self):
self.status = Status.OVER
self.state = State.OVER
self.scheduler.stop(self.drop)
self.scheduler.stop(self.update_time)
self.scheduler.stop(self.repeat_action)