DevOps_Innopolis
/
Knight_and_monsters.py
83 строки · 2.9 Кб
1import random
2from time import sleep
3
4KNIGHT_HEALTH = 10
5KNIGHT_ATTACK = 10
6NUMBER_OF_KILLED_MONSTERS = 0
7
8
9def stats_monitor():
10print("---------------------------------------------------")
11print("HEALTH", KNIGHT_HEALTH, "| ATTACK", KNIGHT_ATTACK, "| KILLED_MONSTERS", NUMBER_OF_KILLED_MONSTERS)
12sleep(1.5)
13
14
15def monster():
16def fight_monster() -> int:
17global KNIGHT_HEALTH
18global KNIGHT_ATTACK
19global NUMBER_OF_KILLED_MONSTERS
20if monster_attack >= KNIGHT_HEALTH:
21print("The monster has torn you apart, GAME OVER")
22exit()
23elif KNIGHT_ATTACK >= monster_health:
24KNIGHT_HEALTH -= monster_attack
25NUMBER_OF_KILLED_MONSTERS += 1
26print(f"You won, but now you have {KNIGHT_HEALTH} points of health")
27return KNIGHT_HEALTH
28else:
29KNIGHT_HEALTH -= monster_attack
30print(f"This monster hurt you and you won't be able to kill him, "
31f"now you have {KNIGHT_HEALTH} points of health")
32
33monster_health = random.randint(5, 30)
34monster_attack = random.randint(5, 30)
35
36text = 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
39while (text != "1") and (text != "2"):
40text = input("Please enter \"1\" or \"2\"")
41
42if text == "1":
43fight_monster()
44
45
46def apple() -> int:
47global KNIGHT_HEALTH
48apple_richness = random.randint(5, 30)
49KNIGHT_HEALTH += apple_richness
50print(f"You found an apple and ate it, it gave you {apple_richness} points of health", KNIGHT_HEALTH)
51return KNIGHT_HEALTH
52
53
54def sword():
55def change_sword() -> int:
56global KNIGHT_ATTACK
57KNIGHT_ATTACK = new_sword
58return KNIGHT_ATTACK
59
60new_sword = random.randint(5, 30)
61text = 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
64while (text != "1") and (text != "2"):
65text = input("Please enter \"1\" or \"2\"")
66
67if text == "1":
68change_sword()
69
70
71print("Hello, you are a knight and life is a pain, you must survive!!!")
72print("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
75while NUMBER_OF_KILLED_MONSTERS != 10:
76stats_monitor()
77actions = monster, apple, sword
78new_action = random.choice(actions)
79new_action()
80
81print("**************************************************************")
82print("Yeah, VICTORY!!! now you can ask for the hand of a princess!!!")
83print("**************************************************************")