From 64f60514d70a28a00959857c9d040bf8fcf84ae6 Mon Sep 17 00:00:00 2001 From: En Yi Date: Mon, 10 Jun 2019 17:48:43 +0100 Subject: [PATCH] Clean up deck rendering --- cards.py | 42 ++++++++++++------------------------------ table.py | 3 ++- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/cards.py b/cards.py index 7817642..e7f92dd 100644 --- a/cards.py +++ b/cards.py @@ -201,39 +201,21 @@ class Deck(): number_of_cards = len(self.cards) if number_of_cards > 0: - if self.is_horizontal(): - total_card_length = self.cards[0].width + self.default_spacing * (number_of_cards-1) - if total_card_length <= self.length - 2*self.line_width: - start_point = (self.length - total_card_length)/2 - for (i, card) in enumerate(self.cards): - x = start_point + self.default_spacing * i - y = (self.width - self.cards[0].height) / 2 - card.set_pos(x, y) - else: - adjusted_spacing = (self.length - self.cards[0].width - 2*self.line_width)/(number_of_cards-1) - - start_point = self.line_width - for (i, card) in enumerate(self.cards): - x = start_point + adjusted_spacing * i - y = (self.width - self.cards[0].height) / 2 - card.set_pos(x, y) + total_card_length = self.cards[0].width + self.default_spacing * (number_of_cards - 1) + if total_card_length <= self.length - 2 * self.line_width: + start_point = (self.length - total_card_length) / 2 + spacing = self.default_spacing else: - total_card_length = self.cards[0].height + self.default_spacing * (number_of_cards-1) + start_point = self.line_width + spacing = (self.length - self.cards[0].width - 2*self.line_width)/(number_of_cards-1) - if total_card_length <= self.length: - start_point = (self.length - total_card_length)/2 - for (i, card) in enumerate(self.cards): - y = start_point + self.default_spacing * i - x = (self.width - self.cards[0].height) / 2 - card.set_pos(x, y) + for (i, card) in enumerate(self.cards): + x = start_point + spacing * i + y = (self.width - self.cards[0].height) / 2 + if self.is_horizontal(): + card.set_pos(x, y) else: - adjusted_spacing = (self.length - self.cards[0].height)/(number_of_cards-1) - - start_point = 0 - for (i, card) in enumerate(self.cards): - y = start_point + adjusted_spacing * i - x = (self.width - self.cards[0].width) / 2 - card.set_pos(x, y) + card.set_pos(y, x) self.update_deck_display() diff --git a/table.py b/table.py index 6605691..8f5676d 100644 --- a/table.py +++ b/table.py @@ -145,7 +145,8 @@ class Table: self.players.append(players.Player(playerx[i], playery[i], l_deck, w_deck, spacing, vert_orientation=vert, - deck_reveal=reveal_mode, flip=(i == 1 or i == 2))) + deck_reveal=reveal_mode, flip=(i == 1 or i == 2), + draw_from_last=(i == 2 or i == 3))) self.players[i].connect_to_table(self.table_status) if i > 0: self.players[i].add_ai(ai.RandomAI(self.table_status))