card game

This is the place to post any code that you want to share with the community. Only completed scripts should be posted here.
Note: posts here are not necessarily endorsed by the community, and may represent amateur or even bad practices.

card game

Postby jelseg » Mon Jul 29, 2013 10:26 pm

I recently made a cardgame (using pygame)

you can download it here:

it is based on the game patience (solitaire). But the way you draw cards is different: when you click on the stack there will come a new card on top of every card.

to drag a card click the left mousebutton, move the mouse and click again. To put the card back on his original place (while dragging) cick the right mousebutton.
if you want to put a card to the top you can also press the rigth mousebutton instead.

ps. I'm still loocking for a name, suggestions are welcome
Posts: 3
Joined: Mon Jun 17, 2013 11:25 am

Re: card game

Postby metulburr » Tue Jul 30, 2013 12:04 am

upload it to or something
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
User avatar
Posts: 2161
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: card game

Postby Mekire » Tue Jul 30, 2013 12:50 am

I agree, you should get a repo. Git is a little overwhelming at first, but it will save many headaches in the future. Also people can look over your code without downloading anything.

For your game, first of all you need to get all those graphic resources out of the toplevel directory. It isn't professional to crowd your top directory. Next, though I haven't looked over your code in detail, things like this strike me:

Code: Select all
elif self.boxrects[0].collidepoint(x,y):
    if not self.boxes[0]==[0,0]:
        if self.boxes[0][1]==0:
elif self.boxrects[1].collidepoint(x,y):
    if not self.boxes[1]==[0,0]:
        if self.boxes[1][1]==0:
elif self.boxrects[2].collidepoint(x,y):
    if not self.boxes[2]==[0,0]:
        if self.boxes[2][1]==0:
elif self.boxrects[3].collidepoint(x,y):
    if not self.boxes[3]==[0,0]:
        if self.boxes[3][1]==0:

Anytime you have this kind of redundancy, you need to reevaluate your approach:
Code: Select all
for i,box in enumerate(self.boxes):
    if self.boxrects[i].collidepoint(x,y):
        if not box == [0,0]:
            self.dragging = [('box',i),(box[0],box[1])]
            box[1] -= 1
            if box[1] == 0:
                box[0] = 0

Also during your dealcards function in the beginning of your game is completely cut off from your event loop. This can easily cause the game to hang. Your game should have one single event loop (and only one single call to pygame.display.update()) and it should never be cut off from it. If being cut off from the event loop is unavoidable (which it shouldn't be), you need to call pygame.event.pump() to avoid hanging.

Regardless of criticism, good job on your game. Keep up the good work,
New Users, Read This
  • Use code tags when posting code.
  • Include any errors with your post (in code tags).
  • Describe your problem; not your chosen solution.
  • Make examples the minimum length to demonstrate your issue.
User avatar
Posts: 1705
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

Return to Completed Scripts

Who is online

Users browsing this forum: Bing [Bot] and 4 guests