Fix card offset problem

master
En Yi 2019-05-04 20:17:11 +01:00
parent 09e44d0ca2
commit 9874cd4b45
2 changed files with 19 additions and 15 deletions

View File

@ -132,28 +132,29 @@ class Deck():
def set_card_positions(self): def set_card_positions(self):
number_of_cards = len(self.cards) number_of_cards = len(self.cards)
if number_of_cards > 0 : if number_of_cards > 0:
if self.is_horizontal(): if self.is_horizontal():
total_card_length = self.cards[0].width + self.default_spacing * (number_of_cards-1) total_card_length = self.cards[0].width + self.default_spacing * (number_of_cards-1)
if total_card_length <= self.length: if total_card_length <= self.length:
start_point = (self.length - total_card_length)/2 start_point = (self.length - total_card_length)/2
for (i, card) in enumerate(self.cards): for (i, card) in enumerate(self.cards):
card.x = start_point + self.default_spacing * (i-1) card.x = start_point + self.default_spacing * i
card.y = (self.width - self.cards[0].height)/ 2 card.y = (self.width - self.cards[0].height) / 2
else: else:
# TODO: make sure that deck length is always longer than card width
adjusted_spacing = (self.length - self.cards[0].width)/(number_of_cards-1) adjusted_spacing = (self.length - self.cards[0].width)/(number_of_cards-1)
start_point = 0 start_point = 0
for (i, card) in enumerate(self.cards): for (i, card) in enumerate(self.cards):
card.x = start_point + adjusted_spacing * i card.x = start_point + adjusted_spacing * i
card.y = (self.width - self.cards[0].height)/ 2 card.y = (self.width - self.cards[0].height) / 2
else: else:
total_card_length = self.cards[0].height + self.default_spacing * (number_of_cards-1) total_card_length = self.cards[0].height + self.default_spacing * (number_of_cards-1)
if total_card_length <= self.length: if total_card_length <= self.length:
start_point = (self.length - total_card_length)/2 start_point = (self.length - total_card_length)/2
for (i, card) in enumerate(self.cards): for (i, card) in enumerate(self.cards):
card.y = start_point + self.default_spacing * (i-1) card.y = start_point + self.default_spacing * (i-1)
card.x = (self.width - self.cards[0].width)/ 2 card.x = (self.width - self.cards[0].width) / 2
else: else:
adjusted_spacing = (self.length - self.cards[0].height)/(number_of_cards-1) adjusted_spacing = (self.length - self.cards[0].height)/(number_of_cards-1)
@ -175,13 +176,14 @@ class Deck():
self.deck_surface.blit(card.image, (card.x, card.y)) self.deck_surface.blit(card.image, (card.x, card.y))
def remove_card(self, pos=-1): def remove_card(self, pos=-1):
if pos < 0: if not self.is_empty():
card = self.cards.pop() if pos < 0:
else: card = self.cards.pop()
card = self.cards.pop(pos) else:
self.set_card_positions() card = self.cards.pop(pos)
return card self.set_card_positions()
return card
return None
def is_horizontal(self): def is_horizontal(self):
return not self.vert_orientation return not self.vert_orientation

View File

@ -139,10 +139,11 @@ class Table:
#while(True): #while(True):
if self.game_state == GameState.DEALING: if self.game_state == GameState.DEALING:
if self.discard_deck: if self.discard_deck:
dealt_cards = random.sample(self.discard_deck, 13) for i in range(10):
random.shuffle(self.discard_deck)
for player in self.players: for player in self.players:
for card in dealt_cards: for i in range(STARTING_HAND):
player.add_card(card) player.add_card(self.discard_deck.pop())
self.update_table.emit() self.update_table.emit()
print("Shuffle Complete!") print("Shuffle Complete!")
self.game_state = GameState.POINT_CHECK self.game_state = GameState.POINT_CHECK
@ -167,6 +168,7 @@ class Table:
pass pass
else: else:
for player in self.players: for player in self.players:
print(len(player.cards))
while not player.is_empty(): while not player.is_empty():
self.discard_deck.append(player.remove_card()) self.discard_deck.append(player.remove_card())
print(len(self.discard_deck)) print(len(self.discard_deck))