/
story.py
52 lines (44 loc) · 1.83 KB
/
story.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from fight import *
from tools import *
import random
class Story:
def __init__(self, name, difficulty_level):
self.name = name
self.location = 'Home'
self.is_alive = True
self.difficulty_level = difficulty_level
def get_diffuculty_level(self):
return 'novice' if self.difficulty_level==0 else 'skilled'
def update_story(self, player, inventory):
flag_quit = False
locations = ['Castle', 'Cave', 'Shore', 'Mountains', 'Fortress']
while (not (player.is_dead()) and not (flag_quit)):
options = ['Quit the game', 'Explore the neighborhood', 'Rest and restore health']
user_input = get_user_input(options)
if (user_input == 1): # Quit
flag_quit = True
print('Your adventure is terminated')
print('')
elif (user_input == 2): # Esplora
probability = 0.5
go_into_battle = random.random() < probability
if go_into_battle:
print('!!! You''ve found an opponent !!!')
fight(player, inventory, self)
print('')
else:
random_location = random.choice(locations)
if (random_location == self.location):
random_location = random.choice(locations)
self.location = random_location
print('No one''s around. You''re moving to ' + self.location)
print('')
elif (user_input == 3): # Return
player.rest()
self.location = 'Home'
print('')
else: # comando sbagliato
print('Wrong command, retry')
print('')
if player.is_dead():
print('Wasted')