-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
113 additions
and
106 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
class Symbol: | ||
'''A class to store the card symbols: icons and colors''' | ||
|
||
def __init__(self, color, icon): | ||
'''Initialize a symbol and set its icon and color.''' | ||
|
||
self.icon = icon | ||
self.color = color | ||
|
||
def __str__(self): | ||
'''Return a symbol which consists of an icon and a color.''' | ||
return f"{self.color}, {self.icon}" | ||
"""A class to store the card symbols: icons and colors""" | ||
|
||
class Card(Symbol): | ||
'''A class to create a card. This class inherits icon and color from the Symbol class and adds a value.''' | ||
def __init__(self, color, icon): | ||
"""Initialize a symbol and set its icon and color.""" | ||
|
||
self.icon = icon | ||
self.color = color | ||
|
||
def __init__(self, color, icon, value): | ||
super().__init__(color, icon) | ||
'''Initialize a card that inherits an icon and a color from Symbol and set its value.''' | ||
self.value = value | ||
|
||
def __str__(self): | ||
"""Return a symbol which consists of an icon and a color.""" | ||
return f"{self.color}, {self.icon}" | ||
|
||
def __str__(self): | ||
'''Return a card which consists of an icon, a color and a value.''' | ||
return f"{self.color}, {self.icon}, {self.value}" | ||
|
||
def create_list_of_cards(self): | ||
'''Creates a list with 4 cards''' | ||
class Card(Symbol): | ||
"""A class to create a card. This class inherits icon and color from the Symbol class and adds a value.""" | ||
|
||
def __init__(self, color, icon, value): | ||
super().__init__(color, icon) | ||
"""Initialize a card that inherits an icon and a color from Symbol and set its value.""" | ||
self.value = value | ||
|
||
def __str__(self): | ||
"""Return a card which consists of an icon, a color and a value.""" | ||
return f"{self.color}, {self.icon}, {self.value}" | ||
|
||
def create_list_of_cards(self): | ||
"""Creates a list with 4 cards""" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
from utils.card import Card | ||
from utils.player import Player, Deck | ||
#from card import Card | ||
#from player import Player, Deck | ||
|
||
# from card import Card | ||
# from player import Player, Deck | ||
|
||
|
||
class Board: | ||
'''A class to stores a board''' | ||
def __init__(self, players : list): | ||
self.players = players | ||
self.turn_count = 0 | ||
self.active_cards = [] | ||
self.history_cards = [] | ||
"""A class to stores a board""" | ||
|
||
def __init__(self, players: list): | ||
self.players = players | ||
self.turn_count = 0 | ||
self.active_cards = [] | ||
self.history_cards = [] | ||
|
||
def start_game(self): | ||
''' | ||
Starts the game, fills a Deck, distributes cards of the Deck to the players. | ||
''' | ||
print('The game has started.') | ||
deck = Deck() | ||
deck.fill_deck() | ||
deck.shuffle() | ||
deck.distribute(self.players) | ||
def start_game(self): | ||
""" | ||
Starts the game, fills a Deck, distributes cards of the Deck to the players. | ||
""" | ||
print("The game has started.") | ||
deck = Deck() | ||
deck.fill_deck() | ||
deck.shuffle() | ||
deck.distribute(self.players) | ||
|
||
while self.turn_count < 26: | ||
self.turn_count += 1 | ||
print(f"Starting turn {self.turn_count}") | ||
for player in self.players: | ||
card = player.play(self.turn_count) | ||
self.history_cards.append(card) | ||
self.active_cards.append(card) | ||
while self.turn_count < 26: | ||
self.turn_count += 1 | ||
print(f"Starting turn {self.turn_count}") | ||
for player in self.players: | ||
card = player.play(self.turn_count) | ||
self.history_cards.append(card) | ||
self.active_cards.append(card) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,69 @@ | ||
from random import shuffle | ||
|
||
from utils.card import Card | ||
#from card import Card | ||
|
||
# from card import Card | ||
|
||
|
||
class Player: | ||
'''A class to manage a player''' | ||
def __init__(self, name: str): | ||
self.name = name | ||
self.cards = [] #cards assigned | ||
self.number_of_cards = 0 | ||
self.history = [] #what cards were assigned to the player | ||
"""A class to manage a player""" | ||
|
||
def __str__(self): | ||
return self.name | ||
def __init__(self, name: str): | ||
self.name = name | ||
self.cards = [] # cards assigned | ||
self.number_of_cards = 0 | ||
self.history = [] # what cards were assigned to the player | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
def play(self, turn_count : int): | ||
'''Player picks a card in cards.''' | ||
shuffle(self.cards) | ||
card = self.cards.pop() | ||
self.history.append(card) | ||
print(f"{self.name} in turn {turn_count} played: {card}") | ||
return card | ||
def play(self, turn_count: int): | ||
"""Player picks a card in cards.""" | ||
shuffle(self.cards) | ||
card = self.cards.pop() | ||
self.history.append(card) | ||
print(f"{self.name} in turn {turn_count} played: {card}") | ||
return card | ||
|
||
class Deck: | ||
'''A class to store a deck of cards.''' | ||
def __init__(self): | ||
''' Initialize a deck of cards''' | ||
self.cards = [] | ||
self.players = [] | ||
|
||
def fill_deck(self): | ||
icons = ["Club", "Heart", "Diamond", "Spade"] | ||
values = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"] | ||
for icon in icons: | ||
if icon == "Heart" or icon =="Diamond": | ||
color = "red" | ||
else: | ||
color = "black" | ||
for value in values: | ||
self.cards.append(Card(color, icon, value)) | ||
class Deck: | ||
"""A class to store a deck of cards.""" | ||
|
||
def __init__(self): | ||
"""Initialize a deck of cards""" | ||
self.cards = [] | ||
self.players = [] | ||
|
||
def __str__(self): | ||
'''Shows a deck of cards''' | ||
string_of_cards = '' | ||
for element in self.cards: | ||
string_of_cards += element.__str__() + " " | ||
return string_of_cards | ||
def fill_deck(self): | ||
icons = ["Club", "Heart", "Diamond", "Spade"] | ||
values = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"] | ||
for icon in icons: | ||
if icon == "Heart" or icon == "Diamond": | ||
color = "red" | ||
else: | ||
color = "black" | ||
for value in values: | ||
self.cards.append(Card(color, icon, value)) | ||
|
||
def shuffle(self): | ||
''' Shuffles all cards in the list of cards. ''' | ||
shuffle(self.cards) | ||
print("The deck has been shuffled.") | ||
def __str__(self): | ||
"""Shows a deck of cards""" | ||
string_of_cards = "" | ||
for element in self.cards: | ||
string_of_cards += element.__str__() + " " | ||
return string_of_cards | ||
|
||
def distribute(self, players: list): | ||
''' | ||
Takes a list of players as a parameter and distributes the cards evenly between all the players. | ||
''' | ||
while len(self.cards) > 0: | ||
for player in players: | ||
if len(self.cards) > 0: | ||
card = self.cards.pop() | ||
player.cards.append(card) | ||
print('Cards have been distributed.') # move to game | ||
def shuffle(self): | ||
"""Shuffles all cards in the list of cards.""" | ||
shuffle(self.cards) | ||
print("The deck has been shuffled.") | ||
|
||
def distribute(self, players: list): | ||
""" | ||
Takes a list of players as a parameter and distributes the cards evenly between all the players. | ||
""" | ||
while len(self.cards) > 0: | ||
for player in players: | ||
if len(self.cards) > 0: | ||
card = self.cards.pop() | ||
player.cards.append(card) | ||
print("Cards have been distributed.") # move to game |