# I need help with a crazy 8's program for computer programming

• 2 or 4 players depending on whether you play with partners.
• Winner is the first player or partnership to get rid of all of their cards.
• One card in the discard pile starts face up.
• Players must play the rank or suit of the discarded card.
• If player can't play a card, they must draw cards until they can play a card or the pile is empty.
• Eights are wild and can be played on any card. If a player plays an eight, they get to choose the suit that the next player must play.

in the file added I have three Classes (Deck,Class, and player) those three are for the crazy eight program

## Get Help With a similar task to - I need help with a crazy 8's program for computer programming

card.py class card: """Represent a card with a rank, suit, and numerical value.""" def __init__(self, suit, rank): """ Constructor that takes two arguments and sets all three class-level variables. The suit and rank should be set to STRINGS while the numerical value should be set to an integer.\n suit: The suit (Clubs, Diamonds, Hearts, Spades)\n rank: The rank (2, 3, 4, ..., J, Q, K, A) of the card.\n""" self.suit = suit self.rank = rank self.value = 0 self.setValue() # Accessors def getSuit(self): """Return the value of the card as a string""" return self.suit def getRank(self): """Return the rank of the card as a string""" return self.rank def getFullRank(self): """Return the full name of a rank if it is J, Q, K, or A""" if(self.rank in "JQKA"): if(self.rank == "J"): return "Jack" elif (self.rank == "Q"): return "Queen" elif (self.rank == "K"): return "King" elif (self.rank == "A"): return "Ace" else: return self.rank def getValue(self): """Return the value of the card as an integer""" return self.value def setValue(self): """Set the numerical value of each card based on the rank.\n J = 11, Q = 12, K = 13, A = 14""" if(self.rank in "JQKA"): if (self.rank == "J"): self.value = 11 elif (self.rank == "Q"): self.value = 12 elif (self.rank == "K"): self.value = 13 elif (self.rank == "A"): self.value = 14 else: self.value = int(self.rank) def compareTo(self,otherCard): """Compare the current card's value to the otherCard's value.\n Return a number less than 0 if the current card < otherCard\n Return a number greater than 0 if the current card > otherCard\n Return 0 if the current card == otherCard""" return self.value - otherCard.getValue() def __str__(self): """Return "[rank] of [suit]" as a string using the class-level variables """ return self.getFullRank() + " of " + self.suit deck.py import card import random # Sets up a "enum" for card values # https://en.wikipedia.org/wiki/Enumerated_type Values = ("2","3","4","5","6","7","8","9","10","J","Q","K","A") class Deck: def __init__(self): """Populates list of card objects with 13 ranks for each suit SCHD.\n pos is used for dealing cards, keeps track of what cards are dealt without permanently deleting cards from the deck.""" self.pos = 0 self.__listofcards = [] for i in range(len(Values)): self.__listofcards.append(card.card("Spades",Values[i])) self.__listofcards.append(card.card("Clubs",Values[i])) self.__listofcards.append(card.card("Hearts",Values[i])) self.__listofcards.append(card.card("Diamonds",Values[i])) def getDeck(self): """Returns list of cards""" return self.__listofcards def size(self): """Returns the current size of the deck, which is 52 cards - where the position is currently.""" return 52 - self.pos def deal(self): """Returns card at pos and then moves pos up by 1""" card_del = self.__listofcards[self.pos] self.pos +=1 return card_del def shuffle(self): """Chooses 2 random number, swaps those two indexes in the list""" for i in range(20000): one = random.randrange(len(self.__listofcards)) two = random.randrange(len(self.__listofcards)) self.__listofcards[one],self.__listofcards[two] = self.__listofcards[two],self.__listofcards[one] def __str__(self): """Returns the list of cards as a String""" my_string = "" for i in range(len(self.__listofcards)): my_string += self.__listofcards[i].__str__()+"\n" return my_string main.py import card import deck import player def main(): name1 = input("Whats the first player's name? ") name2 = input("Whats the second player's name? ") deck1 = deck.Deck() deck1.shuffle() #while loop??? player1 = player.player(name1+"'s ") player1.takeCard(deck1.deal()) player1.takeCard(deck1.deal()) player1.takeCard(deck1.deal()) player2 = player.player(name2+"'s ") player2.takeCard(deck1.deal()) player2.takeCard(deck1.deal()) player2.takeCard(deck1.deal()) print (player1,player2) main() player.py import random class player: def __init__(self,name): self.name = name self.hand = [] self.score = 0 def getname(self): '''returns the name''' return self.name def getHand(self): return self.hand def totalscore(self): '''does the total score''' return self.score def addScore(self,score): self.score +=score def size(self): return len(self.hand) def resetHand(self): self.hand = [] def setHand(self, newHand): self.hand = newHand def takeCard(self, newCard): self.hand.append(newCard) def takeCards(self,newCards): while(len(newCards)>0): self.hand.append(newCards[0]) del newCards [0] def displayHand(self): count = 0 for currentCard in self.hand: count += 1 print(str(count)+". "+currentCard+"\n") def chooseCard(self, index): return self.hand[index] def chooseRandomCard(self): rndCard =random.randrange(self.size()) return self.chooseCard(rndCard) def playTopCard(self): topCard = self.hand[0] del self.hand[0] return topCard def __str__(self): '''return data of object as a string''' stuff = self.name+"Total points: "+str(self.score)+"\n" for currentCard in self.hand: stuff +=str(currentCard)+"\n" return stuff

## Related Questions

Similar orders to I need help with a crazy 8's program for computer programming
24
Views
1
Python - Homework
Running perfectly - if is possible 10/10 on Pylint....
30
Views
0
highschool python assessment
need this done by jan 25 just write the code in python and send me video or screenshots they should be detailed pls...
12
Views
0
highschool python assignment
so this assessment needs to be submitted on jan25th it need to be detailed and user friendly just send me screenshots of all the code i need to write so that when i write it in python and run it in idle it works but send detailed screenshots...
14
Views
0