Python Uno Card Game #68167
Replies: 2 comments 1 reply
This comment was marked as off-topic.
This comment was marked as off-topic.
-
|
GitHub's Acceptable Use Policies prohibits coordinated or inauthentic activity like rapid questions and answers. As a result, we'll be unmarking the answer and locking this post. Please note any future violations may result in a temporary or indefinite block from the Community. Thanks for understanding. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Question
Body
I am making an UNO card game and I generated and then shuffled a deck for it and each player is then given five cards from the shuffled deck. All the cards are supposed to be string objects in the lists but the wild card is being stored as a list object instead of a string object. I want it to be stored as a string.
import random
def buildDeck():
deck = []
colours = ["Red", "Green", "Yellow", "Blue"]
values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "Draw Two", "Skip", "Reverse"]
wilds = ["Wild", "Wild Draw Four"]
def shuffleDeck(deck):
for cardPos in range(len(deck)):
randPos = random.randint(0, 107)
deck[cardPos], deck[randPos] = deck[randPos], deck[cardPos]
return deck
def drawCards(numCards):
cardsDrawn = []
for x in range (numCards):
cardsDrawn.append(unoDeck.pop(0))
return cardsDrawn
def showHand(player, playerHand):
print("{}'s turn".format(player))
print("Your Hand")
print("-----------------------------")
y = 1
for card in playerHand:
print("{}) {}".format(y, card))
y += 1
print("")
unoDeck = buildDeck()
unoDeck = shuffleDeck(unoDeck)
discards = []
players = [] #List to store player cards
playerNames = [] #List to store player names
colours = ["Blue", "Red", "Green", "Yellow"]
numPlayers = None
print("Enter --help to display the rules of the game\n")
numPlayers = input("How many players? ")
if numPlayers == "--help" or numPlayers == "--resume":
checkInput(numPlayers)
else:
numPlayers = int(numPlayers)
while len(playerNames) < numPlayers:
tempName = input("Enter player's name: ")
if tempName == "--help" or tempName == "--resume":
checkInput(tempName)
else:
playerNames.append(tempName)
players.append(drawCards(5))
print("The cards are:")
for (x,y) in zip(playerNames, players):
print("Player {} has {}".format(x, y))
print("")
Beta Was this translation helpful? Give feedback.
All reactions