How does one make it to where all the objects in a list are clickable in Python’s Pygame












0















I’m creating a card game for a project at school and I can’t seem to get it to where the Deck_1 will allow the user to play any card from the list.



I’m also having trouble getting different classes to interact with one another. I’ve been trying to get the different Decks to give cards to each other.



Here is the code for 4 of the decks. Any help would be appreciated.



class Deck_1(Deck):
"""This is a child class"""
def __init__(self,x,y):
#call parent's constructor:
Deck.__init__(self,x,y)
self.y = y
self.x = x
self.cards=
self.a = None
def extend_list(self,a):
self.cards.extend(a)
if len(self.cards) > 0:
for i in range(len(self.cards)):
self.rect.top += 32

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
x = self.x
pygame.draw.rect(screen,BLACK,[self.rect.left,self.rect.top,72,104],2)
i = self.y
if len(self.cards) > 0:
for item in self.cards:
screen.blit(card_dict[item],[x,self.rect.top])
x += 72
else:
if len(self.cards) > 0:
for item in self.cards:
screen.blit(card_dict[item],[x,self.rect.top])
x += 72
pygame.draw.ellipse(screen,OLIVE,[40,40,60,60],5)
def add_card(self,card):
if len(self.cards) < 4:
for i in range(len(card)):
self.rect.top += 32
else:
for i in range(len(card)):
if i > 0:
self.rect.top += 32
self.cards.extend(card)

def click_down(self,card):
"""This is used when the user press the mouse button"""
self.card = card
if len(self.cards) > 0:
x=self.x
left = self.rect.left
top = self.rect.top
lst =
for i in range(len(self.cards)):
if self.check_pos():
pos = pygame.mouse.get_pos()
lst.insert(0,self.cards.pop())
card.card_d = (pos[0] - self.rect.left,pos[1] -
self.rect.top)
card.moved = True
card.cards = self
card.moved_card.extend(lst)
if len(self.cards) > 0:
left-= 72
break
else:
lst.insert(0,self.cards.pop())
self.rect.left -= 72
else:
self.rect.left = left
self.cards.extend(lst)


def check_card(self,moved_card):
card = moved_card[0]
result = False

def show_card(self):
if len(self.cards) == 0 and len(self.hidden) > 0:
self.cards.append(self.hidden.pop())

class Deck_3(Deck):
def __init__(self,x,y):
#call parent's constructor:
Deck.__init__(self,x,y)
self.y = y
self.x = x
self.cards =
Deck_1.__init__(self,x,y)
Deck_5.__init__(self,x,y)
def check_card(self,moved_card):
result = False
next_card = ['2_clubs' , '3_clubs' , '4_clubs' , '5_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs' , '2_diamonds' , '3_diamonds' , '4_diamonds' , '5_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '3_hearts' , '4_hearts' , '5_hearts', '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '3_spades' , '4_spades' , '5_spades', '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']

if len(moved_card) == 1:
card = moved_card[0]
if len(self.cards) == 0:
result = True

elif card == '10_clubs' or card == '10_diamonds' or card == '10_hearts' or card == '10_spades':
result=True
for i in self.cards:
a=self.cards.remove(i)
Deck_5.extend_list(a)

elif card == 'red_joker' or card == 'black_joker':
if len(Deck5.cards)==0:
result=False
else:
result=True
for i in Deck_5.cards:
a=Deck_5.cards.remove(i)
Deck_3.extend_list(a)



