diff --git a/README.md b/README.md index f7ac49f..934ae7b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ ## Memory Game -This is my final project (option 1) for ITSE-1479. Instead of using the provided +This is my final project (option 1) for ITSE-1479. +Instead of using the provided cardback.png image, I used a photo of one of my turtles as the card back. + diff --git a/card.py b/card.py index 230c814..0468e5f 100644 --- a/card.py +++ b/card.py @@ -15,26 +15,10 @@ class Card(ImageSprite): 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.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. \ diff --git a/image_sprite.py b/image_sprite.py index b1a5ce6..999102d 100644 --- a/image_sprite.py +++ b/image_sprite.py @@ -10,10 +10,12 @@ class ImageSprite(pygame.sprite.Sprite): :param screen_height: """ super().__init__() - self.image = pygame.image.load(image_path) + self.image = pygame.image.load(image_path) self.rect = self.image.get_rect() self.rect.move(screen_width / 2, screen_height / 2) + self.width = screen_width + self.height = screen_height def is_clicked(self): """ @@ -33,5 +35,4 @@ class ImageSprite(pygame.sprite.Sprite): :param y: y coordinate :return: None """ - self.rect.move(x, y) - + self.rect.move(x / self.width, y / self.height) diff --git a/main.py b/main.py index 3c27541..6c548da 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ import os import random import pygame -from image_sprite import Card +from card import Card # CONSTANTS WIDTH = 1600 @@ -19,13 +19,20 @@ image_files.extend(image_files) random.shuffle(image_files) # Create sprites -cards = [Card(f'images/{image_files}', WIDTH, HEIGHT) for file in image_files] +cards = [Card(f'images/{file}', WIDTH, HEIGHT) for file in image_files] +for card in cards: + screen.blit(card.image, card.rect) +pygame.display.flip() + # Move sprites +# TODO: Fix initial movement of sprites for i in range(16): # Note: Coordinates start from (0, 0) at top left of screen. # Arrange cards in a grid, 4x4, with a margin of 20 pixels between each card. # Array from left to right, then top to bottom. - cards[i].move(i * (150 * i % 4) + 85, i * (150 * int(i / 4)) + 85) + cards[i].move((150 * (i % 4)) + 85, (150 * int(i / 4)) + 85) + print(str((150 * (i % 4)) + 85), str((150 * int(i / 4)) + 85)) + print(cards[i].rect) game_is_running = True @@ -44,5 +51,5 @@ while game_is_running: clicked_cards.append(card) card.on_click() card.flip_card() - + cards[0].move(1, 0) pygame.display.flip()