added initialize() in quartett.py
copied whole cryptpad into quartett.py
This commit is contained in:
parent
066207c546
commit
269ee73642
|
@ -4,6 +4,8 @@ __author__ = ""
|
|||
__credits__ = ""
|
||||
__email__ = ""
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def io_str(message: str, options: list) -> str:
|
||||
"""
|
||||
|
@ -14,29 +16,29 @@ def io_str(message: str, options: list) -> str:
|
|||
:param options: options is a list of viable inputs.
|
||||
:return: Cleaned user input
|
||||
"""
|
||||
pass
|
||||
# while True:
|
||||
# try:
|
||||
# i = str(input(message))
|
||||
#
|
||||
# except (ValueError, NameError):
|
||||
# i = 0
|
||||
# print("Eingabe nicht gültig, bitte wiederhole deine Eingabe.")
|
||||
#
|
||||
# if i in options:
|
||||
# return i
|
||||
#
|
||||
# else:
|
||||
# if i == "q":
|
||||
# print(
|
||||
# "---------------------\nSpiel wird beendet...\n---------------------")
|
||||
# sys.exit()
|
||||
# elif i == "r":
|
||||
# print(
|
||||
# "---------------------\nSpiel wird neu gestartet...\n---------------------")
|
||||
# game.main()
|
||||
# else:
|
||||
# print('Noch nicht ganz richtig. Hast du deine Auswahl auch richtig geschrieben?')
|
||||
|
||||
while True:
|
||||
try:
|
||||
i = str(input(message))
|
||||
|
||||
except (ValueError, NameError):
|
||||
i = 0
|
||||
print("Eingabe nicht gültig, bitte wiederhole deine Eingabe.")
|
||||
|
||||
if i in options:
|
||||
return i
|
||||
|
||||
else:
|
||||
if i == "q":
|
||||
print(
|
||||
"---------------------\nSpiel wird beendet...\n---------------------")
|
||||
sys.exit()
|
||||
elif i == "r":
|
||||
print(
|
||||
"---------------------\nSpiel wird neu gestartet...\n---------------------")
|
||||
quartett.main()
|
||||
else:
|
||||
print('Noch nicht ganz richtig. Hast du deine Auswahl auch richtig geschrieben?')
|
||||
|
||||
|
||||
def io_int(message: str) -> int:
|
||||
|
@ -47,26 +49,25 @@ def io_int(message: str) -> int:
|
|||
:param message: message needs to be a string that is printed for user instruction
|
||||
:return: Integer >1
|
||||
"""
|
||||
pass
|
||||
# while True:
|
||||
#
|
||||
# unfiltered_input = input(message)
|
||||
#
|
||||
# if unfiltered_input == "q":
|
||||
# print("---------------------\nSpiel wird beendet...\n---------------------")
|
||||
# sys.exit()
|
||||
# elif unfiltered_input == "r":
|
||||
# print(
|
||||
# "---------------------\nSpiel wird neu gestartet...\n---------------------")
|
||||
# game.main()
|
||||
#
|
||||
# try:
|
||||
# i = int(unfiltered_input)
|
||||
#
|
||||
# if i >= 1:
|
||||
# return i
|
||||
# else:
|
||||
# print('Bitte gib eine ganze Zahl größer als 0 ein. ')
|
||||
#
|
||||
# except (ValueError, NameError):
|
||||
# print("Eingabe nicht gültig, bitte wiederhole deine Eingabe.")
|
||||
while True:
|
||||
|
||||
unfiltered_input = input(message)
|
||||
|
||||
if unfiltered_input == "q":
|
||||
print("---------------------\nSpiel wird beendet...\n---------------------")
|
||||
sys.exit()
|
||||
elif unfiltered_input == "r":
|
||||
print(
|
||||
"---------------------\nSpiel wird neu gestartet...\n---------------------")
|
||||
#quartett.main()
|
||||
|
||||
try:
|
||||
i = int(unfiltered_input)
|
||||
|
||||
if i >= 1:
|
||||
return i
|
||||
else:
|
||||
print('Bitte gib eine ganze Zahl größer als 0 ein. ')
|
||||
|
||||
except (ValueError, NameError):
|
||||
print("Eingabe nicht gültig, bitte wiederhole deine Eingabe.")
|
||||
|
|
96
quartett.py
96
quartett.py
|
@ -1 +1,95 @@
|
|||
"""main module"""
|
||||
"""main module"""
|
||||
|
||||
import random
|
||||
import clean_input
|
||||
|
||||
|
||||
# Game
|
||||
|
||||
def central_function():
|
||||
''' does everything, keeps order'''
|
||||
|
||||
|
||||
active = 0 # contains index of the active player
|
||||
|
||||
..., players_with_cards, players = initialize()[0], initialize()[1], initialize()[2]
|
||||
while deckP1 and deckP2 and deckP3 not empty:
|
||||
round(..., players_with_cards, players)
|
||||
# rotate_active_player
|
||||
|
||||
|
||||
def round(..., players_with_cards, players):
|
||||
'''structures one round in the game'''
|
||||
|
||||
|
||||
while player_request in deck_of_player:
|
||||
choose(..., players_with_cards, players)
|
||||
|
||||
|
||||
def choose(..., players_with_cards, players):
|
||||
"""active player chooses another player from whom to steal a card"""
|
||||
|
||||
|
||||
players_without_active = players.pop(active_player)
|
||||
print('Folgende Spieler stehen zur Verfügung:')
|
||||
print(players_without_active)
|
||||
chosen_player = players.index(input(
|
||||
'Welchen Spieler möchtest du befragen?')) # needs clean.io, chosen_player enthält den index in der players liste
|
||||
player_request = input('Welche Karte möchtest du haben?') # TO DO needs clean.io dict magic
|
||||
|
||||
if player_request in players_with_cards[chosen_player]['cards_on_hand']:
|
||||
steal(P1, P2)
|
||||
else:
|
||||
# end of round
|
||||
if stack == exists:
|
||||
# TO DO player.values + card_from_stack
|
||||
break
|
||||
|
||||
|
||||
def steal(P1, P2):
|
||||
"""defines how the active players steals cards from chosen player """
|
||||
|
||||
|
||||
def initialize():
|
||||
"""
|
||||
initializes stuff
|
||||
:return:
|
||||
"""
|
||||
|
||||
card_deck = []
|
||||
players = []
|
||||
players_with_cards = []
|
||||
|
||||
x = 0
|
||||
for i in range(4):
|
||||
for l in "abcdefgh":
|
||||
d = {"id": x, "number": i, "letter": l}
|
||||
card_deck.append(d)
|
||||
x += 1
|
||||
|
||||
number_of_players = clean_input.io_int("Mit wie vielen Spielern wollen Sie spielen?")
|
||||
number_of_players += 1 # Add also human player.
|
||||
|
||||
for i in range(number_of_players):
|
||||
players.append(f"player{i}")
|
||||
|
||||
if len(players) == 2:
|
||||
cards_per_player = 10
|
||||
else:
|
||||
cards_per_player = int(len(card_deck) // len(players))
|
||||
|
||||
for i in range(number_of_players): # Select cards for x players
|
||||
cards_of_player = [] # Player deck
|
||||
for j in range(cards_per_player): # Select ten cards
|
||||
x = random.randint(0, len(card_deck) - 1) # Select one random card
|
||||
selected_card = card_deck[x]
|
||||
del card_deck[x] # Remove card from main card deck.
|
||||
cards_of_player.append(selected_card)
|
||||
|
||||
# Add list of dicts (cards) to players
|
||||
players_with_cards.append({"player": players[i], "cards_on_hand": cards_of_player})
|
||||
|
||||
# print(len(card_deck))
|
||||
# print(players_with_cards)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue