aboutsummaryrefslogtreecommitdiff
path: root/turtetris_master/screen_checker.py
diff options
context:
space:
mode:
authorKarel Kočí <karel.koci@nic.cz>2017-07-19 11:06:04 +0200
committerKarel Kočí <karel.koci@nic.cz>2017-07-19 14:31:18 +0200
commitb934596cfd5415ce83b5a7b42120e0f0e229937a (patch)
treeeba32535681447d1eedad0e8f1f40f299f86f027 /turtetris_master/screen_checker.py
parentdd8bcc2da80d15280b9aa94cec648fbdac576cc3 (diff)
downloadturris-tetris-b934596cfd5415ce83b5a7b42120e0f0e229937a.tar.gz
turris-tetris-b934596cfd5415ce83b5a7b42120e0f0e229937a.tar.bz2
turris-tetris-b934596cfd5415ce83b5a7b42120e0f0e229937a.zip
Add screen checker
Diffstat (limited to 'turtetris_master/screen_checker.py')
-rw-r--r--turtetris_master/screen_checker.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/turtetris_master/screen_checker.py b/turtetris_master/screen_checker.py
new file mode 100644
index 0000000..d8ed327
--- /dev/null
+++ b/turtetris_master/screen_checker.py
@@ -0,0 +1,33 @@
+class ScreenChecker:
+ "Simple screen checker showing lines and updates"
+
+ def __init__(self, matrix):
+ "Initialize it for given matrix"
+ if matrix.height >= matrix.width:
+ raise Exception('ScreenChecker doesn\'t support wide matrix.')
+ self.matrix = matrix
+ self.__tick__ = 0
+ self.__pos__ = [[0, 0] for _ in range(matrix.height)]
+ for i in range(0, matrix.height):
+ self.__pos__[i][1] = i
+ for y in range(0, i):
+ matrix.pixel(i, y, 'green')
+
+ def __pos_inc__(self, p):
+ p += 1
+ if p >= self.matrix.width:
+ p = 0
+ return p
+
+ def tick(self):
+ self.__tick__ += 1
+ if self.__tick__ > 60:
+ self.__tick__ = 0
+ for i in range(0, self.matrix.height):
+ self.matrix.pixel(self.__pos__[i][0], i, '000000')
+ self.__pos__[i][0] = self.__pos_inc__(self.__pos__[i][0])
+ self.__pos__[i][1] = self.__pos_inc__(self.__pos__[i][1])
+ self.matrix.pixel(self.__pos__[i][1], i, color='green')
+ return True
+ else:
+ return False