DevOps_Innopolis

Форк
0
/
Knight_and_monsters.py 
83 строки · 2.9 Кб
1
import random
2
from time import sleep
3

4
KNIGHT_HEALTH = 10
5
KNIGHT_ATTACK = 10
6
NUMBER_OF_KILLED_MONSTERS = 0
7

8

9
def stats_monitor():
10
    print("---------------------------------------------------")
11
    print("HEALTH", KNIGHT_HEALTH, "| ATTACK", KNIGHT_ATTACK, "| KILLED_MONSTERS", NUMBER_OF_KILLED_MONSTERS)
12
    sleep(1.5)
13

14

15
def monster():
16
    def fight_monster() -> int:
17
        global KNIGHT_HEALTH
18
        global KNIGHT_ATTACK
19
        global NUMBER_OF_KILLED_MONSTERS
20
        if monster_attack >= KNIGHT_HEALTH:
21
            print("The monster has torn you apart, GAME OVER")
22
            exit()
23
        elif KNIGHT_ATTACK >= monster_health:
24
            KNIGHT_HEALTH -= monster_attack
25
            NUMBER_OF_KILLED_MONSTERS += 1
26
            print(f"You won, but now you have {KNIGHT_HEALTH} points of health")
27
            return KNIGHT_HEALTH
28
        else:
29
            KNIGHT_HEALTH -= monster_attack
30
            print(f"This monster hurt you and you won't be able to kill him, "
31
                  f"now you have {KNIGHT_HEALTH} points of health")
32

33
    monster_health = random.randint(5, 30)
34
    monster_attack = random.randint(5, 30)
35

36
    text = input(f"It's a monster, it looks like it has {monster_health} points of health and {monster_attack} attack, "
37
                 "do you want to fight? Please enter \"1\" if you want to fight or \"2\" if you run away ")
38

39
    while (text != "1") and (text != "2"):
40
        text = input("Please enter \"1\" or \"2\"")
41

42
    if text == "1":
43
        fight_monster()
44

45

46
def apple() -> int:
47
    global KNIGHT_HEALTH
48
    apple_richness = random.randint(5, 30)
49
    KNIGHT_HEALTH += apple_richness
50
    print(f"You found an apple and ate it, it gave you {apple_richness} points of health", KNIGHT_HEALTH)
51
    return KNIGHT_HEALTH
52

53

54
def sword():
55
    def change_sword() -> int:
56
        global KNIGHT_ATTACK
57
        KNIGHT_ATTACK = new_sword
58
        return KNIGHT_ATTACK
59

60
    new_sword = random.randint(5, 30)
61
    text = input(f"You found a new sword, it has {new_sword} attack, "
62
                 "do you choose this one? Please enter \"1\" if you want to choose a new sword or \"2\" if not ")
63

64
    while (text != "1") and (text != "2"):
65
        text = input("Please enter \"1\" or \"2\"")
66

67
    if text == "1":
68
        change_sword()
69

70

71
print("Hello, you are a knight and life is a pain, you must survive!!!")
72
print("You can meet monsters in this dark wood, you have to kill 10 monsters. "
73
      "It will show your courage and will allow you to win the heart of a princess =)")
74

75
while NUMBER_OF_KILLED_MONSTERS != 10:
76
    stats_monitor()
77
    actions = monster, apple, sword
78
    new_action = random.choice(actions)
79
    new_action()
80

81
print("**************************************************************")
82
print("Yeah, VICTORY!!! now you can ask for the hand of a princess!!!")
83
print("**************************************************************")

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.