-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserInterface.py
More file actions
137 lines (119 loc) · 4.26 KB
/
userInterface.py
File metadata and controls
137 lines (119 loc) · 4.26 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from prompt.prompt import Prompt
from player.player import Player
from world.timeService import TimeService
# @author Daniel McCoy Stephenson
class UserInterface:
def __init__(self, currentPrompt: Prompt, timeService: TimeService, player: Player):
self.currentPrompt = currentPrompt
self.timeService = timeService
self.player = player
self.prompt = "Make your choice!"
self.optionList = []
self.times = {
0: "12:00 AM",
1: "1:00 AM",
2: "2:00 AM",
3: "3:00 AM",
4: "4:00 AM",
5: "5:00 AM",
6: "6:00 AM",
7: "7:00 AM",
8: "8:00 AM",
9: "9:00 AM",
10: "10:00 AM",
11: "11:00 AM",
12: "12:00 PM",
13: "1:00 PM",
14: "2:00 PM",
15: "3:00 PM",
16: "4:00 PM",
17: "5:00 PM",
18: "6:00 PM",
19: "7:00 PM",
20: "8:00 PM",
21: "9:00 PM",
22: "10:00 PM",
23: "11:00 PM",
}
def lotsOfSpace(self):
print("\n" * 20)
def divider(self):
print("\n")
print("-" * 75)
print("\n")
def showOptions(
self,
descriptor,
optionList,
):
while True:
self.lotsOfSpace()
self.divider()
print(" " + descriptor)
self.divider()
print(" Day %d" % self.timeService.day)
print(" | " + self.times[self.timeService.time])
print(" | Money: $%d" % self.player.money)
print(" | Fish: %d" % self.player.fishCount)
print(" | Energy: %d" % self.player.energy)
print("\n " + self.currentPrompt.text)
self.divider()
self.n = 1
self.listOfN = []
for option in optionList:
print(" [%d] %s" % (self.n, option))
self.listOfN.append("%d" % self.n)
self.n += 1
choice = input("\n> ")
for i in self.listOfN:
if choice == i:
return choice
self.currentPrompt.text = "Try again!"
def showDialogue(self, text):
self.lotsOfSpace()
self.divider()
print(text)
self.divider()
input(" [ CONTINUE ]")
self.currentPrompt.text = "What would you like to do?"
def showInteractiveDialogue(self, npc):
"""Shows an interactive dialogue menu with the NPC"""
while True:
self.lotsOfSpace()
self.divider()
print(f" Talking with {npc.name}")
self.divider()
# Show dialogue options
dialogue_options = npc.get_dialogue_options()
if not dialogue_options:
# Fallback to simple introduction if no options
print(npc.introduce())
self.divider()
input(" [ CONTINUE ]")
self.currentPrompt.text = "What would you like to do?"
break
print(" What would you like to ask?\n")
option_list = []
for i, option in enumerate(dialogue_options):
question = option.get("question", f"Option {i+1}")
print(f" [{i+1}] {question}")
option_list.append(str(i+1))
print(f" [{len(option_list)+1}] [Back]")
option_list.append(str(len(option_list)+1))
choice = input("\n> ")
if choice in option_list:
choice_idx = int(choice) - 1
# Check if user chose to go back
if choice_idx == len(dialogue_options):
self.currentPrompt.text = "What would you like to do?"
break
# Show the response
response = npc.get_dialogue_response(choice_idx)
self.lotsOfSpace()
self.divider()
print(f" {npc.name}: {response}")
self.divider()
input(" [ CONTINUE ]")
else:
print(" Invalid choice. Try again!")
input(" [ CONTINUE ]")