From 702b7839d02e2ba78155bf01b525d288d7ba9582 Mon Sep 17 00:00:00 2001 From: tyler Date: Thu, 5 Mar 2015 13:46:29 -0500 Subject: [PATCH] Tyler 3/5/15 --- Challenge2.py | 45 +++++++++++++ __pycache__/cards.cpython-32.pyc | Bin 0 -> 3977 bytes __pycache__/games.cpython-32.pyc | Bin 0 -> 1692 bytes blackjack.py | 109 +++++++++++++++++++++++++------ challeng2.py | 45 +++++++++++++ challeng2.py~ | 13 ++++ 6 files changed, 192 insertions(+), 20 deletions(-) create mode 100644 Challenge2.py create mode 100644 __pycache__/cards.cpython-32.pyc create mode 100644 __pycache__/games.cpython-32.pyc create mode 100644 challeng2.py create mode 100644 challeng2.py~ diff --git a/Challenge2.py b/Challenge2.py new file mode 100644 index 0000000..f04929a --- /dev/null +++ b/Challenge2.py @@ -0,0 +1,45 @@ +import random +RANKS =["A", "2", "3", "4", "5", "6", "7", + "8", "9", "10", "J", "Q", "K"] +SUITS = ["c", "d", "h", "s"] + +Player1Counter=0 +Player2Counter=0 +print("Welcome to WAR!") +print("You and a friend will player war until one of the two of you get ten points!") +print("Before we begin, Can you please enter our names.") +Player1Name=input("Player 1 Name: ") +Player2Name=input("Player 2 Name: ") +while Player1Counter < 10 and Player2Counter < 10: + Player1CardIndex=random.randrange(len(RANKS)) + Player2CardIndex=random.randrange(len(RANKS)) + Player1Card=RANKS[Player1CardIndex] + Player2Card=RANKS[Player2CardIndex] + if Player1CardIndex > 8: + Player1CardIndex = 10 + if Player2CardIndex > 8: + Player2CardIndex = 10 + Player1Suit=random.choice(SUITS) + Player2Suit=random.choice(SUITS) + Player1Card =Player1Card + Player1Suit + Player2Card = Player2Card + Player2Suit + print(Player1Name,":",Player1Card) + print(Player2Name,":",Player2Card) + if Player1CardIndex > Player2CardIndex: + print(Player1Name,"has won this round and has gained one point.") + Player1Counter += 1 + elif Player1CardIndex < Player2CardIndex: + print(Player2Name,"has won this round and has gained one point.") + Player2Counter += 1 + else: + print("Oh No! No one has won this round1") + print(Player1Name,":",Player1Counter) + print(Player2Name,":",Player2Counter) + input("Please press the key.") +if Player1Counter < Player2Counter: + print(Player1Name,"has won and is the ultimate champion!") +else: + print(Player2Name,"has won and is the ulimate champion!") +print("Thanks for playing.") +input("Please press to exit.") + diff --git a/__pycache__/cards.cpython-32.pyc b/__pycache__/cards.cpython-32.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4f60ecd7b66691f603db0ff6c56a933d28c2e763 GIT binary patch literal 3977 zcmcgvYj4~{6usV8y33}o^xXqz|AiR26B0psln#64WXpGG=Fzb+WM?KiWiU zKDEDxU&fE%oNKQ)SqfB1g_F6yGoG3IJ~KP)PIvD9@#jik4m=I;-=L+xfqZ8~-iR1S ztjO!StU4H~=}>(%RKrk1hniw*It$+#Vp_6QljK*iO)*pQ+7ZXL#GFtr#HMXop6x(L z-vQyn_cYogv~&mLmB_ac45`p#wMIQ4-P8pF4R*zLQ``|-nU0tb#B{|>%f_^j49{PJhxZ(Ew#LT%l zwOdenTj?F8pDX=B>6c3HD!r%leqO_>TQ{}yMCngTpDOJuHA)9c(|!XB`0&lei)iUb zAg>(y!vj-O2HmerjCgXUbD_~Di^X&z)b{T!s;y5F~69?x<@@zD;~-!gp) z-$!%7$}CC#DaiaF+P3rAMsAbDpI?ezhQr7=>HOlrk29Ni_vh)ZbS~b@Phh&|1!0hR z9_6Pk5OLc0t3pl-D=R-i2PSSp`D@Ck#hW#`xbH}am^lIlepsI6nw~oM`SZf&!xsMC zCS5YNnSM%atcD%QI=aa7(k$`3Q(#kCOXFs0t+9EGNo5|>sxYrx1oA-GIB_yaI>tz) z2-49NZm0SMh z@yfD#awW;_p)i-L)GIoJf;BVC?T1m{AEusnJaZP2V(OTaP^{y$ob%2l=WMOpY)`3F zey>uDZe)9emM(z6`ID&f22cRRP-G)e)D;teFbZshi>8hME?USw`X;{u;x4!YKQwN% zeh4knIrotGDg}sc8>#{7*o>=ILrpJh@e~eI1CJGXrsSvquYxb5U#Z3#pcI9eB`{_2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?>ytAyxWw(yNQ=78 rmoe;Fl(S|f_SWVup12j?yuhqg9=`W6*AJoph-HsE?N)nzgLT+Hi;ZZo literal 0 HcmV?d00001 diff --git a/blackjack.py b/blackjack.py index b98c635..2f7f7d3 100644 --- a/blackjack.py +++ b/blackjack.py @@ -1,5 +1,7 @@ # Blackjack # From 1 to 7 players compete against a dealer +#Help from interweb tutor +#and tom import cards, games @@ -66,26 +68,60 @@ def is_busted(self): return self.total > 21 + + + + + class BJ_Player(BJ_Hand): """ A Blackjack Player. """ + def betting(stash): + try: + if stash>0: + wager=int(input("\n How mush do you want to wager?: ")) + if wager > bet.stash: + int(input("\n You can only wager what you have. How much?: ")) + elif wager <0: + int(input("\nYou can only wager what you have. How much?: ")) + except ValuError: + int(input("\n Thats not valid choose a number: ")) + + def is_hitting(self): response = games.ask_yes_no("\n" + self.name + ", do you want a hit? (Y/N): ") return response == "y" - def bust(self): + def bust(self,stash,wager): print(self.name, "busts.") - self.lose() + self.lose(self,stash,wager) - def lose(self): + def lose(self,stash,wager): print(self.name, "loses.") + stash = stash - wager + print("Your stash is: ",stash) + return stash - def win(self): + def win(self,stash,wager): print(self.name, "wins.") + stash = stash + wager + print("Your stash is: ",stash) + return stash def push(self): print(self.name, "pushes.") - + def betting(bet,stash): + try: + if stash > 0: + wager = int(input("\nHow much do you want to wager?: ")) + if wager > stash: + int(input("\n You can only wager what you have. How much?: ")) + elif wager < 0: + int(input("\n You can only wager what you have. How much?: ")) + except ValueError: + int(input("\n That's not valid! Choose a number: ")) + + class BJ_Dealer(BJ_Hand): """ A Blackjack Dealer. """ def is_hitting(self): @@ -104,8 +140,24 @@ class BJ_Game(object): def __init__(self, names): self.players = [] for name in names: + stash=100 player = BJ_Player(name) + bet=BJ_Player(name).betting(stash) + + playerbet=bet(stash).betting(stash) self.players.append(player) + + + def betting(bet,stash): + try: + if stash > 0: + wager = int(input("\nHow much do you want to wager?: ")) + if wager > stash: + int(input("\n You can only wager what you have. How much?: ")) + elif wager < 0: + int(input("\n You can only wager what you have. How much?: ")) + except ValueError: + int(input("\n That's not valid! Choose a number: ")) self.dealer = BJ_Dealer("Dealer") @@ -113,6 +165,18 @@ def __init__(self, names): self.deck.populate() self.deck.shuffle() + def populate(self): + for suit in BJ_Card.SUITS: + for rank in BJ_Card.RANKS: + self.cards.append(BJ_Card(rank, suit)) + + def gamble(bet): + if bet.stash <= 0: + print("\nYou are out of money! You're out of the game!") + + def __init__(bet, money = 10): + stash = money + @property def still_playing(self): sp = [] @@ -121,14 +185,14 @@ def still_playing(self): sp.append(player) return sp - def __additional_cards(self, player): + def __additional_cards(self, player,stash,wager): while not player.is_busted() and player.is_hitting(): self.deck.deal([player]) print(player) if player.is_busted(): - player.bust() + player.bust(self,stash,wager) - def play(self): + def play(self,stash,wager): # deal initial 2 cards to everyone self.deck.deal(self.players + [self.dealer], per_hand = 2) self.dealer.flip_first_card() # hide dealer's first card @@ -138,9 +202,9 @@ def play(self): # deal additional cards to players for player in self.players: - self.__additional_cards(player) + self.__additional_cards(player,stash,wager) - self.dealer.flip_first_card() # reveal dealer's first + self.dealer.flip_first_card() # reveal dealer's first if not self.still_playing: # since all players have busted, just show the dealer's hand @@ -148,19 +212,19 @@ def play(self): else: # deal additional cards to dealer print(self.dealer) - self.__additional_cards(self.dealer) + self.__additional_cards(self.dealer,stash,wager) if self.dealer.is_busted(): # everyone still playing wins for player in self.still_playing: - player.win() + player.win(stash,wager) else: # compare each player still playing to dealer for player in self.still_playing: if player.total > self.dealer.total: - player.win() + player.win(stash,wager) elif player.total < self.dealer.total: - player.lose() + player.lose(stash,wager) else: player.push() @@ -168,23 +232,29 @@ def play(self): for player in self.players: player.clear() self.dealer.clear() - + def main(): print("\t\tWelcome to Blackjack!\n") - + stash = 0 + wager = 0 + pari=10 names = [] - number = games.ask_number("How many players? (1 - 7): ", low = 1, high = 8) + number = games.ask_number("How many players? (1 - 7): ", low = 1, high =8) + for i in range(number): name = input("Enter player name: ") + bet=BJ_Player(name).betting(pari) names.append(name) print() - + game = BJ_Game(names) + + again = None while again != "n": - game.play() + game.play(stash,wager) again = games.ask_yes_no("\nDo you want to play again?: ") @@ -192,4 +262,3 @@ def main(): input("\n\nPress the enter key to exit.") - diff --git a/challeng2.py b/challeng2.py new file mode 100644 index 0000000..47db231 --- /dev/null +++ b/challeng2.py @@ -0,0 +1,45 @@ +import random +RANKS =["A", "2", "3", "4", "5", "6", "7", + "8", "9", "10", "J", "Q", "K"] +SUITS = ["c", "d", "h", "s"] + +Player1Counter=0 +Player2Counter=0 +print("Welcome to WAR!") +print("You and a friend will player war until one of the two of you get ten points!") +print("Before we begin, Can you please enter our names.") +Player1Name=input("Player 1 Name: ") +Player2Name=input("Player 2 Name: ") +while Player1Counter < 10 or Player2Counter < 10: + Player1CardIndex=random.randint(len(RANKS)) + Player2CardIndex=random.randint(len(RANKS)) + Player1Card=RANKS[Player1CardIndex] + Player2Card=RANKS[Player2CardIndex] + if Player1CardIndex < 9: + Player1CardIndex = 10 + if Player2CardIndex < 9: + Player2CardIndex = 10 + Player1Suit=random.choice(SUITS) + Player2Suit=random.choice(SUITS) + Player1Card =Player1Card + Player1Suit + Player2Card = Player2Card + Player2Suit + print(Player1Name,":",Player1Card) + print(Player2Name,":",Player2Card) + if Player1CardIndex < Player2CardIndex: + print(Player1Name,"has won this round and has gained one point.") + Player1Counter += 1 + elif Player1CardIndex > Player2CardIndex: + print(PlayerName,"has won this round and has gained one point.") + Player2Counter += 1 + else: + print("Oh No! No one has won this round1") + print(Player1Name,":",Player1Counter) + print(Player2Name,":",Player2Counter) + input("Please press the key.") +if Player1Counter < Player2Counter: + print(Player1Name,"has won and is the ultimate champion!") +else: + print(Player2Name,"has won and is the ulimate champion!") +print("Thanks for playing.") +input("Please press to exit.") + \ No newline at end of file diff --git a/challeng2.py~ b/challeng2.py~ new file mode 100644 index 0000000..f0437b9 --- /dev/null +++ b/challeng2.py~ @@ -0,0 +1,13 @@ +RANKS =["A", "2", "3", "4", "5", "6", "7", + "8", "9", "10", "J", "Q", "K"] +SUITS = ["c", "d", "h", "s"] + +Player1Counter=0 +Player2Counter=0 +print("Welcome to WAR!") +print("You and a friend will player war until one of the two of you get ten points!") +print("Before we begin, Can you please enter our names.") +Player1Name=input("Player 1 Name: ") +Player2Name=input("Player 2 Name: ") +while Player1Counter < 10 or Player2Counter < 10: + \ No newline at end of file