Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import random
- import time
- options = ['Papier', 'Kamień', 'Nożyce']
- player_score = 0
- cpu_score = 0
- def get_winner(choice_one, choice_two):
- if choice_one == choice_two:
- result = 'tie'
- elif choice_one == options[1] and choice_two == options[0]:
- result = 'cpu_won'
- elif choice_one == options[1] and choice_two == options[2]:
- result = 'player_won'
- elif choice_one == options[0] and choice_two == options[1]:
- result = 'player_won'
- elif choice_one == options[0] and choice_two == options[2]:
- result = 'cpu_won'
- elif choice_one == options[2] and choice_two == options[1]:
- result = 'cpu_won'
- elif choice_one == options[2] and choice_two == options[0]:
- result = 'player_won'
- return result
- def start_game():
- print('Kamień, Papier, Nożyce.')
- start = input("By rozpocząć gre wpisz 'start', by wyłaczyć wpisz 'zakoncz': ")
- if start == 'start' or start == 'START':
- player_select()
- elif start == 'zakoncz' or start == 'ZAKONCZ':
- sys.exit()
- else:
- print('Spróbuj ponownie. Słowo powinno być wpisane wielkimi lub małymi literami bez polskich znaków.')
- start_game()
- def player_select():
- player_choice = input('Wybierz: {}, {} lub {}: '.format(options[0], options[1], options[2]))
- if player_choice == options[0] or player_choice == options[1] or player_choice == options[2]:
- cpu_select()
- else:
- print('Zła nazwa symbolu. Nazwa powinna być wpisana wielką literą z polskimi znakami.')
- player_select()
- return player_choice
- def cpu_select():
- cpu_choice = random.choice(options)
- print('Twój przeciwnik wybrał:')
- time.sleep(0.5)
- print(cpu_choice)
- game_result()
- return cpu_choice
- def game_result():
- result = get_winner(player_choice, cpu_choice)
- if result == 'player_won':
- print('Wygrałeś.')
- player_score += 1
- elif result == 'cpu_won':
- print('Przegrałeś.')
- cpu_score += 1
- else:
- print('Remis.')
- score_board = 'Wynik: Gracz: ' + str(player_score) + ' Komputer: ' + str(cpu_score)
- print(score_board)
- end_game()
- def end_game():
- play_again = input('Gramy ponownie? Wpisz tak lub nie: ')
- if play_again == 'Tak' or play_again == 'tak':
- print('Gramy dalej.')
- game()
- elif play_again == 'Nie' or play_again == 'nie':
- print('Dziękujemy za grę.')
- sys.exit()
- else:
- print('Spróbuj ponownie.')
- end_game()
- return score_board
- while True:
- start_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement