Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- SPELL_TYPES = ["Огонь", "Тросник", "Вулкан", "Молнии",
- "Вода", "Ураган", "Землятресение"]
- USER_TURN = 1
- COMPUTER_TURN = 2
- def run():
- print("Добро пожаловать в игру \"Рулетка амулетов\"")
- print_spell_types()
- user_amuletes = get_user_amultes()
- computer_amultes = get_computer_amultes()
- current_turn = random.sample([USER_TURN, COMPUTER_TURN], 1)[0]
- computer_used_spells = set()
- computer_attack_spell = None
- user_attack_spell = None
- game_continues = True
- while game_continues:
- print()
- if current_turn == USER_TURN:
- user_attack_spell = get_spell_type_from_uset_input()
- current_turn = COMPUTER_TURN
- game_continues = user_attack_spell in computer_amultes
- else:
- computer_current_spell_count = len(computer_used_spells)
- while computer_current_spell_count == len(computer_used_spells):
- computer_attack_spell = get_random_spell()
- computer_used_spells.add(computer_attack_spell)
- print("Атака противника: {}".format(computer_attack_spell))
- current_turn = USER_TURN
- game_continues = computer_attack_spell in user_amuletes
- if current_turn == COMPUTER_TURN:
- print("Поздравляю Вы выиграили")
- else:
- print("Поздравляю Вы проиграли")
- print("Амулеты соперника")
- print_spells_set(computer_amultes)
- def print_spell_types():
- print_spells_set(SPELL_TYPES)
- def get_spell_type_from_uset_input():
- number = int(input("Введите цифру: ")) - 1
- print("Вы выбрали {}".format(SPELL_TYPES[number]))
- return SPELL_TYPES[number]
- def get_user_amultes():
- print("Выбире себе амулеты")
- user_amuletes = set()
- while len(user_amuletes) < 4:
- user_amuletes.add(get_spell_type_from_uset_input())
- return user_amuletes
- def get_computer_amultes():
- computer_amultes = set()
- while len(computer_amultes) < 4:
- computer_amultes.add(get_random_spell())
- return computer_amultes
- def get_random_spell():
- return SPELL_TYPES[random.randrange(0,len(SPELL_TYPES))]
- def print_spells_set(spells):
- i = 1
- for spell_type in spells:
- print("{0}. {1}".format(i, spell_type))
- i+=1
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement