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

@ -138,9 +138,10 @@ class Deck():
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
@ -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 not self.is_empty():
if pos < 0: if pos < 0:
card = self.cards.pop() card = self.cards.pop()
else: else:
card = self.cards.pop(pos) card = self.cards.pop(pos)
self.set_card_positions() self.set_card_positions()
return card 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))