edited print calls to show "Du" for human player, first addition of time.sleep()
This commit is contained in:
parent
81b1cd3cd8
commit
8277c96938
56
quartett.py
56
quartett.py
|
@ -6,8 +6,11 @@ __email__ = ""
|
||||||
|
|
||||||
import random
|
import random
|
||||||
import copy
|
import copy
|
||||||
|
import time
|
||||||
import clean_input
|
import clean_input
|
||||||
|
|
||||||
|
total_time = 1
|
||||||
|
|
||||||
|
|
||||||
def central_function():
|
def central_function():
|
||||||
"""
|
"""
|
||||||
|
@ -28,11 +31,19 @@ def central_function():
|
||||||
|
|
||||||
drop_cards(players_with_cards, all_quartets)
|
drop_cards(players_with_cards, all_quartets)
|
||||||
|
|
||||||
|
if active == 0:
|
||||||
|
print("Du bist als erstes dran!")
|
||||||
|
else:
|
||||||
|
print(f"{players[active]} ist als erstes dran.")
|
||||||
|
|
||||||
|
time.sleep(total_time)
|
||||||
|
|
||||||
while switch:
|
while switch:
|
||||||
round(card_stack, players_with_cards, players, active, complete_card_stack, all_quartets)
|
round(card_stack, players_with_cards, players, active, complete_card_stack, all_quartets)
|
||||||
|
|
||||||
for i in range(len(players)): # check if any card deck is empty
|
for i in range(len(players)): # check if any card deck is empty
|
||||||
switch = bool(players_with_cards[i]['cards_on_hand'])
|
if not bool(players_with_cards[i]['cards_on_hand']):
|
||||||
|
switch = False
|
||||||
|
|
||||||
active += 1
|
active += 1
|
||||||
if active >= len(players):
|
if active >= len(players):
|
||||||
|
@ -80,11 +91,18 @@ def round(card_stack, players_with_cards, players, active, complete_card_stack,
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Diese Karte hat der Spieler nicht. Der nächste Spieler ist dran...")
|
print("Diese Karte hat der Spieler nicht. Der nächste Spieler ist dran...")
|
||||||
|
time.sleep(total_time)
|
||||||
# end of round
|
# end of round
|
||||||
# except if stack is not empty, which is not only the case with two players
|
# except if stack is not empty, which is not only the case with two players
|
||||||
if card_stack:
|
if card_stack:
|
||||||
# last card from the stack gets added to active player's hand
|
# last card from the stack gets added to active player's hand
|
||||||
players_with_cards[active]['cards_on_hand'].append(card_stack.pop())
|
draw_card = card_stack.pop()
|
||||||
|
print(f"Du ziehst die Karte {draw_card['number']}{draw_card['letter']}"
|
||||||
|
f" vom Stapel.")
|
||||||
|
players_with_cards[active]['cards_on_hand'].append(draw_card)
|
||||||
|
drop_cards(players_with_cards, all_quartets, active)
|
||||||
|
time.sleep(total_time)
|
||||||
|
|
||||||
|
|
||||||
switch = False
|
switch = False
|
||||||
|
|
||||||
|
@ -103,23 +121,36 @@ def round(card_stack, players_with_cards, players, active, complete_card_stack,
|
||||||
# select card
|
# select card
|
||||||
player_request = random.choice(cards_to_choose_from)
|
player_request = random.choice(cards_to_choose_from)
|
||||||
|
|
||||||
|
if players[chosen_player] == "player0":
|
||||||
|
print(
|
||||||
|
f"{players[active]} fragt dich nach "
|
||||||
|
f"der Karte {player_request['number']}{player_request['letter']}.")
|
||||||
|
else:
|
||||||
print(
|
print(
|
||||||
f"{players[active]} fragt {players[chosen_player]} nach "
|
f"{players[active]} fragt {players[chosen_player]} nach "
|
||||||
f"der Karte {player_request}.")
|
f"der Karte {player_request['number']}{player_request['letter']}.")
|
||||||
|
|
||||||
if player_request in players_with_cards[chosen_player]['cards_on_hand']:
|
if player_request in players_with_cards[chosen_player]['cards_on_hand']:
|
||||||
steal(active, chosen_player, players_with_cards, player_request)
|
steal(active, chosen_player, players_with_cards, player_request)
|
||||||
drop_cards(players_with_cards, all_quartets, active)
|
drop_cards(players_with_cards, all_quartets, active)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(
|
if players[chosen_player] == "player0":
|
||||||
f"{players[chosen_player]} hat die Karte {player_request} nicht. "
|
print(f"Du hast die Karte {player_request['number']}{player_request['letter']}"
|
||||||
|
f" nicht. "
|
||||||
f"Der nächste Spieler ist dran...")
|
f"Der nächste Spieler ist dran...")
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
f"{players[chosen_player]} hat die Karte "
|
||||||
|
f"{player_request['number']}{player_request['letter']} nicht. "
|
||||||
|
f"Der nächste Spieler ist dran...")
|
||||||
|
time.sleep(total_time)
|
||||||
# end of round
|
# end of round
|
||||||
# except if stack is not empty, which is not only the case with two players
|
# except if stack is not empty, which is not only the case with two players
|
||||||
if card_stack:
|
if card_stack:
|
||||||
# last card from the stack gets added to active player's hand
|
# last card from the stack gets added to active player's hand
|
||||||
players_with_cards[active]['cards_on_hand'].append(card_stack.pop())
|
players_with_cards[active]['cards_on_hand'].append(card_stack.pop())
|
||||||
|
drop_cards(players_with_cards, all_quartets, active)
|
||||||
|
|
||||||
switch = False
|
switch = False
|
||||||
|
|
||||||
|
@ -158,9 +189,14 @@ def steal(active, chosen_player, players_with_cards, player_request):
|
||||||
if active == 0:
|
if active == 0:
|
||||||
print(f"player{chosen_player} hat die Karte, die du "
|
print(f"player{chosen_player} hat die Karte, die du "
|
||||||
"haben möchtest und sie wandert in dein Deck.")
|
"haben möchtest und sie wandert in dein Deck.")
|
||||||
|
else:
|
||||||
|
if chosen_player == 0:
|
||||||
|
print(f"Du hast die Karte, die player{active} "
|
||||||
|
"haben möchte und sie wandert in sein Deck.")
|
||||||
else:
|
else:
|
||||||
print(f"player{chosen_player} hat die Karte, die player{active} "
|
print(f"player{chosen_player} hat die Karte, die player{active} "
|
||||||
"haben möchte und sie wandert in sein Deck.")
|
"haben möchte und sie wandert in sein Deck.")
|
||||||
|
time.sleep(total_time)
|
||||||
card_index = players_with_cards[chosen_player]['cards_on_hand'].index(player_request)
|
card_index = players_with_cards[chosen_player]['cards_on_hand'].index(player_request)
|
||||||
players_with_cards[active]['cards_on_hand'].append(
|
players_with_cards[active]['cards_on_hand'].append(
|
||||||
players_with_cards[chosen_player]['cards_on_hand'].pop(card_index))
|
players_with_cards[chosen_player]['cards_on_hand'].pop(card_index))
|
||||||
|
@ -207,6 +243,10 @@ def drop_cards_help(p, all_quartets):
|
||||||
quartet_letter = reference[counter.index(i)]
|
quartet_letter = reference[counter.index(i)]
|
||||||
counter[counter.index(i)] = 0
|
counter[counter.index(i)] = 0
|
||||||
p["quartet"] += 1
|
p["quartet"] += 1
|
||||||
|
|
||||||
|
if p["player"] == "player0":
|
||||||
|
print(f"Du legst das {quartet_letter}-Quartett ab...")
|
||||||
|
else:
|
||||||
print(f"{p['player']} legt das {quartet_letter}-Quartett ab...")
|
print(f"{p['player']} legt das {quartet_letter}-Quartett ab...")
|
||||||
|
|
||||||
# build list of cards that are now dropped
|
# build list of cards that are now dropped
|
||||||
|
@ -304,7 +344,11 @@ def the_winner_is(players_with_cards, players):
|
||||||
# to print all the players' names who have won
|
# to print all the players' names who have won
|
||||||
for i in range(len(winners)):
|
for i in range(len(winners)):
|
||||||
if winners[i] == temp:
|
if winners[i] == temp:
|
||||||
print(players[i], "has won the game!")
|
print(f"{players[i]} hat das Spiel gewonnen!")
|
||||||
|
|
||||||
|
clean_input.io_str("Möchten Sie das Spiel beenden oder ein neues Spiel starten?"
|
||||||
|
"Drücken Sie 'q' zum Beenden oder 'r',"
|
||||||
|
"um ein neues Spiel zu starten...", [])
|
||||||
|
|
||||||
|
|
||||||
# Call central_function() only if quartett.py is the main module
|
# Call central_function() only if quartett.py is the main module
|
||||||
|
|
Loading…
Reference in New Issue
Block a user