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.

card game

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

I recently made a cardgame (using pygame)

you can download it here: http://speedy.sh/wbXDm/card-game.rar

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.

controls:
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
jelseg
 
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 github.com or something
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1407
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]:
        self.dragging=[('box',0),(self.boxes[0][0],self.boxes[0][1])]
        self.boxes[0][1]-=1
        if self.boxes[0][1]==0:
            self.boxes[0][0]=0
elif self.boxrects[1].collidepoint(x,y):
    if not self.boxes[1]==[0,0]:
        self.dragging=[('box',1),(self.boxes[1][0],self.boxes[1][1])]
        self.boxes[1][1]-=1
        if self.boxes[1][1]==0:
            self.boxes[1][0]=0
elif self.boxrects[2].collidepoint(x,y):
    if not self.boxes[2]==[0,0]:
        self.dragging=[('box',2),(self.boxes[2][0],self.boxes[2][1])]
        self.boxes[2][1]-=1
        if self.boxes[2][1]==0:
            self.boxes[2][0]=0
elif self.boxrects[3].collidepoint(x,y):
    if not self.boxes[3]==[0,0]:
        self.dragging=[('box',3),(self.boxes[3][0],self.boxes[3][1])]
        self.boxes[3][1]-=1
        if self.boxes[3][1]==0:
            self.boxes[3][0]=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,
-Mek
User avatar
Mekire
 
Posts: 987
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan


Return to Completed Scripts

Who is online

Users browsing this forum: No registered users and 1 guest