Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.42 KB | None | 0 0
  1. import random
  2. class Card:
  3.     def __init__(self, suit, val):
  4.         self.suit = suit
  5.         self.value = val
  6.  
  7.     def show(self):
  8.         print("{} of {}".format(self.value, self.suit))
  9.  
  10.     def sendWhole(self):
  11.         return "{} of {}".format(self.value, self.suit)
  12.  
  13.     def cvalue(self):
  14.         return self.value
  15.  
  16. class Deck:
  17.     def __init__(self):
  18.         self.cards = []
  19.         self.build()
  20.  
  21.     def build(self):
  22.         for s in ["Spades", "Clubs", "Diamonds", "Hearts"]:
  23.             for v in range(1,14):
  24.                 self.cards.append(Card(s, v))
  25.  
  26.     def showDeck(self):
  27.         for card in self.cards:
  28.             card.show()
  29.  
  30.     def shuffle(self):
  31.         for i in range(len(self.cards) - 1, 0, -1): #Randomizing
  32.             r = random.randint(0, i)
  33.             self.cards[i], self.cards[r] = self.cards[r], self.cards[i]
  34.  
  35.     def drawCard(self):
  36.         return self.cards.pop()
  37.  
  38.     def cardAmount(self):
  39.         return len(self.cards)
  40.  
  41. class Player:
  42.     def __init__(self, name):
  43.         self.name = name
  44.         self.hand = []
  45.  
  46.     def draw(self, deck):
  47.         self.hand.insert(0,(deck.drawCard()))
  48.         return self
  49.  
  50.     def playCard(self):
  51.         currentCard = self.hand.pop()
  52.         deck1.cards.append(currentCard)
  53.         cardValues.append(currentCard.cvalue())
  54.         return currentCard.show()
  55.  
  56.     def playWarMatt(self):
  57.         if not self.hand:
  58.             Noah.givePlayedNoah()
  59.             gameOver(0)
  60.         else:
  61.             currentCard = self.hand.pop()
  62.             deck1.cards.append(currentCard)
  63.             print("Matt Places a Card Face Down")
  64.         if not self.hand:
  65.             Noah.givePlayedNoah()
  66.             gameOver(0)
  67.         else:
  68.             Matt.playCard()
  69.  
  70.     def playWarNoah(self):
  71.         if not self.hand:
  72.             Matt.givePlayedMatt()
  73.             gameOver(1)
  74.         else:
  75.             currentCard = self.hand.pop()
  76.             deck1.cards.append(currentCard)
  77.             print("Noah Places a Card Face Down")
  78.         if not self.hand:
  79.             Matt.givePlayedMatt()
  80.             gameOver(1)
  81.         else:
  82.             Noah.playCard()
  83.  
  84.     def count(self):
  85.         return len(self.hand)
  86.  
  87.     def showHand(self):
  88.         for card in self.hand:
  89.             card.show()
  90.  
  91.     def givePlayedMatt(self):
  92.         deck1.shuffle()
  93.         for card in range(deck1.cardAmount()):
  94.             Matt.draw(deck1)
  95.  
  96.     def givePlayedNoah(self):
  97.         deck1.shuffle()
  98.         for card in range(deck1.cardAmount()):
  99.             Noah.draw(deck1)
  100.  
  101. Matt = Player("Matt!")
  102. Noah = Player("Noah!")
  103. deck1 = Deck()
  104. deck1.shuffle()
  105. deck1.shuffle()
  106. for num in range(0, 26):
  107.     Matt.draw(deck1)
  108.     Noah.draw(deck1)
  109.  
  110. cardValues = []
  111.  
  112. def gameOver(playerNo):
  113.     print("Game Over!")
  114.     if playerNo == 0:
  115.         print("Noah Wins!")
  116.     elif playerNo == 1:
  117.         print("Matt Wins!")
  118.     else:
  119.         print("Invalid PlayerNo")
  120.     return 0
  121.  
  122. mtally = 0
  123. ntally = 0
  124.  
  125. while Matt.count() != 0 and Matt.count() != 52:
  126.     print("Matt plays")
  127.     Matt.playCard()
  128.     print("Noah plays")
  129.     Noah.playCard()
  130.     if  cardValues[0] > cardValues[1]:
  131.         print("Matt Wins the Pot!")
  132.         Matt.givePlayedMatt()
  133.         cardValues = []
  134.         mtally += 1
  135.         print(Matt.count())
  136.         print(Noah.count())
  137.     elif cardValues[0] < cardValues[1]:
  138.         print("Noah Wins the Pot!")
  139.         Noah.givePlayedNoah()
  140.         cardValues = []
  141.         ntally += 1
  142.         print(Noah.count())
  143.         print(Matt.count())
  144.     else:
  145.         print("WAR!")
  146.         cardValues = []
  147.         Matt.playWarMatt()
  148.         Noah.playWarNoah()
  149.         if cardValues[0] > cardValues[1]:
  150.             print("Matt Wins the Pot!")
  151.             Matt.givePlayedMatt()
  152.             cardValues = []
  153.             mtally += 1
  154.             print(Matt.count())
  155.             print(Noah.count())
  156.         elif cardValues[0] < cardValues[1]:
  157.             print("Noah Wins the Pot!")
  158.             Noah.givePlayedNoah()
  159.             cardValues = []
  160.             ntally += 1
  161.             print(Noah.count())
  162.             print(Matt.count())
  163.     print("Game Step Complete")
  164.  
  165. #Checking for GameOver
  166. if Matt.count() == 0:
  167.     gameOver(0)
  168. elif Noah.count() == 0:
  169.     gameOver(1)
  170.  
  171. print("-------------------Matt's Hand-------------------")
  172. print(Matt.count())
  173. print(mtally)
  174. print("-------------------Noah's Hand-------------------")
  175. print(Noah.count())
  176. print(ntally)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement