Pārlūkot izejas kodu

tetris static piece colors by default

Thomas Buck 1 gadu atpakaļ
vecāks
revīzija
5f328c5107
1 mainītis faili ar 9 papildinājumiem un 3 dzēšanām
  1. 9
    3
      tetris.py

+ 9
- 3
tetris.py Parādīt failu

@@ -13,13 +13,14 @@ import random
13 13
 import util
14 14
 
15 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 17
         self.gui = g
18 18
         self.input = i
19 19
         self.timestep = ts
20 20
         self.timeout = to
21 21
         self.width = min(w, self.gui.width)
22 22
         self.height = min(h, self.gui.height)
23
+        self.randomizeColors = rc
23 24
 
24 25
         self.endText = ScrollText(self.gui, "Game Over!", "uushi",
25 26
                                    1, 50, (251, 72, 196))
@@ -251,9 +252,14 @@ class Tetris:
251 252
     def step(self):
252 253
         if self.next_piece == None:
253 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 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 263
                 0, # x
258 264
                 0, # y
259 265
             ]

Notiek ielāde…
Atcelt
Saglabāt