Untitled
unknown
python
2 years ago
2.8 kB
3
Indexable
Never
""" Combo Breaker Card Game 1 - The game consist 30 cards, 0-9 numbers and Red, Green and Blue color 2 - Each player gets 3 cards 3 - Each game consist of some number of players, and winners are determined by who has the best Combo: 3.1 Color Combo (3 same color) [3 points] 3.2 Value Combo (3 same value) [2 points] 3.3 Pair Combo (2 same value + random) [1 point] 3.4 etc not important [0 points] 4. Write the library required to play this game. Don't worry about UI or getters / setters / constructors or implementing methods, just draw out what ou need and who will call what. """ import random import heapq rgb = "RGB" # str[0]:R, str[1]:G, str[2]:B #print(rgb[0], rgb[1], rgb[2]) class Card: value = None color = None def __init__(self): self.value = random.randint(0, 9) print("Card val: ", self.value) self.color = rgb[random.randint(0, 2)] print("Card col: ", self.color) class Player: cards = [] name = None def __init__(self, name): if PM_flag == "y": self.cards.append(Card()) self.cards.append(Card()) self.name = name print("Player:", self.name) else: self.cards.append(Card()) self.cards.append(Card()) self.cards.append(Card()) self.name = name print("Player:", self.name) def __repr__(self): return "Player numer:" + str(self.name) # Adding new players print("How many players?: ") player_counter = int(input()) players = [] print("Crazy Combo Breaker? [y] for yes: ") CCB_flag = input() print("Party Mode? [y] for yes: ") PM_flag = input() for i in range(player_counter): players.append(Player(i)) #print("I added: ", i, "Player") if PM_flag == "y": all_card = Card() for player in players: player.cards.append(all_card) Scoreboard = [] Winners = {} def Score(player): if player.cards[0].color == player.cards[1].color == player.cards[2].color == "R": return 5 # Red Sun Combo elif player.cards[0].color == player.cards[1].color == player.cards[2].color: return 4 # Color Combo elif player.cards[0].color == player.cards[1].color or player.cards[0].color == player.cards[2].color or player.cards[1].color == player.cards[2].color: return 3 # Two of the Kind elif player.cards[0].value == player.cards[1].value == player.cards[2].value: return 2 # Value Combo elif player.cards[0].value == player.cards[1].value or player.cards[0].value == player.cards[2].value or player.cards[1].value == player.cards[2].value: return 1 # Pair Combo else: return 0 # No combo for player in players: if CCB_flag == "y": Scoreboard.append(-1 * Score(player)) else: Scoreboard.append(Score(player)) Winners = Winners.fromkeys(Scoreboard, players) print("Winners: ", Winners[max(Winners.keys())], "With score: ", max(Winners.keys()))