-
Notifications
You must be signed in to change notification settings - Fork 1
/
17.10_exercises.py
46 lines (33 loc) · 1.05 KB
/
17.10_exercises.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pygame
import random
rng = random.Random()
class Cards:
def __init__(self, image, display_position):
self.img = image
self.posn = display_position
def update(self):
self.posn.x += 40
def draw(self, target_surface, card_num):
print(self, target_surface, card_num)
if card_num / 2 >= 2:
patch_rect = (card_num * 50, -50, 50, 50)
target_surface.blit(self.image, self.posn, patch_rect)
return
def display_cards():
pygame.init()
surface_sz = 500
surface = pygame.display.set_mode((surface_sz, surface_sz))
cards = pygame.image.load("playcards.png")
card_nums = list(range(1, 53))
rng.shuffle(card_nums)
card_nums = card_nums[:5]
Cards.__init__(cards, (100, 100))
while True:
# Look for an event from keyboard, mouse, etc.
ev = pygame.event.poll()
if ev.type == pygame.QUIT:
break
if ev.type == pygame.MOUSEBUTTONDOWN:
for i in card_nums:
Cards.draw(surface, i)
display_cards()