Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. import random
  2.  
  3. SPELL_TYPES = ["Огонь", "Тросник", "Вулкан", "Молнии",
  4. "Вода", "Ураган", "Землятресение"]
  5.  
  6. USER_TURN = 1
  7. COMPUTER_TURN = 2
  8.  
  9.  
  10. def run():
  11. print("Добро пожаловать в игру \"Рулетка амулетов\"")
  12. print_spell_types()
  13. user_amuletes = get_user_amultes()
  14. computer_amultes = get_computer_amultes()
  15.  
  16. current_turn = random.sample([USER_TURN, COMPUTER_TURN], 1)[0]
  17.  
  18. computer_used_spells = set()
  19. computer_attack_spell = None
  20. user_attack_spell = None
  21. game_continues = True
  22.  
  23. while game_continues:
  24. print()
  25. if current_turn == USER_TURN:
  26. user_attack_spell = get_spell_type_from_uset_input()
  27. current_turn = COMPUTER_TURN
  28. game_continues = user_attack_spell in computer_amultes
  29. else:
  30. computer_current_spell_count = len(computer_used_spells)
  31. while computer_current_spell_count == len(computer_used_spells):
  32. computer_attack_spell = get_random_spell()
  33. computer_used_spells.add(computer_attack_spell)
  34. print("Атака противника: {}".format(computer_attack_spell))
  35. current_turn = USER_TURN
  36. game_continues = computer_attack_spell in user_amuletes
  37.  
  38. if current_turn == COMPUTER_TURN:
  39. print("Поздравляю Вы выиграили")
  40. else:
  41. print("Поздравляю Вы проиграли")
  42.  
  43. print("Амулеты соперника")
  44. print_spells_set(computer_amultes)
  45.  
  46.  
  47. def print_spell_types():
  48. print_spells_set(SPELL_TYPES)
  49.  
  50. def get_spell_type_from_uset_input():
  51. number = int(input("Введите цифру: ")) - 1
  52. print("Вы выбрали {}".format(SPELL_TYPES[number]))
  53. return SPELL_TYPES[number]
  54.  
  55. def get_user_amultes():
  56. print("Выбире себе амулеты")
  57. user_amuletes = set()
  58. while len(user_amuletes) < 4:
  59. user_amuletes.add(get_spell_type_from_uset_input())
  60.  
  61. return user_amuletes
  62.  
  63. def get_computer_amultes():
  64. computer_amultes = set()
  65. while len(computer_amultes) < 4:
  66. computer_amultes.add(get_random_spell())
  67. return computer_amultes
  68.  
  69. def get_random_spell():
  70. return SPELL_TYPES[random.randrange(0,len(SPELL_TYPES))]
  71.  
  72. def print_spells_set(spells):
  73. i = 1
  74. for spell_type in spells:
  75. print("{0}. {1}".format(i, spell_type))
  76. i+=1
  77.  
  78.  
  79.  
  80. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement