91 lines
2.0 KiB
Python
91 lines
2.0 KiB
Python
import time
|
|
import random
|
|
|
|
|
|
# Karten: 1-13 in Blau, Rot, Gelb, Gruen und 4xZ und 4xN
|
|
|
|
|
|
def chunks(lst, n):
|
|
"""Yield successive n-sized chunks from lst."""
|
|
for i in range(0, len(lst), n):
|
|
yield lst[i:i + n]
|
|
|
|
|
|
class Card:
|
|
def __init__(self, color, value):
|
|
self.color = color
|
|
self.value = value
|
|
|
|
def __str__(self):
|
|
sc = self.color if self.color else ' '
|
|
sv = str(self.value)
|
|
return sc+' '+sv
|
|
|
|
def __repr__(self):
|
|
return str(self)
|
|
|
|
class Player:
|
|
def __init__(self, name, player_id):
|
|
self.name = name
|
|
self.id = player_id
|
|
self.cards = []
|
|
|
|
def deal_cards(self, cards):
|
|
self.cards = cards
|
|
|
|
def show_cards(self):
|
|
print(self.cards)
|
|
|
|
|
|
class WizGame:
|
|
def __init__(self):
|
|
self.players = []
|
|
self.card_deck = []
|
|
|
|
def create_deck(self):
|
|
for color in ["blue", "red", "green", "yellow"]:
|
|
for val in range(1,14):
|
|
self.card_deck.append(Card(color, val))
|
|
for _ in range(1,5):
|
|
self.card_deck.append(Card(None, 'Z'))
|
|
for _ in range(1,5):
|
|
self.card_deck.append(Card(None, 'N'))
|
|
print("carddeck:")
|
|
print(self.card_deck)
|
|
|
|
def deal_cards(self):
|
|
random.shuffle(self.card_deck)
|
|
num_cards = int(len(self.card_deck)/len(self.players))
|
|
print(num_cards)
|
|
cs = list(chunks(self.card_deck, num_cards))
|
|
for i in range(len(self.players)):
|
|
self.players[i].deal_cards(cs[i])
|
|
self.players[i].show_cards()
|
|
|
|
def add_player(self, name: str, player_id):
|
|
if len(self.players) < 6:
|
|
self.players.append((Player(name, player_id)))
|
|
|
|
|
|
|
|
def main():
|
|
print("main started")
|
|
w = WizGame()
|
|
w.create_deck()
|
|
w.add_player("p1", 1)
|
|
w.add_player("p2", 2)
|
|
w.add_player("p3", 3)
|
|
w.add_player("p4", 4)
|
|
w.deal_cards()
|
|
print("round 2")
|
|
w.deal_cards()
|
|
print("round 3")
|
|
w.deal_cards()
|
|
print("round 4")
|
|
w.deal_cards()
|
|
exit(0)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|