V 1.0
This commit is contained in:
parent
8ec1091199
commit
30389951b0
|
@ -15,7 +15,6 @@ def io_str(message: str, options: list) -> str:
|
||||||
|
|
||||||
if i in options:
|
if i in options:
|
||||||
return i
|
return i
|
||||||
break
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if i == "q":
|
if i == "q":
|
||||||
|
@ -35,17 +34,15 @@ def io_int(message: str) -> int:
|
||||||
if unfiltered_input == "q":
|
if unfiltered_input == "q":
|
||||||
print("--------------------------\nSpiel wird beendet...\n--------------------------")
|
print("--------------------------\nSpiel wird beendet...\n--------------------------")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
#elif unfiltered_input == "r":
|
elif unfiltered_input == "r":
|
||||||
#print("--------------------------\nSpiel wird neu gestartet...\n--------------------------")
|
print("--------------------------\nSpiel wird neu gestartet...\n--------------------------")
|
||||||
#game.main() #DAS FUNKTIONIERT NOCH NICHT
|
game.main() # DOCH TUT ES
|
||||||
|
|
||||||
try:
|
try:
|
||||||
i = int(unfiltered_input)
|
i = int(unfiltered_input)
|
||||||
|
|
||||||
if i >= 1:
|
if i >= 1:
|
||||||
return i
|
return i
|
||||||
print("deine Zahl ist", i)
|
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
print('Bitte gib eine ganze Zahl größer als 0 ein. ')
|
print('Bitte gib eine ganze Zahl größer als 0 ein. ')
|
||||||
|
|
||||||
|
@ -55,5 +52,5 @@ def io_int(message: str) -> int:
|
||||||
|
|
||||||
|
|
||||||
#testing
|
#testing
|
||||||
io_int("Bitte gib eine Zahl ein.")
|
#io_int("Bitte gib eine Zahl ein.")
|
||||||
|
|
||||||
|
|
68
game.py
68
game.py
|
@ -1,14 +1,21 @@
|
||||||
"""game"""
|
"""This is the main module of the game 16-is-dead.
|
||||||
|
Main functionality and calculations are handled here.
|
||||||
|
"""
|
||||||
|
|
||||||
|
__author__ = ""
|
||||||
|
__credits__ = ""
|
||||||
|
__email__ = ""
|
||||||
|
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
# import user_interface.user_interface as ui
|
import sys
|
||||||
import clean_input as ci
|
import user_interface as ui
|
||||||
|
import clean_input
|
||||||
|
|
||||||
|
|
||||||
def check_special_score(score, p):
|
def check_special_score(score, p):
|
||||||
"""
|
"""
|
||||||
Checks if player of AI have a score of 9, 10 or >=16.
|
Checks if player or AI have a score of 9, 10 or >=16.
|
||||||
If a score is >=16, 'restart' gets returned and the game
|
If a score is >=16, 'restart' gets returned and the game
|
||||||
is immediately over.
|
is immediately over.
|
||||||
Otherwise the score is returned.
|
Otherwise the score is returned.
|
||||||
|
@ -27,9 +34,11 @@ def check_special_score(score, p):
|
||||||
print("Sie haben 10 erreicht. Noch ein letzter Wurf...")
|
print("Sie haben 10 erreicht. Noch ein letzter Wurf...")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
r = roll_dice()
|
r = roll_dice()
|
||||||
|
ui.dice_animation()
|
||||||
|
ui.pling(r)
|
||||||
print(f"Sie würfeln {r}.")
|
print(f"Sie würfeln {r}.")
|
||||||
if score + sum(r) == 16:
|
if score + sum(r) == 16:
|
||||||
print(f"Sie haben insgesamt {score} gewürfelt und damit verloren.\n")
|
print(f"Sie haben insgesamt {score + sum(r)} gewürfelt und damit verloren.\n")
|
||||||
return False, "restart"
|
return False, "restart"
|
||||||
return True, score + sum(r)
|
return True, score + sum(r)
|
||||||
elif score >= 16 and p[1]: # player has too much
|
elif score >= 16 and p[1]: # player has too much
|
||||||
|
@ -72,16 +81,19 @@ def choose_loser(all_results):
|
||||||
if r["final_score"] == loser_score:
|
if r["final_score"] == loser_score:
|
||||||
losers.append(r["player"])
|
losers.append(r["player"])
|
||||||
|
|
||||||
loser_string = "Die folgenden Spieler haben verloren: "
|
loser_string = "\nDie folgenden Spieler haben verloren: "
|
||||||
losers = ",".join(losers)
|
losers = ",".join(losers)
|
||||||
loser_string = loser_string + losers
|
loser_string = loser_string + losers
|
||||||
|
|
||||||
print(loser_string)
|
print(loser_string)
|
||||||
|
|
||||||
main()
|
ui.the_end()
|
||||||
|
|
||||||
|
clean_input.io_str("Wollen Sie noch eine Runde spielen? Drücken Sie 'r'"
|
||||||
|
" für eine neue Runde oder 'q' zum Beenden. ", [])
|
||||||
|
|
||||||
|
|
||||||
def roll_dice(number=1, faces=6, seed=None):
|
def roll_dice(number=1, faces=6, seed=3.8):
|
||||||
"""
|
"""
|
||||||
Throws a certain number of dice with a certain number of faces.
|
Throws a certain number of dice with a certain number of faces.
|
||||||
|
|
||||||
|
@ -96,7 +108,6 @@ def roll_dice(number=1, faces=6, seed=None):
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
for n in range(number):
|
for n in range(number):
|
||||||
# ui.dice_animation()
|
|
||||||
result = random.randint(1, faces)
|
result = random.randint(1, faces)
|
||||||
results.append(result)
|
results.append(result)
|
||||||
|
|
||||||
|
@ -117,11 +128,13 @@ def sixteen_is_dead(players):
|
||||||
for p in players:
|
for p in players:
|
||||||
|
|
||||||
if p[1]: # human player
|
if p[1]: # human player
|
||||||
button = input("Sie sind an der Reihe!")
|
button = clean_input.io_str("Sie sind an der Reihe!", ["", "n"])
|
||||||
player_score = 0
|
player_score = 0
|
||||||
|
|
||||||
while button != "n":
|
while button != "n":
|
||||||
current_roll = roll_dice()
|
current_roll = roll_dice()
|
||||||
|
ui.dice_animation()
|
||||||
|
ui.pling(current_roll)
|
||||||
print("Sie haben " + str(current_roll) + " gewürfelt!")
|
print("Sie haben " + str(current_roll) + " gewürfelt!")
|
||||||
|
|
||||||
player_score += sum(current_roll)
|
player_score += sum(current_roll)
|
||||||
|
@ -133,25 +146,25 @@ def sixteen_is_dead(players):
|
||||||
|
|
||||||
print("Damit haben Sie insgesamt " + str(player_score) + " gewürfelt.")
|
print("Damit haben Sie insgesamt " + str(player_score) + " gewürfelt.")
|
||||||
|
|
||||||
# if player_score >= 16:
|
|
||||||
# print("Sie haben verloren!")
|
|
||||||
# sys.exit()
|
|
||||||
|
|
||||||
if button:
|
if button:
|
||||||
break
|
break
|
||||||
|
|
||||||
button = ci.io("Wollen Sie weiterwürfeln? ",["", "n"])
|
button = clean_input.io_str("Wollen Sie weiterwürfeln? ", ["", "n"])
|
||||||
# button = input("Wollen Sie weiterwürfeln?")
|
|
||||||
|
|
||||||
all_results.append({"player": p[0], "final_score": player_score})
|
all_results.append({"player": p[0], "final_score": player_score})
|
||||||
|
|
||||||
else: # AI
|
else: # AI
|
||||||
|
print("Nächster Spieler...")
|
||||||
ai_score = 0
|
ai_score = 0
|
||||||
|
|
||||||
|
time.sleep(1.5)
|
||||||
|
|
||||||
while ai_score < 13: # roll until score at least 12
|
while ai_score < 13: # roll until score at least 12
|
||||||
current_roll = roll_dice()
|
current_roll = roll_dice()
|
||||||
print(f"{p[0]} würfelt {current_roll}.")
|
print(f"{p[0]} würfelt {current_roll}.")
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
ai_score += sum(current_roll)
|
ai_score += sum(current_roll)
|
||||||
|
|
||||||
button, ai_score = check_special_score(ai_score, p)
|
button, ai_score = check_special_score(ai_score, p)
|
||||||
|
@ -165,8 +178,8 @@ def sixteen_is_dead(players):
|
||||||
break
|
break
|
||||||
|
|
||||||
all_results.append({"player": p[0], "final_score": ai_score})
|
all_results.append({"player": p[0], "final_score": ai_score})
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(all_results)
|
|
||||||
choose_loser(all_results)
|
choose_loser(all_results)
|
||||||
|
|
||||||
|
|
||||||
|
@ -179,23 +192,26 @@ def main():
|
||||||
"""
|
"""
|
||||||
with open("player_welcome_message", "r", encoding="utf8") as f:
|
with open("player_welcome_message", "r", encoding="utf8") as f:
|
||||||
welcome = ""
|
welcome = ""
|
||||||
for l in f.readlines():
|
for line in f.readlines():
|
||||||
welcome += l
|
welcome += line
|
||||||
# print(welcome)
|
|
||||||
eval(welcome)
|
eval(welcome)
|
||||||
|
|
||||||
name = ""
|
name = ""
|
||||||
while not name:
|
while not name:
|
||||||
name = input("Wie heißen Sie? ")
|
name = input("Wie heißen Sie? ")
|
||||||
|
if name == 'r':
|
||||||
|
main()
|
||||||
|
elif name == 'q':
|
||||||
|
ui.the_end()
|
||||||
|
sys.exit()
|
||||||
|
else:
|
||||||
|
pass
|
||||||
print(f"Willkommen, {name}!")
|
print(f"Willkommen, {name}!")
|
||||||
|
|
||||||
player_number = 0
|
player_number = 0
|
||||||
while not player_number:
|
while not player_number:
|
||||||
try:
|
player_number = clean_input.io_int("Gegen wie viele Personen wollen Sie spielen? ")
|
||||||
player_number = int(input("Gegen wie viele Personen wollen Sie spielen? "))
|
|
||||||
except:
|
|
||||||
print("Ihre Eingabe war nicht korrekt. Bitte versuchen Sie es nochmal. ")
|
|
||||||
# TODO: player_number check for integer
|
|
||||||
|
|
||||||
players = []
|
players = []
|
||||||
human = (name, True)
|
human = (name, True)
|
||||||
|
@ -209,3 +225,5 @@ def main():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
# Tests:
|
||||||
|
|
|
@ -46,7 +46,7 @@ def pling(current_roll):
|
||||||
if line[0] == '#':
|
if line[0] == '#':
|
||||||
clear()
|
clear()
|
||||||
print(scan_lines[:-2])
|
print(scan_lines[:-2])
|
||||||
time.sleep(1)
|
time.sleep(0.5)
|
||||||
scan_lines = ""
|
scan_lines = ""
|
||||||
|
|
||||||
#for item in animations:
|
#for item in animations:
|
||||||
|
@ -60,4 +60,4 @@ def the_end():
|
||||||
#dice_animation()
|
#dice_animation()
|
||||||
#for i in range(1,7):
|
#for i in range(1,7):
|
||||||
#pling(i)
|
#pling(i)
|
||||||
the_end()
|
#the_end()
|
||||||
|
|
Loading…
Reference in New Issue