Mar-06-2020, 02:53 PM
Hey guys/gals,
I have been working on my first python project of modelling a deck of standard playing cards. I am hoping to program a basic card game and then begin making a GUI for it.
I am stuck on getting the players hand organized. The card class has two attributes: value, suit. I would like to organize by 'value' so that I can come back check for pairs, 3 of a kind, etc...
Also, I just started reviewing PEP-8 recently. So I will be reorganizing things after its all functional as a learning exercise.
What do you guys/gals recommend
I have been working on my first python project of modelling a deck of standard playing cards. I am hoping to program a basic card game and then begin making a GUI for it.
I am stuck on getting the players hand organized. The card class has two attributes: value, suit. I would like to organize by 'value' so that I can come back check for pairs, 3 of a kind, etc...
Also, I just started reviewing PEP-8 recently. So I will be reorganizing things after its all functional as a learning exercise.
What do you guys/gals recommend
from Card import Card class Deck: def __init__(self): self.deck_of_cards=[] def initialize_deck(self): suits = ["Hearts", "Clubs", "Spades", "Diamonds"] values = ["Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"] for suit in suits: for value in values: temp_card = Card() #create a temporary card for each iteration temp_card.setvalue(value) #set value and suit of temporary card prior to storage temp_card.setsuit(suit) self.deck_of_cards.append(temp_card) #store card in the Deck object def shuffle_deck(self): import random #Import "random" module to gain access to "random.shuffle()" random.shuffle(self.deck_of_cards) def draw_card(self): temp_card = self.deck_of_cards.pop() return(temp_card) def load_card(self, temp_card): self.deck_of_cards.append(temp_card)
class Card: def __init__(self): self.value = "UNASSIGNED VALUE" self.suit = "UNASSIGNED SUIT" #def __init__(self, newvalue, newsuit): #self.value = newvalue #self.suit = newsuit def getvalue(self): return(self.value) def getsuit(self): return(self.suit) def setvalue(self, new_value): self.value=new_value def setsuit(self, new_suit): self.suit=new_suit def identify_card(self): print(self.getvalue(), "of", self.getsuit())
from Deck import Deck from Card import Card class Hand: def __init__(self): self.cards_in_hand = [] def look_hand(self): for card in self.cards_in_hand: card.identify_card() def draw_card(self, deck): self.cards_in_hand.append(deck.draw_card()) #def give_card(self): #FUNCTION WILL REMOVE A SPECIFIC CARD FROM HAND.CARDS_IN_HAND[]. #FUNCTION WILL RECIEVE A NUMBER WHICH CORRELATES TO THE INDEX LOCATION OF THE #CARD TO BE RETURNED BY THE FUNCTION #def sort_hand(self): #FUNCTION WILL ORDER THE HAND BY VALUE OF THE CARDS. #def check_hand(self): #FUNCTION WILL RETURN AN INTEGER WHICH CORRESPONDS TO HIGHEST CHANCE TO WIN #AND AN INTEGER WHICH CORRESPONDS TO THE HIGH CARD OF THE HAND, # HIGH CARD = 0 # PAIR = 1 # TWO PAIR = 2 # 3 OF A KIND = 3 # STRAIGHT = 4 # FLUSH = 5 # FULL HOUSE = 6 # 4 OF A KIND = 7 # STR8T FLUSH = 8 # ROYAL FLUSH = 9 # 4 OF A KIND = 3 # HIGH CARD: 2 = [0], 3 = [1] ... ACE = [13]