Повтор игрыPython

Программы на Python
Ответить
Anonymous
 Повтор игры

Сообщение Anonymous »

Как мне сделать цикл повторного воспроизведения игры? Могут ли игроки не видеть ответы друг друга или добавлять одновременно? Это ремейк Strategy Steps, Wii Party, и я хочу спросить (в конце), хочет ли игрок снова сыграть в эту игру.
import time

def game():
welcome = input("Welcome to Wii Party: Strategy Steps! Would you like to know how to play this game? Type 'yes' or 'no': ")
if welcome == "Yes" or welcome == "yes":
time.sleep(1)
print("Two players choose between three numbers (1,3,5).\nIf a player selects the same number as another player, both players stay where they are.\nIf both numbers are different, the players will move up in accordance to the number they have selected.\nFor example, if players 1-3 (in 4 player situation) choose 3 and player 4 chooses 5, player 4 will move up by 5 steps but players 1-3 will stay where they are.\nThere are 20 steps altogether.\nThe first player to reach the top of the staircase is the winner.")
else:
time.sleep(1)
print("Let's move on!")
totalsteps = 20
player1position = 0
player2position = 0
options = [1, 3, 5]

while player1position < totalsteps and player2position < totalsteps:
player1choice = int(input("Player 1, choose a number between 1, 3 and 5: "))
while player1choice not in options:
print("That is not one of the options. Try again.")
player1choice = int(input("Player 1, choose a number between 1, 3 and 5: "))
if player1choice in options:
break
else:
pass
time.sleep(1)
player2choice = int(input("Player 2, choose a number between 1, 3 and 5: "))
while player2choice not in options:
print("That is not one of the options. Try again.")
player2choice = int(input("Player 2, choose a number between 1, 3 and 5: "))
if player2choice in options:
break
else:
pass

if player1choice != player2choice:
player1position += player1choice
player2position += player2choice
print("Player 1 has moved up ", player1choice, "steps and is now on step", player1position,"!")
time.sleep(1)
print("Player 2 has moved up ", player2choice, "steps and is now on step", player2position,"!")
else:
time.sleep(1)
print("The same number was picked so no one moved")
if player1position >= totalsteps:
print("Player 1 wins!")
break
elif player2position >= totalsteps:
print("Player 2 wins!")
break

game()


Подробнее здесь: https://stackoverflow.com/questions/791 ... ing-a-game
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»