edited print calls to show "Du" for human player, first addition of time.sleep()

This commit is contained in:
Steinadler 2021-01-14 11:15:16 +01:00
parent 81b1cd3cd8
commit 8277c96938
1 changed files with 56 additions and 12 deletions

View File

@ -6,8 +6,11 @@ __email__ = ""
import random
import copy
import time
import clean_input
total_time = 1
def central_function():
"""
@ -28,11 +31,19 @@ def central_function():
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:
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
switch = bool(players_with_cards[i]['cards_on_hand'])
if not bool(players_with_cards[i]['cards_on_hand']):
switch = False
active += 1
if active >= len(players):
@ -80,11 +91,18 @@ def round(card_stack, players_with_cards, players, active, complete_card_stack,
else:
print("Diese Karte hat der Spieler nicht. Der nächste Spieler ist dran...")
time.sleep(total_time)
# end of round
# except if stack is not empty, which is not only the case with two players
if card_stack:
# 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
@ -103,23 +121,36 @@ def round(card_stack, players_with_cards, players, active, complete_card_stack,
# select card
player_request = random.choice(cards_to_choose_from)
print(
f"{players[active]} fragt {players[chosen_player]} nach "
f"der Karte {player_request}.")
if players[chosen_player] == "player0":
print(
f"{players[active]} fragt dich nach "
f"der Karte {player_request['number']}{player_request['letter']}.")
else:
print(
f"{players[active]} fragt {players[chosen_player]} nach "
f"der Karte {player_request['number']}{player_request['letter']}.")
if player_request in players_with_cards[chosen_player]['cards_on_hand']:
steal(active, chosen_player, players_with_cards, player_request)
drop_cards(players_with_cards, all_quartets, active)
else:
print(
f"{players[chosen_player]} hat die Karte {player_request} nicht. "
f"Der nächste Spieler ist dran...")
if players[chosen_player] == "player0":
print(f"Du hast die Karte {player_request['number']}{player_request['letter']}"
f" nicht. "
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
# except if stack is not empty, which is not only the case with two players
if card_stack:
# last card from the stack gets added to active player's hand
players_with_cards[active]['cards_on_hand'].append(card_stack.pop())
drop_cards(players_with_cards, all_quartets, active)
switch = False
@ -159,8 +190,13 @@ def steal(active, chosen_player, players_with_cards, player_request):
print(f"player{chosen_player} hat die Karte, die du "
"haben möchtest und sie wandert in dein Deck.")
else:
print(f"player{chosen_player} hat die Karte, die player{active} "
"haben möchte und sie wandert in sein Deck.")
if chosen_player == 0:
print(f"Du hast die Karte, die player{active} "
"haben möchte und sie wandert in sein Deck.")
else:
print(f"player{chosen_player} hat die Karte, die player{active} "
"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)
players_with_cards[active]['cards_on_hand'].append(
players_with_cards[chosen_player]['cards_on_hand'].pop(card_index))
@ -207,7 +243,11 @@ def drop_cards_help(p, all_quartets):
quartet_letter = reference[counter.index(i)]
counter[counter.index(i)] = 0
p["quartet"] += 1
print(f"{p['player']} legt das {quartet_letter}-Quartett ab...")
if p["player"] == "player0":
print(f"Du legst das {quartet_letter}-Quartett ab...")
else:
print(f"{p['player']} legt das {quartet_letter}-Quartett ab...")
# build list of cards that are now dropped
q = [c for c in p["cards_on_hand"] if quartet_letter == c["letter"]]
@ -304,7 +344,11 @@ def the_winner_is(players_with_cards, players):
# to print all the players' names who have won
for i in range(len(winners)):
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