Advertisement
Guest User

Kamień, Papier, Nożyce

a guest
Jul 17th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.63 KB | None | 0 0
  1. import sys
  2. import random
  3. import time
  4.  
  5. options = ['Papier', 'Kamień', 'Nożyce']
  6. player_score = 0
  7. cpu_score = 0
  8.  
  9. def get_winner(choice_one, choice_two):
  10.     if choice_one == choice_two:
  11.         result = 'tie'
  12.     elif choice_one == options[1] and choice_two == options[0]:
  13.         result = 'cpu_won'
  14.     elif choice_one == options[1] and choice_two == options[2]:
  15.         result = 'player_won'
  16.     elif choice_one == options[0] and choice_two == options[1]:
  17.         result = 'player_won'
  18.     elif choice_one == options[0] and choice_two == options[2]:
  19.         result = 'cpu_won'
  20.     elif choice_one == options[2] and choice_two == options[1]:
  21.         result = 'cpu_won'
  22.     elif choice_one == options[2] and choice_two == options[0]:
  23.         result = 'player_won'
  24.     return result
  25.  
  26. def start_game():
  27.     print('Kamień, Papier, Nożyce.')
  28.     start = input("By rozpocząć gre wpisz 'start', by wyłaczyć wpisz 'zakoncz': ")
  29.     if start == 'start' or start == 'START':
  30.         player_select()
  31.     elif start == 'zakoncz' or start == 'ZAKONCZ':
  32.         sys.exit()
  33.     else:
  34.         print('Spróbuj ponownie. Słowo powinno być wpisane wielkimi lub małymi literami bez polskich znaków.')
  35.         start_game()
  36.  
  37. def player_select():
  38.     player_choice = input('Wybierz: {}, {} lub {}: '.format(options[0], options[1], options[2]))
  39.     if player_choice == options[0] or player_choice == options[1] or player_choice == options[2]:
  40.         cpu_select()
  41.     else:
  42.         print('Zła nazwa symbolu. Nazwa powinna być wpisana wielką literą z polskimi znakami.')
  43.         player_select()
  44.  
  45.     return player_choice
  46.  
  47. def cpu_select():
  48.     cpu_choice = random.choice(options)
  49.     print('Twój przeciwnik wybrał:')
  50.     time.sleep(0.5)
  51.     print(cpu_choice)
  52.     game_result()
  53.    
  54.     return cpu_choice
  55.  
  56. def game_result():
  57.     result = get_winner(player_choice, cpu_choice)
  58.     if result == 'player_won':
  59.         print('Wygrałeś.')
  60.         player_score += 1
  61.     elif result == 'cpu_won':
  62.         print('Przegrałeś.')
  63.         cpu_score += 1
  64.     else:
  65.         print('Remis.')
  66.        
  67.     score_board = 'Wynik: Gracz: ' + str(player_score) + ' Komputer: ' + str(cpu_score)
  68.     print(score_board)
  69.     end_game()
  70.  
  71. def end_game():
  72.     play_again = input('Gramy ponownie? Wpisz tak lub nie: ')
  73.     if play_again == 'Tak' or play_again == 'tak':
  74.         print('Gramy dalej.')
  75.         game()
  76.     elif play_again == 'Nie' or play_again == 'nie':
  77.         print('Dziękujemy za grę.')
  78.         sys.exit()
  79.     else:
  80.         print('Spróbuj ponownie.')
  81.         end_game()
  82.  
  83.     return score_board
  84.  
  85.  
  86. while True:
  87.     start_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement