Removed test.py, it should have been gone already.
This commit is contained in:
parent
42d07e95ed
commit
66b837cecd
2 changed files with 51 additions and 65 deletions
51
card.py
51
card.py
|
@ -0,0 +1,51 @@
|
||||||
|
import pygame
|
||||||
|
from image_sprite import ImageSprite
|
||||||
|
|
||||||
|
|
||||||
|
class Card(ImageSprite):
|
||||||
|
def __init__(self, image_path, screen_width, screen_height):
|
||||||
|
"""
|
||||||
|
Initializes Card object.
|
||||||
|
:param image_path: Path to image
|
||||||
|
:param screen_width: Width of screen
|
||||||
|
:param screen_height: Height of screen
|
||||||
|
"""
|
||||||
|
super().__init__(image_path, screen_width, screen_height)
|
||||||
|
|
||||||
|
self.size = 150 # image height and width (in pixels)
|
||||||
|
self.card_back = pygame.transform.scale(pygame.image.load('images/turtle.jpg'), (self.size, self.size))
|
||||||
|
self.card_front = pygame.transform.scale(pygame.image.load(image_path), (self.size, self.size))
|
||||||
|
super().image = self.card_back
|
||||||
|
|
||||||
|
self.temp_count = 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def image(self):
|
||||||
|
return super().image
|
||||||
|
|
||||||
|
@image.setter
|
||||||
|
def image(self, image):
|
||||||
|
super().image = image
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rect(self):
|
||||||
|
return super().rect
|
||||||
|
|
||||||
|
@rect.setter
|
||||||
|
def rect(self, rect):
|
||||||
|
super().rect = rect
|
||||||
|
|
||||||
|
def on_click(self):
|
||||||
|
"""
|
||||||
|
Is meant to be called when the card is clicked, but that must be implemented by the class which has-a Card. \
|
||||||
|
Currently prints the number of times the card has been clicked.
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self.temp_count += 1
|
||||||
|
print(self.temp_count)
|
||||||
|
|
||||||
|
def flip_card(self):
|
||||||
|
if self.image == self.card_back:
|
||||||
|
self.image = self.card_front
|
||||||
|
else:
|
||||||
|
self.image = self.card_back
|
65
test.py
65
test.py
|
@ -1,65 +0,0 @@
|
||||||
# import the pygame module
|
|
||||||
import pygame
|
|
||||||
|
|
||||||
# import pygame.locals for easier
|
|
||||||
# access to key coordinates
|
|
||||||
from pygame.locals import *
|
|
||||||
|
|
||||||
|
|
||||||
# Define our square object and call super to
|
|
||||||
# give it all the properties and methods of pygame.sprite.Sprite
|
|
||||||
# Define the class for our square objects
|
|
||||||
class Square(pygame.sprite.Sprite):
|
|
||||||
def __init__(self):
|
|
||||||
super(Square, self).__init__()
|
|
||||||
|
|
||||||
# Define the dimension of the surface
|
|
||||||
# Here we are making squares of side 25px
|
|
||||||
self.surf = pygame.Surface((25, 25))
|
|
||||||
|
|
||||||
# Define the color of the surface using RGB color coding.
|
|
||||||
self.surf.fill((0, 200, 255))
|
|
||||||
self.rect = self.surf.get_rect()
|
|
||||||
|
|
||||||
|
|
||||||
# initialize pygame
|
|
||||||
pygame.init()
|
|
||||||
|
|
||||||
# Define the dimensions of screen object
|
|
||||||
screen = pygame.display.set_mode((800, 600))
|
|
||||||
|
|
||||||
# instantiate all square objects
|
|
||||||
square1 = Square()
|
|
||||||
square2 = Square()
|
|
||||||
square3 = Square()
|
|
||||||
square4 = Square()
|
|
||||||
|
|
||||||
# Variable to keep our game loop running
|
|
||||||
gameOn = True
|
|
||||||
|
|
||||||
# Our game loop
|
|
||||||
while gameOn:
|
|
||||||
# for loop through the event queue
|
|
||||||
for event in pygame.event.get():
|
|
||||||
|
|
||||||
# Check for KEYDOWN event
|
|
||||||
if event.type == KEYDOWN:
|
|
||||||
|
|
||||||
# If the Backspace key has been pressed set
|
|
||||||
# running to false to exit the main loop
|
|
||||||
if event.key == K_BACKSPACE:
|
|
||||||
gameOn = False
|
|
||||||
|
|
||||||
# Check for QUIT event
|
|
||||||
elif event.type == QUIT:
|
|
||||||
gameOn = False
|
|
||||||
|
|
||||||
# Define where the squares will appear on the screen
|
|
||||||
# Use blit to draw them on the screen surface
|
|
||||||
screen.blit(square1.surf, (40, 40))
|
|
||||||
screen.blit(square2.surf, (40, 530))
|
|
||||||
screen.blit(square3.surf, (730, 40))
|
|
||||||
screen.blit(square4.surf, (730, 530))
|
|
||||||
|
|
||||||
# Update the display using flip
|
|
||||||
pygame.display.flip()
|
|
Loading…
Reference in a new issue