Skip to content

Commit 3d1efde

Browse files
committed
Fix code style issues with Black
1 parent 7d02863 commit 3d1efde

2 files changed

Lines changed: 60 additions & 18 deletions

File tree

games/chapter4/practice/flappy_bird/OOPflappybird.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ def __init__(self):
6464
self.rect = pygame.Rect
6565

6666
def draw(
67-
self, screen: pygame.Surface, color: tuple, specific_rect: pygame.Rect = None
67+
self,
68+
screen: pygame.Surface,
69+
color: tuple,
70+
specific_rect: pygame.Rect = None,
6871
):
6972
"""
7073
Draws a rectangle onto the screen in the specified color.
@@ -232,8 +235,12 @@ def process_spritesheet(
232235
@param offset_y: int - the y offset before the sprite columns start
233236
"""
234237
self.sprites = []
235-
self.sprite_frame_width = (spritesheet.get_width() - offset_x) // num_pics_x
236-
self.sprite_frame_height = (spritesheet.get_height() - offset_y) // num_pics_y
238+
self.sprite_frame_width = (
239+
spritesheet.get_width() - offset_x
240+
) // num_pics_x
241+
self.sprite_frame_height = (
242+
spritesheet.get_height() - offset_y
243+
) // num_pics_y
237244
for row in range(num_pics_x):
238245
for column in range(num_pics_y):
239246
temp = spritesheet.subsurface(
@@ -258,7 +265,9 @@ def draw(self, screen: pygame.Surface, framecount: int):
258265
# so that it won't be bigger or smaller than the new sprite
259266
self.cur_sprite_idx = curr_sprite_idx
260267
temp = self.sprites[self.cur_sprite_idx]
261-
self.rect = temp.get_rect().move(self.rect.topleft[0], self.rect.topleft[1])
268+
self.rect = temp.get_rect().move(
269+
self.rect.topleft[0], self.rect.topleft[1]
270+
)
262271
super().draw(screen, BLACK)
263272

264273
def blit(self, screen: pygame.Surface):
@@ -335,8 +344,12 @@ def __init__(self):
335344

336345
def create_buttons(self, button1text="Start Game", button2bg=RED):
337346
self.buttons = {
338-
"start": Button(width // 2, height // 4, LGREEN, LILAC, button1text),
339-
"quit": Button(width // 2, height // 4 * 3, button2bg, LILAC, "Quit Game"),
347+
"start": Button(
348+
width // 2, height // 4, LGREEN, LILAC, button1text
349+
),
350+
"quit": Button(
351+
width // 2, height // 4 * 3, button2bg, LILAC, "Quit Game"
352+
),
340353
}
341354

342355
def mainloop(self):
@@ -411,10 +424,15 @@ def create_tubes(self):
411424
"""
412425
Creates tubes and puts a coin in the middle of each tube.
413426
"""
414-
if len(self.tubes) == 0 or self.tubes[-1].bottom_tube.right < width - 200:
427+
if (
428+
len(self.tubes) == 0
429+
or self.tubes[-1].bottom_tube.right < width - 200
430+
):
415431
bottom_tube_height = random.randint(0, height - Tubes.TUBEGAP)
416432
self.tubes.append(Tubes(bottom_tube_height))
417-
self.coins.append(Coin(height - bottom_tube_height - (Tubes.TUBEGAP // 2)))
433+
self.coins.append(
434+
Coin(height - bottom_tube_height - (Tubes.TUBEGAP // 2))
435+
)
418436

419437
def draw_all(self):
420438
# draw bird and coin rectangles before background so that they won't

games/chapter4/solutions/flappy_bird/OOPflappybird.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ def __init__(self):
5151
self.rect = pygame.Rect
5252

5353
def draw(
54-
self, screen: pygame.Surface, color: tuple, specific_rect: pygame.Rect = None
54+
self,
55+
screen: pygame.Surface,
56+
color: tuple,
57+
specific_rect: pygame.Rect = None,
5558
):
5659
"""
5760
Draws a rectangle onto the screen in the specified color.
@@ -121,10 +124,16 @@ def __init__(self, bottom_tube_height: int):
121124
and TUBEWIDTH variables as dimensions.
122125
"""
123126
self.bottom_tube = pygame.Rect(
124-
width, height - bottom_tube_height, self.TUBEWIDTH, bottom_tube_height
127+
width,
128+
height - bottom_tube_height,
129+
self.TUBEWIDTH,
130+
bottom_tube_height,
125131
)
126132
self.top_tube = pygame.Rect(
127-
width, 0, self.TUBEWIDTH, height - bottom_tube_height - self.TUBEGAP
133+
width,
134+
0,
135+
self.TUBEWIDTH,
136+
height - bottom_tube_height - self.TUBEGAP,
128137
)
129138

130139
def draw(self, screen: pygame.Surface):
@@ -229,8 +238,12 @@ def process_spritesheet(
229238
@param offset_y: int - the y offset before the sprite columns start
230239
"""
231240
self.sprites = []
232-
self.sprite_frame_width = (spritesheet.get_width() - offset_x) // num_pics_x
233-
self.sprite_frame_height = (spritesheet.get_height() - offset_y) // num_pics_y
241+
self.sprite_frame_width = (
242+
spritesheet.get_width() - offset_x
243+
) // num_pics_x
244+
self.sprite_frame_height = (
245+
spritesheet.get_height() - offset_y
246+
) // num_pics_y
234247
for row in range(num_pics_x):
235248
for column in range(num_pics_y):
236249
temp = spritesheet.subsurface(
@@ -255,7 +268,9 @@ def draw(self, screen: pygame.Surface, framecount: int):
255268
# so that it won't be bigger or smaller than the new sprite
256269
self.cur_sprite_idx = curr_sprite_idx
257270
temp = self.sprites[self.cur_sprite_idx]
258-
self.rect = temp.get_rect().move(self.rect.topleft[0], self.rect.topleft[1])
271+
self.rect = temp.get_rect().move(
272+
self.rect.topleft[0], self.rect.topleft[1]
273+
)
259274
super().draw(screen, BLACK)
260275

261276
def blit(self, screen: pygame.Surface):
@@ -332,8 +347,12 @@ def __init__(self):
332347

333348
def create_buttons(self, button1text="Start Game", button2bg=RED):
334349
self.buttons = {
335-
"start": Button(width // 2, height // 4, LGREEN, LILAC, button1text),
336-
"quit": Button(width // 2, height // 4 * 3, button2bg, LILAC, "Quit Game"),
350+
"start": Button(
351+
width // 2, height // 4, LGREEN, LILAC, button1text
352+
),
353+
"quit": Button(
354+
width // 2, height // 4 * 3, button2bg, LILAC, "Quit Game"
355+
),
337356
}
338357

339358
def mainloop(self):
@@ -411,10 +430,15 @@ def create_tubes(self):
411430
"""
412431
Creates tubes and puts a coin in the middle of each tube.
413432
"""
414-
if len(self.tubes) == 0 or self.tubes[-1].bottom_tube.right < width - 200:
433+
if (
434+
len(self.tubes) == 0
435+
or self.tubes[-1].bottom_tube.right < width - 200
436+
):
415437
bottom_tube_height = random.randint(0, height - Tubes.TUBEGAP)
416438
self.tubes.append(Tubes(bottom_tube_height))
417-
self.coins.append(Coin(height - bottom_tube_height - (Tubes.TUBEGAP // 2)))
439+
self.coins.append(
440+
Coin(height - bottom_tube_height - (Tubes.TUBEGAP // 2))
441+
)
418442

419443
def draw_all(self):
420444
# draw bird and coin rectangles before background so that they won't

0 commit comments

Comments
 (0)