-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
99 lines (95 loc) · 4.08 KB
/
cli.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# cli.py
from mountain_manager import MountainManager
from mountain import Mountain
from trail import Trail
from mountain_organiser import MountainOrganiser
from personality import TopWalker, BottomWalker, LazyWalker
from serialize import serialize, deserialize
def run_cli():
mountain_manager = MountainManager()
trail = Trail()
mountain_organiser = MountainOrganiser()
while True:
print("\nMountain Trail Manager")
print("1. Add Mountain")
print("2. Remove Mountain")
print("3. Query Mountains")
print("4. Load Trail Data")
print("5. Save Trail Data")
print("6. Simulate Walker's Path")
print("7. Organize Mountains")
print("8. Display Mountain Positions")
print("9. Quit")
choice = input("Enter your choice (1-9): ")
if choice == "1":
name = input("Enter mountain name: ")
difficulty = int(input("Enter difficulty level: "))
length = int(input("Enter length: "))
mountain = Mountain(name, difficulty, length)
mountain_manager.add_mountain(mountain)
print(f"Mountain '{name}' added successfully.")
elif choice == "2":
name = input("Enter mountain name to remove: ")
mountain = next((m for m in mountain_manager.mountains if m.name == name), None)
if mountain:
mountain_manager.remove_mountain(mountain)
print(f"Mountain '{name}' removed successfully.")
else:
print(f"Mountain '{name}' not found.")
elif choice == "3":
print("Mountains:")
for mountain in mountain_manager.mountains:
print(f"- {mountain.name} (Difficulty: {mountain.difficulty}, Length: {mountain.length})")
elif choice == "4":
filename = input("Enter the filename to load: ")
try:
with open(filename, 'r') as file:
data = file.read()
trail = deserialize(data)
print("Trail data loaded successfully.")
except FileNotFoundError:
print(f"File '{filename}' not found.")
elif choice == "5":
filename = input("Enter the filename to save: ")
try:
with open(filename, 'w') as file:
data = serialize(trail)
file.write(data)
print("Trail data saved successfully.")
except IOError:
print(f"Error occurred while saving the file '{filename}'.")
elif choice == "6":
print("Select a walker personality:")
print("1. Top Walker")
print("2. Bottom Walker")
print("3. Lazy Walker")
personality_choice = input("Enter your choice (1-3): ")
if personality_choice == "1":
personality = TopWalker()
elif personality_choice == "2":
personality = BottomWalker()
elif personality_choice == "3":
personality = LazyWalker()
else:
print("Invalid personality choice. Skipping simulation.")
continue
trail.follow_path(personality)
if not personality.mountains:
print("No mountains found in the path.")
else:
print("Walker's Path:")
for mountain in personality.mountains:
print(f"- {mountain.name} (Difficulty: {mountain.difficulty}, Length: {mountain.length})")
elif choice == "7":
mountain_organiser.add_mountains(mountain_manager.mountains)
print("Mountains organized successfully.")
elif choice == "8":
print("Mountain Positions:")
for mountain in mountain_manager.mountains:
position = mountain_organiser.cur_position(mountain)
print(f"- {mountain.name} (Position: {position})")
elif choice == "9":
print("Exiting...")
break
else:
print("Invalid choice. Please try again.")