else:
if '2_clubs' in self.cards[-1] or '2_diamonds' in self.cards[-1] or '2_hearts' in self.cards[-1] or '2_spades' in self.cards[-1]:
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '3_clubs' in self.cards[-1] or '3_diamonds' in self.cards[-1] or '3_hearts' in self.cards[-1] or '3_spades' in self.cards[-1]:
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '4_clubs' in self.cards[-1] or '4_diamonds' in self.cards[-1] or '4_hearts' in self.cards[-1] or '4_spades' in self.cards[-1]:
next_card = ['2_clubs' , '4_clubs' , '5_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '4_diamonds' , '5_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds' , 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '4_hearts' , '5_hearts' , '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts','2_spades' , '4_spades' , '5_spades', '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades' , 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '5_clubs' in self.cards[-1] or '5_diamonds' in self.cards[-1] or '5_hearts' in self.cards[-1] or '5_spades' in self.cards[-1]:
next_card = ['2_clubs' , '5_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '5_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '5_hearts', '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '5_spades' , '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '6_clubs' in self.cards[-1] or '6_diamonds' in self.cards[-1] or '6_hearts' in self.cards[-1] or '6_spades' in self.cards[-1]:
next_card = ['2_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts', '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades', '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '7_clubs' in self.cards[-1] or '7_diamonds' in self.cards[-1] or '7_hearts' in self.cards[-1] or '7_spades' in self.cards[-1]:
next_card = ['2_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds' , 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '8_clubs' in self.cards[-1] or '8_diamonds' in self.cards[-1] or '8_hearts' in self.cards[-1] or '8_spades' in self.cards[-1]:
next_card = ['2_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '8_spades' , '9_spades' , '10_spades' , 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '9_clubs' in self.cards[-1] or '9_diamonds' in self.cards[-1] or '9_hearts' in self.cards[-1] or '9_spades' in self.cards[-1]:
next_card = ['2_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
else:
self.cards
except Exception as e:
print(str(e))
elif '10_clubs' in self.cards[-1] or '10_diamonds' in self.cards[-1] or '10_hearts' in self.cards[-1] or '10_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'jack_clubs' in self.cards[-1] or 'jack_diamonds' in self.cards[-1] or 'jack_hearts' in self.cards[-1] or 'jack_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'queen_clubs' in self.cards[-1] or 'queen_diamonds' in self.cards[-1] or 'queen_hearts' in self.cards[-1] or 'queen_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'king_clubs' in self.cards[-1] or 'king_diamonds' in self.cards[-1] or 'king_hearts' in self.cards[-1] or 'king_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs', 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds', 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'ace_clubs' in self.cards[-1] or 'ace_diamonds' in self.cards[-1] or 'ace_hearts' in self.cards[-1] or 'ace_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts' , 'ace_hearts', '2_spades' , '10_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'red_joker' in self.cards[-1] or 'black_joker' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
else:
if len(self.cards)==0:
result=False
else:
result=False
for i in self.cards:
a=self.cards.remove(i)
Deck_1.extend_list(a)


print(result)
return result
def click_down(self,card):
"""This is used when the user press the mouse button"""
result=False

def extend_list(self,a):
self.cards.extend(a)
if len(self.cards) > 0:
for i in range(len(self.cards)):
self.rect.top += 32

def add_card(self,card):
self.cards.extend(card)

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
pygame.draw.rect(screen,BLACK,[self.rect.left,self.rect.top,72,104],2)
if len(self.cards) > 0:
screen.blit(card_dict[self.cards[-1]],[self.rect.left,self.rect.top])
class Deck_4(Deck_1):
"""This is a child class"""
def __init__(self,x,y):
#call parent's constructor:
Deck_1.__init__(self,x,y)
self.y = y
self.hidden =
self.cards=

def extend_list(self,lst):
self.hidden.extend(lst)
self.cards.append(self.hidden.pop())
if len(self.hidden) > 0:
for i in range(len(self.hidden)):
self.rect.top += 32

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
pygame.draw.rect(screen,BLACK,[self.rect.left,self.rect.top,72,104],2)
i = self.y
if len(self.hidden) > 0:
for item in self.hidden:
pygame.draw.rect(screen,TEAL,[self.rect.left,i,71,96])
pygame.draw.rect(screen,BLACK,[self.rect.left,i,71,96],2)
i += 32
if len(self.cards) > 0:
for item in self.cards:
screen.blit(card_dict[item],[self.rect.left,i])
i += 32

def add_card(self,card):
if len(self.cards) > 0 or len(self.hidden) > 0:
for i in range(len(card)):
self.rect.top += 32
else:
for i in range(len(card)):
if i > 0:
self.rect.top += 32
self.cards.extend(card)

def click_down(self,card):
"""This is used when the user press the mouse button"""
if len(Deck_1.cards) == 0:
if len(self.cards) > 0:
top = self.rect.top
lst =
for i in range(len(self.cards)):
if self.check_pos():
pos = pygame.mouse.get_pos()
lst.insert(0,self.cards.pop())
card.card_d = (pos[0] - self.rect.left,pos[1] -
self.rect.top)
card.moved = True
card.cards = self
card.moved_card.extend(lst)
if len(self.cards) > 0:
self.rect.top -= 32
break
else:
lst.insert(0,self.cards.pop())
self.rect.top -= 32
else:
self.rect.top = top
self.cards.extend(lst)

def show_card(self):
if len(self.cards) == 0 and len(self.hidden) > 0:
self.cards.append(self.hidden.pop())

def check_card(self,moved_card):
result = False

class Deck_5(Deck):
"""This is a child class"""
def __init__(self,x,y):
#call parent's constructor:
Deck.__init__(self,x,y)
self.y = y
self.x = x
self.card=None
self.cards=
self.a=None
def click_down(self,card):
"""This is used when the user press the mouse button"""
result=False

def extend_list(self,a):
self.cards.extend(a)
if len(self.cards) > 0:
for i in range(len(self.cards)):
self.rect.top += 32

def add_card(self,card):
self.cards.extend(card)

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
pygame.draw.rect(screen,RED,[self.rect.left,self.rect.top,72,104],2)
if len(self.cards) > 0:
screen.blit(card_dict[self.cards[-1]],[self.rect.left,self.rect.top])


def check_card(self,moved_card):
result = False









share|improve this question




















  • 2





    Possible duplicate of Pygame mouse clicking detection

    – Green Cloak Guy
    Nov 22 '18 at 3:06
















0















I’m creating a card game for a project at school and I can’t seem to get it to where the Deck_1 will allow the user to play any card from the list.



I’m also having trouble getting different classes to interact with one another. I’ve been trying to get the different Decks to give cards to each other.



Here is the code for 4 of the decks. Any help would be appreciated.



class Deck_1(Deck):
"""This is a child class"""
def __init__(self,x,y):
#call parent's constructor:
Deck.__init__(self,x,y)
self.y = y
self.x = x
self.cards=
self.a = None
def extend_list(self,a):
self.cards.extend(a)
if len(self.cards) > 0:
for i in range(len(self.cards)):
self.rect.top += 32

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
x = self.x
pygame.draw.rect(screen,BLACK,[self.rect.left,self.rect.top,72,104],2)
i = self.y
if len(self.cards) > 0:
for item in self.cards:
screen.blit(card_dict[item],[x,self.rect.top])
x += 72
else:
if len(self.cards) > 0:
for item in self.cards:
screen.blit(card_dict[item],[x,self.rect.top])
x += 72
pygame.draw.ellipse(screen,OLIVE,[40,40,60,60],5)
def add_card(self,card):
if len(self.cards) < 4:
for i in range(len(card)):
self.rect.top += 32
else:
for i in range(len(card)):
if i > 0:
self.rect.top += 32
self.cards.extend(card)

def click_down(self,card):
"""This is used when the user press the mouse button"""
self.card = card
if len(self.cards) > 0:
x=self.x
left = self.rect.left
top = self.rect.top
lst =
for i in range(len(self.cards)):
if self.check_pos():
pos = pygame.mouse.get_pos()
lst.insert(0,self.cards.pop())
card.card_d = (pos[0] - self.rect.left,pos[1] -
self.rect.top)
card.moved = True
card.cards = self
card.moved_card.extend(lst)
if len(self.cards) > 0:
left-= 72
break
else:
lst.insert(0,self.cards.pop())
self.rect.left -= 72
else:
self.rect.left = left
self.cards.extend(lst)


def check_card(self,moved_card):
card = moved_card[0]
result = False

def show_card(self):
if len(self.cards) == 0 and len(self.hidden) > 0:
self.cards.append(self.hidden.pop())

class Deck_3(Deck):
def __init__(self,x,y):
#call parent's constructor:
Deck.__init__(self,x,y)
self.y = y
self.x = x
self.cards =
Deck_1.__init__(self,x,y)
Deck_5.__init__(self,x,y)
def check_card(self,moved_card):
result = False
next_card = ['2_clubs' , '3_clubs' , '4_clubs' , '5_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs' , '2_diamonds' , '3_diamonds' , '4_diamonds' , '5_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '3_hearts' , '4_hearts' , '5_hearts', '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '3_spades' , '4_spades' , '5_spades', '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']

if len(moved_card) == 1:
card = moved_card[0]
if len(self.cards) == 0:
result = True

elif card == '10_clubs' or card == '10_diamonds' or card == '10_hearts' or card == '10_spades':
result=True
for i in self.cards:
a=self.cards.remove(i)
Deck_5.extend_list(a)

elif card == 'red_joker' or card == 'black_joker':
if len(Deck5.cards)==0:
result=False
else:
result=True
for i in Deck_5.cards:
a=Deck_5.cards.remove(i)
Deck_3.extend_list(a)



else:
if '2_clubs' in self.cards[-1] or '2_diamonds' in self.cards[-1] or '2_hearts' in self.cards[-1] or '2_spades' in self.cards[-1]:
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '3_clubs' in self.cards[-1] or '3_diamonds' in self.cards[-1] or '3_hearts' in self.cards[-1] or '3_spades' in self.cards[-1]:
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '4_clubs' in self.cards[-1] or '4_diamonds' in self.cards[-1] or '4_hearts' in self.cards[-1] or '4_spades' in self.cards[-1]:
next_card = ['2_clubs' , '4_clubs' , '5_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '4_diamonds' , '5_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds' , 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '4_hearts' , '5_hearts' , '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts','2_spades' , '4_spades' , '5_spades', '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades' , 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '5_clubs' in self.cards[-1] or '5_diamonds' in self.cards[-1] or '5_hearts' in self.cards[-1] or '5_spades' in self.cards[-1]:
next_card = ['2_clubs' , '5_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '5_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '5_hearts', '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '5_spades' , '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '6_clubs' in self.cards[-1] or '6_diamonds' in self.cards[-1] or '6_hearts' in self.cards[-1] or '6_spades' in self.cards[-1]:
next_card = ['2_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts', '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades', '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '7_clubs' in self.cards[-1] or '7_diamonds' in self.cards[-1] or '7_hearts' in self.cards[-1] or '7_spades' in self.cards[-1]:
next_card = ['2_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds' , 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '8_clubs' in self.cards[-1] or '8_diamonds' in self.cards[-1] or '8_hearts' in self.cards[-1] or '8_spades' in self.cards[-1]:
next_card = ['2_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '8_spades' , '9_spades' , '10_spades' , 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '9_clubs' in self.cards[-1] or '9_diamonds' in self.cards[-1] or '9_hearts' in self.cards[-1] or '9_spades' in self.cards[-1]:
next_card = ['2_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
else:
self.cards
except Exception as e:
print(str(e))
elif '10_clubs' in self.cards[-1] or '10_diamonds' in self.cards[-1] or '10_hearts' in self.cards[-1] or '10_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'jack_clubs' in self.cards[-1] or 'jack_diamonds' in self.cards[-1] or 'jack_hearts' in self.cards[-1] or 'jack_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'queen_clubs' in self.cards[-1] or 'queen_diamonds' in self.cards[-1] or 'queen_hearts' in self.cards[-1] or 'queen_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'king_clubs' in self.cards[-1] or 'king_diamonds' in self.cards[-1] or 'king_hearts' in self.cards[-1] or 'king_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs', 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds', 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'ace_clubs' in self.cards[-1] or 'ace_diamonds' in self.cards[-1] or 'ace_hearts' in self.cards[-1] or 'ace_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts' , 'ace_hearts', '2_spades' , '10_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'red_joker' in self.cards[-1] or 'black_joker' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
else:
if len(self.cards)==0:
result=False
else:
result=False
for i in self.cards:
a=self.cards.remove(i)
Deck_1.extend_list(a)


print(result)
return result
def click_down(self,card):
"""This is used when the user press the mouse button"""
result=False

def extend_list(self,a):
self.cards.extend(a)
if len(self.cards) > 0:
for i in range(len(self.cards)):
self.rect.top += 32

def add_card(self,card):
self.cards.extend(card)

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
pygame.draw.rect(screen,BLACK,[self.rect.left,self.rect.top,72,104],2)
if len(self.cards) > 0:
screen.blit(card_dict[self.cards[-1]],[self.rect.left,self.rect.top])
class Deck_4(Deck_1):
"""This is a child class"""
def __init__(self,x,y):
#call parent's constructor:
Deck_1.__init__(self,x,y)
self.y = y
self.hidden =
self.cards=

def extend_list(self,lst):
self.hidden.extend(lst)
self.cards.append(self.hidden.pop())
if len(self.hidden) > 0:
for i in range(len(self.hidden)):
self.rect.top += 32

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
pygame.draw.rect(screen,BLACK,[self.rect.left,self.rect.top,72,104],2)
i = self.y
if len(self.hidden) > 0:
for item in self.hidden:
pygame.draw.rect(screen,TEAL,[self.rect.left,i,71,96])
pygame.draw.rect(screen,BLACK,[self.rect.left,i,71,96],2)
i += 32
if len(self.cards) > 0:
for item in self.cards:
screen.blit(card_dict[item],[self.rect.left,i])
i += 32

def add_card(self,card):
if len(self.cards) > 0 or len(self.hidden) > 0:
for i in range(len(card)):
self.rect.top += 32
else:
for i in range(len(card)):
if i > 0:
self.rect.top += 32
self.cards.extend(card)

def click_down(self,card):
"""This is used when the user press the mouse button"""
if len(Deck_1.cards) == 0:
if len(self.cards) > 0:
top = self.rect.top
lst =
for i in range(len(self.cards)):
if self.check_pos():
pos = pygame.mouse.get_pos()
lst.insert(0,self.cards.pop())
card.card_d = (pos[0] - self.rect.left,pos[1] -
self.rect.top)
card.moved = True
card.cards = self
card.moved_card.extend(lst)
if len(self.cards) > 0:
self.rect.top -= 32
break
else:
lst.insert(0,self.cards.pop())
self.rect.top -= 32
else:
self.rect.top = top
self.cards.extend(lst)

def show_card(self):
if len(self.cards) == 0 and len(self.hidden) > 0:
self.cards.append(self.hidden.pop())

def check_card(self,moved_card):
result = False

class Deck_5(Deck):
"""This is a child class"""
def __init__(self,x,y):
#call parent's constructor:
Deck.__init__(self,x,y)
self.y = y
self.x = x
self.card=None
self.cards=
self.a=None
def click_down(self,card):
"""This is used when the user press the mouse button"""
result=False

def extend_list(self,a):
self.cards.extend(a)
if len(self.cards) > 0:
for i in range(len(self.cards)):
self.rect.top += 32

def add_card(self,card):
self.cards.extend(card)

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
pygame.draw.rect(screen,RED,[self.rect.left,self.rect.top,72,104],2)
if len(self.cards) > 0:
screen.blit(card_dict[self.cards[-1]],[self.rect.left,self.rect.top])


def check_card(self,moved_card):
result = False









share|improve this question




















  • 2





    Possible duplicate of Pygame mouse clicking detection

    – Green Cloak Guy
    Nov 22 '18 at 3:06














0












0








0








I’m creating a card game for a project at school and I can’t seem to get it to where the Deck_1 will allow the user to play any card from the list.



I’m also having trouble getting different classes to interact with one another. I’ve been trying to get the different Decks to give cards to each other.



Here is the code for 4 of the decks. Any help would be appreciated.



class Deck_1(Deck):
"""This is a child class"""
def __init__(self,x,y):
#call parent's constructor:
Deck.__init__(self,x,y)
self.y = y
self.x = x
self.cards=
self.a = None
def extend_list(self,a):
self.cards.extend(a)
if len(self.cards) > 0:
for i in range(len(self.cards)):
self.rect.top += 32

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
x = self.x
pygame.draw.rect(screen,BLACK,[self.rect.left,self.rect.top,72,104],2)
i = self.y
if len(self.cards) > 0:
for item in self.cards:
screen.blit(card_dict[item],[x,self.rect.top])
x += 72
else:
if len(self.cards) > 0:
for item in self.cards:
screen.blit(card_dict[item],[x,self.rect.top])
x += 72
pygame.draw.ellipse(screen,OLIVE,[40,40,60,60],5)
def add_card(self,card):
if len(self.cards) < 4:
for i in range(len(card)):
self.rect.top += 32
else:
for i in range(len(card)):
if i > 0:
self.rect.top += 32
self.cards.extend(card)

def click_down(self,card):
"""This is used when the user press the mouse button"""
self.card = card
if len(self.cards) > 0:
x=self.x
left = self.rect.left
top = self.rect.top
lst =
for i in range(len(self.cards)):
if self.check_pos():
pos = pygame.mouse.get_pos()
lst.insert(0,self.cards.pop())
card.card_d = (pos[0] - self.rect.left,pos[1] -
self.rect.top)
card.moved = True
card.cards = self
card.moved_card.extend(lst)
if len(self.cards) > 0:
left-= 72
break
else:
lst.insert(0,self.cards.pop())
self.rect.left -= 72
else:
self.rect.left = left
self.cards.extend(lst)


def check_card(self,moved_card):
card = moved_card[0]
result = False

def show_card(self):
if len(self.cards) == 0 and len(self.hidden) > 0:
self.cards.append(self.hidden.pop())

class Deck_3(Deck):
def __init__(self,x,y):
#call parent's constructor:
Deck.__init__(self,x,y)
self.y = y
self.x = x
self.cards =
Deck_1.__init__(self,x,y)
Deck_5.__init__(self,x,y)
def check_card(self,moved_card):
result = False
next_card = ['2_clubs' , '3_clubs' , '4_clubs' , '5_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs' , '2_diamonds' , '3_diamonds' , '4_diamonds' , '5_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '3_hearts' , '4_hearts' , '5_hearts', '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '3_spades' , '4_spades' , '5_spades', '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']

if len(moved_card) == 1:
card = moved_card[0]
if len(self.cards) == 0:
result = True

elif card == '10_clubs' or card == '10_diamonds' or card == '10_hearts' or card == '10_spades':
result=True
for i in self.cards:
a=self.cards.remove(i)
Deck_5.extend_list(a)

elif card == 'red_joker' or card == 'black_joker':
if len(Deck5.cards)==0:
result=False
else:
result=True
for i in Deck_5.cards:
a=Deck_5.cards.remove(i)
Deck_3.extend_list(a)



else:
if '2_clubs' in self.cards[-1] or '2_diamonds' in self.cards[-1] or '2_hearts' in self.cards[-1] or '2_spades' in self.cards[-1]:
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '3_clubs' in self.cards[-1] or '3_diamonds' in self.cards[-1] or '3_hearts' in self.cards[-1] or '3_spades' in self.cards[-1]:
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '4_clubs' in self.cards[-1] or '4_diamonds' in self.cards[-1] or '4_hearts' in self.cards[-1] or '4_spades' in self.cards[-1]:
next_card = ['2_clubs' , '4_clubs' , '5_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '4_diamonds' , '5_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds' , 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '4_hearts' , '5_hearts' , '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts','2_spades' , '4_spades' , '5_spades', '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades' , 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '5_clubs' in self.cards[-1] or '5_diamonds' in self.cards[-1] or '5_hearts' in self.cards[-1] or '5_spades' in self.cards[-1]:
next_card = ['2_clubs' , '5_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '5_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '5_hearts', '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '5_spades' , '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '6_clubs' in self.cards[-1] or '6_diamonds' in self.cards[-1] or '6_hearts' in self.cards[-1] or '6_spades' in self.cards[-1]:
next_card = ['2_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts', '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades', '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '7_clubs' in self.cards[-1] or '7_diamonds' in self.cards[-1] or '7_hearts' in self.cards[-1] or '7_spades' in self.cards[-1]:
next_card = ['2_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds' , 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '8_clubs' in self.cards[-1] or '8_diamonds' in self.cards[-1] or '8_hearts' in self.cards[-1] or '8_spades' in self.cards[-1]:
next_card = ['2_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '8_spades' , '9_spades' , '10_spades' , 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '9_clubs' in self.cards[-1] or '9_diamonds' in self.cards[-1] or '9_hearts' in self.cards[-1] or '9_spades' in self.cards[-1]:
next_card = ['2_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
else:
self.cards
except Exception as e:
print(str(e))
elif '10_clubs' in self.cards[-1] or '10_diamonds' in self.cards[-1] or '10_hearts' in self.cards[-1] or '10_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'jack_clubs' in self.cards[-1] or 'jack_diamonds' in self.cards[-1] or 'jack_hearts' in self.cards[-1] or 'jack_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'queen_clubs' in self.cards[-1] or 'queen_diamonds' in self.cards[-1] or 'queen_hearts' in self.cards[-1] or 'queen_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'king_clubs' in self.cards[-1] or 'king_diamonds' in self.cards[-1] or 'king_hearts' in self.cards[-1] or 'king_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs', 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds', 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'ace_clubs' in self.cards[-1] or 'ace_diamonds' in self.cards[-1] or 'ace_hearts' in self.cards[-1] or 'ace_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts' , 'ace_hearts', '2_spades' , '10_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'red_joker' in self.cards[-1] or 'black_joker' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
else:
if len(self.cards)==0:
result=False
else:
result=False
for i in self.cards:
a=self.cards.remove(i)
Deck_1.extend_list(a)


print(result)
return result
def click_down(self,card):
"""This is used when the user press the mouse button"""
result=False

def extend_list(self,a):
self.cards.extend(a)
if len(self.cards) > 0:
for i in range(len(self.cards)):
self.rect.top += 32

def add_card(self,card):
self.cards.extend(card)

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
pygame.draw.rect(screen,BLACK,[self.rect.left,self.rect.top,72,104],2)
if len(self.cards) > 0:
screen.blit(card_dict[self.cards[-1]],[self.rect.left,self.rect.top])
class Deck_4(Deck_1):
"""This is a child class"""
def __init__(self,x,y):
#call parent's constructor:
Deck_1.__init__(self,x,y)
self.y = y
self.hidden =
self.cards=

def extend_list(self,lst):
self.hidden.extend(lst)
self.cards.append(self.hidden.pop())
if len(self.hidden) > 0:
for i in range(len(self.hidden)):
self.rect.top += 32

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
pygame.draw.rect(screen,BLACK,[self.rect.left,self.rect.top,72,104],2)
i = self.y
if len(self.hidden) > 0:
for item in self.hidden:
pygame.draw.rect(screen,TEAL,[self.rect.left,i,71,96])
pygame.draw.rect(screen,BLACK,[self.rect.left,i,71,96],2)
i += 32
if len(self.cards) > 0:
for item in self.cards:
screen.blit(card_dict[item],[self.rect.left,i])
i += 32

def add_card(self,card):
if len(self.cards) > 0 or len(self.hidden) > 0:
for i in range(len(card)):
self.rect.top += 32
else:
for i in range(len(card)):
if i > 0:
self.rect.top += 32
self.cards.extend(card)

def click_down(self,card):
"""This is used when the user press the mouse button"""
if len(Deck_1.cards) == 0:
if len(self.cards) > 0:
top = self.rect.top
lst =
for i in range(len(self.cards)):
if self.check_pos():
pos = pygame.mouse.get_pos()
lst.insert(0,self.cards.pop())
card.card_d = (pos[0] - self.rect.left,pos[1] -
self.rect.top)
card.moved = True
card.cards = self
card.moved_card.extend(lst)
if len(self.cards) > 0:
self.rect.top -= 32
break
else:
lst.insert(0,self.cards.pop())
self.rect.top -= 32
else:
self.rect.top = top
self.cards.extend(lst)

def show_card(self):
if len(self.cards) == 0 and len(self.hidden) > 0:
self.cards.append(self.hidden.pop())

def check_card(self,moved_card):
result = False

class Deck_5(Deck):
"""This is a child class"""
def __init__(self,x,y):
#call parent's constructor:
Deck.__init__(self,x,y)
self.y = y
self.x = x
self.card=None
self.cards=
self.a=None
def click_down(self,card):
"""This is used when the user press the mouse button"""
result=False

def extend_list(self,a):
self.cards.extend(a)
if len(self.cards) > 0:
for i in range(len(self.cards)):
self.rect.top += 32

def add_card(self,card):
self.cards.extend(card)

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
pygame.draw.rect(screen,RED,[self.rect.left,self.rect.top,72,104],2)
if len(self.cards) > 0:
screen.blit(card_dict[self.cards[-1]],[self.rect.left,self.rect.top])


def check_card(self,moved_card):
result = False









share|improve this question
















I’m creating a card game for a project at school and I can’t seem to get it to where the Deck_1 will allow the user to play any card from the list.



I’m also having trouble getting different classes to interact with one another. I’ve been trying to get the different Decks to give cards to each other.



Here is the code for 4 of the decks. Any help would be appreciated.



class Deck_1(Deck):
"""This is a child class"""
def __init__(self,x,y):
#call parent's constructor:
Deck.__init__(self,x,y)
self.y = y
self.x = x
self.cards=
self.a = None
def extend_list(self,a):
self.cards.extend(a)
if len(self.cards) > 0:
for i in range(len(self.cards)):
self.rect.top += 32

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
x = self.x
pygame.draw.rect(screen,BLACK,[self.rect.left,self.rect.top,72,104],2)
i = self.y
if len(self.cards) > 0:
for item in self.cards:
screen.blit(card_dict[item],[x,self.rect.top])
x += 72
else:
if len(self.cards) > 0:
for item in self.cards:
screen.blit(card_dict[item],[x,self.rect.top])
x += 72
pygame.draw.ellipse(screen,OLIVE,[40,40,60,60],5)
def add_card(self,card):
if len(self.cards) < 4:
for i in range(len(card)):
self.rect.top += 32
else:
for i in range(len(card)):
if i > 0:
self.rect.top += 32
self.cards.extend(card)

def click_down(self,card):
"""This is used when the user press the mouse button"""
self.card = card
if len(self.cards) > 0:
x=self.x
left = self.rect.left
top = self.rect.top
lst =
for i in range(len(self.cards)):
if self.check_pos():
pos = pygame.mouse.get_pos()
lst.insert(0,self.cards.pop())
card.card_d = (pos[0] - self.rect.left,pos[1] -
self.rect.top)
card.moved = True
card.cards = self
card.moved_card.extend(lst)
if len(self.cards) > 0:
left-= 72
break
else:
lst.insert(0,self.cards.pop())
self.rect.left -= 72
else:
self.rect.left = left
self.cards.extend(lst)


def check_card(self,moved_card):
card = moved_card[0]
result = False

def show_card(self):
if len(self.cards) == 0 and len(self.hidden) > 0:
self.cards.append(self.hidden.pop())

class Deck_3(Deck):
def __init__(self,x,y):
#call parent's constructor:
Deck.__init__(self,x,y)
self.y = y
self.x = x
self.cards =
Deck_1.__init__(self,x,y)
Deck_5.__init__(self,x,y)
def check_card(self,moved_card):
result = False
next_card = ['2_clubs' , '3_clubs' , '4_clubs' , '5_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs' , '2_diamonds' , '3_diamonds' , '4_diamonds' , '5_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '3_hearts' , '4_hearts' , '5_hearts', '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '3_spades' , '4_spades' , '5_spades', '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']

if len(moved_card) == 1:
card = moved_card[0]
if len(self.cards) == 0:
result = True

elif card == '10_clubs' or card == '10_diamonds' or card == '10_hearts' or card == '10_spades':
result=True
for i in self.cards:
a=self.cards.remove(i)
Deck_5.extend_list(a)

elif card == 'red_joker' or card == 'black_joker':
if len(Deck5.cards)==0:
result=False
else:
result=True
for i in Deck_5.cards:
a=Deck_5.cards.remove(i)
Deck_3.extend_list(a)



else:
if '2_clubs' in self.cards[-1] or '2_diamonds' in self.cards[-1] or '2_hearts' in self.cards[-1] or '2_spades' in self.cards[-1]:
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '3_clubs' in self.cards[-1] or '3_diamonds' in self.cards[-1] or '3_hearts' in self.cards[-1] or '3_spades' in self.cards[-1]:
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '4_clubs' in self.cards[-1] or '4_diamonds' in self.cards[-1] or '4_hearts' in self.cards[-1] or '4_spades' in self.cards[-1]:
next_card = ['2_clubs' , '4_clubs' , '5_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '4_diamonds' , '5_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds' , 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '4_hearts' , '5_hearts' , '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts','2_spades' , '4_spades' , '5_spades', '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades' , 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '5_clubs' in self.cards[-1] or '5_diamonds' in self.cards[-1] or '5_hearts' in self.cards[-1] or '5_spades' in self.cards[-1]:
next_card = ['2_clubs' , '5_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '5_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '5_hearts', '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '5_spades' , '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '6_clubs' in self.cards[-1] or '6_diamonds' in self.cards[-1] or '6_hearts' in self.cards[-1] or '6_spades' in self.cards[-1]:
next_card = ['2_clubs', '6_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds', '6_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts', '6_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades', '6_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '7_clubs' in self.cards[-1] or '7_diamonds' in self.cards[-1] or '7_hearts' in self.cards[-1] or '7_spades' in self.cards[-1]:
next_card = ['2_clubs' , '7_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '7_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds' , 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '7_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '7_spades' , '8_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '8_clubs' in self.cards[-1] or '8_diamonds' in self.cards[-1] or '8_hearts' in self.cards[-1] or '8_spades' in self.cards[-1]:
next_card = ['2_clubs' , '8_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '8_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '8_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '8_spades' , '9_spades' , '10_spades' , 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif '9_clubs' in self.cards[-1] or '9_diamonds' in self.cards[-1] or '9_hearts' in self.cards[-1] or '9_spades' in self.cards[-1]:
next_card = ['2_clubs' , '9_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '9_diamonds', '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '9_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '9_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
else:
self.cards
except Exception as e:
print(str(e))
elif '10_clubs' in self.cards[-1] or '10_diamonds' in self.cards[-1] or '10_hearts' in self.cards[-1] or '10_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'jack_clubs' in self.cards[-1] or 'jack_diamonds' in self.cards[-1] or 'jack_hearts' in self.cards[-1] or 'jack_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'queen_clubs' in self.cards[-1] or 'queen_diamonds' in self.cards[-1] or 'queen_hearts' in self.cards[-1] or 'queen_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'king_clubs' in self.cards[-1] or 'king_diamonds' in self.cards[-1] or 'king_hearts' in self.cards[-1] or 'king_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs', 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds', 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'ace_clubs' in self.cards[-1] or 'ace_diamonds' in self.cards[-1] or 'ace_hearts' in self.cards[-1] or 'ace_spades' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts' , 'ace_hearts', '2_spades' , '10_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
elif 'red_joker' in self.cards[-1] or 'black_joker' in self.cards[-1]:
next_card = ['2_clubs' , '10_clubs' , 'jack_clubs', 'queen_clubs' , 'king_clubs' , 'ace_clubs', '2_diamonds' , '10_diamonds' , 'jack_diamonds', 'queen_diamonds' , 'king_diamonds' , 'ace_diamonds', '2_hearts' , '10_hearts', 'jack_hearts' , 'queen_hearts' , 'king_hearts' , 'ace_hearts', '2_spades' , '10_spades', 'jack_spades' , 'queen_spades' , 'king_spades' , 'ace_spades', 'red_joker' , 'black_joker']
try:
if (card in next_card):
result = True
except Exception as e:
print(str(e))
else:
if len(self.cards)==0:
result=False
else:
result=False
for i in self.cards:
a=self.cards.remove(i)
Deck_1.extend_list(a)


print(result)
return result
def click_down(self,card):
"""This is used when the user press the mouse button"""
result=False

def extend_list(self,a):
self.cards.extend(a)
if len(self.cards) > 0:
for i in range(len(self.cards)):
self.rect.top += 32

def add_card(self,card):
self.cards.extend(card)

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
pygame.draw.rect(screen,BLACK,[self.rect.left,self.rect.top,72,104],2)
if len(self.cards) > 0:
screen.blit(card_dict[self.cards[-1]],[self.rect.left,self.rect.top])
class Deck_4(Deck_1):
"""This is a child class"""
def __init__(self,x,y):
#call parent's constructor:
Deck_1.__init__(self,x,y)
self.y = y
self.hidden =
self.cards=

def extend_list(self,lst):
self.hidden.extend(lst)
self.cards.append(self.hidden.pop())
if len(self.hidden) > 0:
for i in range(len(self.hidden)):
self.rect.top += 32

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
pygame.draw.rect(screen,BLACK,[self.rect.left,self.rect.top,72,104],2)
i = self.y
if len(self.hidden) > 0:
for item in self.hidden:
pygame.draw.rect(screen,TEAL,[self.rect.left,i,71,96])
pygame.draw.rect(screen,BLACK,[self.rect.left,i,71,96],2)
i += 32
if len(self.cards) > 0:
for item in self.cards:
screen.blit(card_dict[item],[self.rect.left,i])
i += 32

def add_card(self,card):
if len(self.cards) > 0 or len(self.hidden) > 0:
for i in range(len(card)):
self.rect.top += 32
else:
for i in range(len(card)):
if i > 0:
self.rect.top += 32
self.cards.extend(card)

def click_down(self,card):
"""This is used when the user press the mouse button"""
if len(Deck_1.cards) == 0:
if len(self.cards) > 0:
top = self.rect.top
lst =
for i in range(len(self.cards)):
if self.check_pos():
pos = pygame.mouse.get_pos()
lst.insert(0,self.cards.pop())
card.card_d = (pos[0] - self.rect.left,pos[1] -
self.rect.top)
card.moved = True
card.cards = self
card.moved_card.extend(lst)
if len(self.cards) > 0:
self.rect.top -= 32
break
else:
lst.insert(0,self.cards.pop())
self.rect.top -= 32
else:
self.rect.top = top
self.cards.extend(lst)

def show_card(self):
if len(self.cards) == 0 and len(self.hidden) > 0:
self.cards.append(self.hidden.pop())

def check_card(self,moved_card):
result = False

class Deck_5(Deck):
"""This is a child class"""
def __init__(self,x,y):
#call parent's constructor:
Deck.__init__(self,x,y)
self.y = y
self.x = x
self.card=None
self.cards=
self.a=None
def click_down(self,card):
"""This is used when the user press the mouse button"""
result=False

def extend_list(self,a):
self.cards.extend(a)
if len(self.cards) > 0:
for i in range(len(self.cards)):
self.rect.top += 32

def add_card(self,card):
self.cards.extend(card)

def draw_card(self,screen,card_dict):
"""This will draw all the cards on the screen"""
pygame.draw.rect(screen,RED,[self.rect.left,self.rect.top,72,104],2)
if len(self.cards) > 0:
screen.blit(card_dict[self.cards[-1]],[self.rect.left,self.rect.top])


def check_card(self,moved_card):
result = False






python






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 3:05









Green Cloak Guy

3,0741721




3,0741721










asked Nov 22 '18 at 2:25









Toris SherwoodToris Sherwood

1




1








  • 2





    Possible duplicate of Pygame mouse clicking detection

    – Green Cloak Guy
    Nov 22 '18 at 3:06














  • 2





    Possible duplicate of Pygame mouse clicking detection

    – Green Cloak Guy
    Nov 22 '18 at 3:06








2




2





Possible duplicate of Pygame mouse clicking detection

– Green Cloak Guy
Nov 22 '18 at 3:06





Possible duplicate of Pygame mouse clicking detection

– Green Cloak Guy
Nov 22 '18 at 3:06












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423049%2fhow-does-one-make-it-to-where-all-the-objects-in-a-list-are-clickable-in-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423049%2fhow-does-one-make-it-to-where-all-the-objects-in-a-list-are-clickable-in-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()