Browse Source

tetris static piece colors by default

Thomas Buck 1 year ago
parent
commit
5f328c5107
1 changed files with 9 additions and 3 deletions
  1. 9
    3
      tetris.py

+ 9
- 3
tetris.py View File

13
 import util
13
 import util
14
 
14
 
15
 class Tetris:
15
 class Tetris:
16
-    def __init__(self, g, i, ts = 0.5, to = 60.0, w = 10, h = 22):
16
+    def __init__(self, g, i, ts = 0.5, to = 60.0, w = 10, h = 22, rc = False):
17
         self.gui = g
17
         self.gui = g
18
         self.input = i
18
         self.input = i
19
         self.timestep = ts
19
         self.timestep = ts
20
         self.timeout = to
20
         self.timeout = to
21
         self.width = min(w, self.gui.width)
21
         self.width = min(w, self.gui.width)
22
         self.height = min(h, self.gui.height)
22
         self.height = min(h, self.gui.height)
23
+        self.randomizeColors = rc
23
 
24
 
24
         self.endText = ScrollText(self.gui, "Game Over!", "uushi",
25
         self.endText = ScrollText(self.gui, "Game Over!", "uushi",
25
                                    1, 50, (251, 72, 196))
26
                                    1, 50, (251, 72, 196))
251
     def step(self):
252
     def step(self):
252
         if self.next_piece == None:
253
         if self.next_piece == None:
253
             # select a new piece type and color
254
             # select a new piece type and color
255
+            p_i = random.randrange(0, len(self.pieces))
256
+            if self.randomizeColors:
257
+                c_i = random.randrange(0, len(self.colors))
258
+            else:
259
+                c_i = p_i % len(self.colors)
254
             self.next_piece = [
260
             self.next_piece = [
255
-                self.pieces[random.randrange(0, len(self.pieces))], # piece
256
-                self.colors[random.randrange(0, len(self.colors))], # color
261
+                self.pieces[p_i], # piece
262
+                self.colors[c_i], # color
257
                 0, # x
263
                 0, # x
258
                 0, # y
264
                 0, # y
259
             ]
265
             ]

Loading…
Cancel
Save