Для классного проекта мне нужно написать эту игру в кости на Python, и единственное, что я не могу решить, это то, что переменная total_score сбрасывается обратно в 0 в начале хода каждого игрока. Я считаю, что это связано с тем, что значение не сохраняется должным образом, но не могу найти решение.
import math, random
def print_instructions():
print("""Welcome to Pig Dice. Get 2 to 10 players and one 6 sided die. During a player's turn, they may roll the die as many times as they wish. At the end of their turn, add all of their points together and pass the die to the next person. However, if they roll a one, they lose all points gained, and that turn ends. First one to score 100 points wins.""")
def get_Player_names ():
print("You will need 2 to 10 players!")
done = False
players = []
while not done:
player = input("Names of players(hit enter to quit): ")
if len(player)>0:
players.append(player)
else:
done=True
print()
return players
def process_player_turn(player_name,total_score,turn_score):
choice = input(f"{player_name} would you like to roll or pass? ")
while choice == ("roll"):
player_value = random.randint(1,6)
print(f"{player_name} rolled a {player_value}")
turn_score = turn_score + player_value
if player_value == 1:
turn_score = 0
print(f"{player_name} rolled a 1! Turn over!")
print("Total score:", total_score)
break
if total_score >= 100:
print(f"{player_name}'s score:", total_score, f"{player_name} Wins!")
return True
choice = input(f"{player_name} would you like to roll again? ")
else:
total_score = total_score + turn_score
print("Total score:", total_score, "Turn ended.")
turn_score = 0
print()
return False
def main():
total_score = 0
turn_score = 0
print_instructions()
player_names = get_Player_names()
done = False
while not done:
for player_name in player_names:
done = process_player_turn(player_name,total_score,turn_score)
if done:
break
if __name__=="__main__":
main()
Подробнее здесь: https://stackoverflow.com/questions/783 ... every-turn
Пытаюсь сыграть в игру в кости со свиньями, но счет сбрасывается каждый ход. ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Превратите игру с черепахой Python в локальную многопользовательскую игру LAN
Anonymous » » в форуме Python - 0 Ответы
- 29 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Поверните игру с черепахой Python в многопользовательскую игру LAN LAN [закрыто]
Anonymous » » в форуме Python - 0 Ответы
- 42 Просмотры
-
Последнее сообщение Anonymous
-