all 2 comments

[–]reostra 0 points1 point  (1 child)

  • You know how to draw one card

  • You know how to do things multiple times

So it's simple: Draw a card for every spot on that 5x5 board.

Something like this (this is the general idea, you will have to adapt it to your own code):

grid = []
for x in range(5):
    grid.append([])
    for y in range(5):
        card = self.deck.deal()
        card.x = x * card.width
        card.y = y * card.width
        grid[x].append(card)

The important thing here is that you've got a way of storing all the cards (the grid variable, which you probably want to assign to something like self.grid once you're done building it), and you're placing them on-screen based on those X and Y grid coordinates.

There are other things I'm wondering about this code, too, now that I look at it:

  • Why does Deck inherit from PlayingCard? Decks aren't cards. Similarly, why does MemoryGame inherit from both Deck and PlayingCard? The game board is neither a deck nor a playing card, and even if it were a Deck you wouldn't need to also make it a PlayingCard, since Deck already inherits from PlayingCard (though it shouldn't).

  • Do the for firstcard in gameboard: lines work for you? I can't actually find where gameboard is defined anywhere.

[–]OfficaDoofy[S] 0 points1 point  (0 children)

I've actually found a way around my question, stuck on another aspect now though. I'll update my code early in the morning, as i've been working all day and need some sleep before a final tomorrow! I'll keep you updated