Created
March 28, 2018 03:17
-
-
Save calthoff/47bba0ad04f814178df0bc079a349eae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Game: | |
| def __init__(self): | |
| name1 = input("p1 name ") | |
| name2 = input("p2 name ") | |
| self.deck = Deck() | |
| self.p1 = Player(name1) | |
| self.p2 = Player(name2) | |
| def wins(self, winner): | |
| w = "{} wins this round" | |
| w = w.format(winner) | |
| print(w) | |
| def draw(self, p1n, p1c, p2n, p2c): | |
| d = "{} drew {} {} drew {}" | |
| d = d.format(p1n, p1c, p2n, p2c) | |
| print(d) | |
| def play_game(self): | |
| cards = self.deck.cards | |
| print("beginning War!") | |
| while len(cards) >= 2: | |
| m = "q to quit. Any " + "key to play:" | |
| response = input(m) | |
| if response == 'q': | |
| break | |
| p1c = self.deck.rm_card() | |
| p2c = self.deck.rm_card() | |
| p1n = self.p1.name | |
| p2n = self.p2.name | |
| self.draw(p1n, p1c, p2n, p2c) | |
| if p1c > p2c: | |
| self.p1.wins += 1 | |
| self.wins(self.p1.name) | |
| else: | |
| self.p2.wins += 1 | |
| self.wins(self.p2.name) | |
| win = self.winner(self.p1, self.p2) | |
| print("War is over.{} wins".format(win)) | |
| def winner(self, p1, p2): | |
| if p1.wins > p2.wins: | |
| return p1.name | |
| if p1.wins < p2.wins: | |
| return p2.name | |
| return "It was a tie!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment