Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- class Card:
- def __init__(self, suit, val):
- self.suit = suit
- self.value = val
- def show(self):
- print("{} of {}".format(self.value, self.suit))
- def sendWhole(self):
- return "{} of {}".format(self.value, self.suit)
- def cvalue(self):
- return self.value
- class Deck:
- def __init__(self):
- self.cards = []
- self.build()
- def build(self):
- for s in ["Spades", "Clubs", "Diamonds", "Hearts"]:
- for v in range(1,14):
- self.cards.append(Card(s, v))
- def showDeck(self):
- for card in self.cards:
- card.show()
- def shuffle(self):
- for i in range(len(self.cards) - 1, 0, -1): #Randomizing
- r = random.randint(0, i)
- self.cards[i], self.cards[r] = self.cards[r], self.cards[i]
- def drawCard(self):
- return self.cards.pop()
- def cardAmount(self):
- return len(self.cards)
- class Player:
- def __init__(self, name):
- self.name = name
- self.hand = []
- def draw(self, deck):
- self.hand.insert(0,(deck.drawCard()))
- return self
- def playCard(self):
- currentCard = self.hand.pop()
- deck1.cards.append(currentCard)
- cardValues.append(currentCard.cvalue())
- return currentCard.show()
- def playWarMatt(self):
- if not self.hand:
- Noah.givePlayedNoah()
- gameOver(0)
- else:
- currentCard = self.hand.pop()
- deck1.cards.append(currentCard)
- print("Matt Places a Card Face Down")
- if not self.hand:
- Noah.givePlayedNoah()
- gameOver(0)
- else:
- Matt.playCard()
- def playWarNoah(self):
- if not self.hand:
- Matt.givePlayedMatt()
- gameOver(1)
- else:
- currentCard = self.hand.pop()
- deck1.cards.append(currentCard)
- print("Noah Places a Card Face Down")
- if not self.hand:
- Matt.givePlayedMatt()
- gameOver(1)
- else:
- Noah.playCard()
- def count(self):
- return len(self.hand)
- def showHand(self):
- for card in self.hand:
- card.show()
- def givePlayedMatt(self):
- deck1.shuffle()
- for card in range(deck1.cardAmount()):
- Matt.draw(deck1)
- def givePlayedNoah(self):
- deck1.shuffle()
- for card in range(deck1.cardAmount()):
- Noah.draw(deck1)
- Matt = Player("Matt!")
- Noah = Player("Noah!")
- deck1 = Deck()
- deck1.shuffle()
- deck1.shuffle()
- for num in range(0, 26):
- Matt.draw(deck1)
- Noah.draw(deck1)
- cardValues = []
- def gameOver(playerNo):
- print("Game Over!")
- if playerNo == 0:
- print("Noah Wins!")
- elif playerNo == 1:
- print("Matt Wins!")
- else:
- print("Invalid PlayerNo")
- return 0
- mtally = 0
- ntally = 0
- while Matt.count() != 0 and Matt.count() != 52:
- print("Matt plays")
- Matt.playCard()
- print("Noah plays")
- Noah.playCard()
- if cardValues[0] > cardValues[1]:
- print("Matt Wins the Pot!")
- Matt.givePlayedMatt()
- cardValues = []
- mtally += 1
- print(Matt.count())
- print(Noah.count())
- elif cardValues[0] < cardValues[1]:
- print("Noah Wins the Pot!")
- Noah.givePlayedNoah()
- cardValues = []
- ntally += 1
- print(Noah.count())
- print(Matt.count())
- else:
- print("WAR!")
- cardValues = []
- Matt.playWarMatt()
- Noah.playWarNoah()
- if cardValues[0] > cardValues[1]:
- print("Matt Wins the Pot!")
- Matt.givePlayedMatt()
- cardValues = []
- mtally += 1
- print(Matt.count())
- print(Noah.count())
- elif cardValues[0] < cardValues[1]:
- print("Noah Wins the Pot!")
- Noah.givePlayedNoah()
- cardValues = []
- ntally += 1
- print(Noah.count())
- print(Matt.count())
- print("Game Step Complete")
- #Checking for GameOver
- if Matt.count() == 0:
- gameOver(0)
- elif Noah.count() == 0:
- gameOver(1)
- print("-------------------Matt's Hand-------------------")
- print(Matt.count())
- print(mtally)
- print("-------------------Noah's Hand-------------------")
- print(Noah.count())
- print(ntally)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement