From 580130d99c798c9fb0034f4daba96f8357927f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Thu, 20 Jul 2017 14:17:28 +0200 Subject: Add score --- turtetris_master/game.py | 10 +++++++--- turtetris_master/state_machine.py | 8 ++++++++ turtetris_master/usb_input.py | 3 +-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/turtetris_master/game.py b/turtetris_master/game.py index 63987b0..3a5d463 100644 --- a/turtetris_master/game.py +++ b/turtetris_master/game.py @@ -120,7 +120,12 @@ class Game: def __show_score__(self): "Show score in bottom right" - pass + i = self.score % 5 + y = int(self.score / 5) + for ii in range(i): + self.matrix.pixel(self.matrix.width - 1, ii, 'green') + for yy in range(y): + self.matrix.pixel(self.matrix.width - 2, yy, 'green') def __place__(self): "Stone can't move so place it, check lines and generate new one" @@ -202,8 +207,7 @@ class Game: self.__rotate__() if input['left'] != input['right']: self.__move__(input['left']) - if self.step >= self.step_edge or \ - (input['down'] and self.step >= self.step_edge/3): + if self.step >= self.step_edge or input['down']: gameover = not self.__down__() self.step = 0 else: diff --git a/turtetris_master/state_machine.py b/turtetris_master/state_machine.py index 3c07acb..7cbfcaa 100644 --- a/turtetris_master/state_machine.py +++ b/turtetris_master/state_machine.py @@ -36,6 +36,14 @@ class StateMachine: if self.state != "game": __exception__() self.matrix.fill('red') + i = self.matrix.height - 2 + # Show score + for _ in range(int(self.game.score / 5)): + for s in range(5): + self.matrix.pixel(s + 3, i, 'green') + i -= 1 + for s in range(self.game.score % 5): + self.matrix.pixel(s + 3, i, 'green') self.matrix.display() else: __exception__() diff --git a/turtetris_master/usb_input.py b/turtetris_master/usb_input.py index 856c653..dc01489 100644 --- a/turtetris_master/usb_input.py +++ b/turtetris_master/usb_input.py @@ -63,7 +63,6 @@ class Gamepad: changed = {} for key in ['left', 'right', 'up', 'down', 'select', 'start']: changed[key] = new_state[key] and not self.state[key] - if key == 'down': - changed[key] = new_state[key] + # TODO repeat self.state = new_state return changed -- cgit v1.2.3