-
Notifications
You must be signed in to change notification settings - Fork 4
/
ui.py
251 lines (182 loc) · 6.41 KB
/
ui.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
from functools import partial
import logging
from time import sleep
from nc import init_ui, printw, getstr, clear, alert
from menu import Menu, IdeaMenu, RightMenu
from idea import Idea
windows = init_ui()
print0 = partial(printw, windows[0])
print1 = partial(printw, windows[1])
print2 = partial(printw, windows[2])
print3 = partial(printw, windows[3])
read = partial(getstr, windows[3])
def wait_anim(sec):
for i in range(sec*20):
print3("-", end="")
sleep(0.02)
clear(windows[3])
def list_ideas(count):
ideas = []
for i in range(count):
idea = Idea()
ideas.append(idea)
return select_idea("Choose your idea", ideas)
def initproject(all_budget):
idea = list_ideas(15)
clear(windows[1])
idea_pitch = " ".join(idea.pitch.split(" ")[1:])
print1("So you have an idea, you are going to build {}".format(idea_pitch))
print1("What's the name of the project?")
name = str(read(), 'utf-8')
budget = all_budget + 1
clear(windows[1])
while budget > all_budget:
print1("You have $10000.")
print1("Your daily personal expense is $25.")
print1("How much budget do you want to allocate to your project?")
budget = int(read())
clear(windows[1])
return name, budget, idea
def print_info(project, last, key, char="", reverse=False, multiplier=1):
val = getattr(project, key)
print0(char + str(int(val*multiplier)), end="")
if reverse:
positive = 1
negative = 2
else:
positive = 2
negative = 1
if last:
last_val = getattr(last, key)
delta = int(val) - int(last_val)
if delta < 0:
print0("({})".format(delta), color=negative, end="")
elif delta >0:
print0("(+{})".format(delta), color=positive, end="")
print0()
def print_project(project, used_resources, player, last_state):
clear(windows[0])
print0("Week {}".format(used_resources.turn_count))
print0("Your Wallet: ${}({})".format(player.money, player.cash_flow), color=1)
print0("Your shares: %{}".format(player.shares))
print0("-------------------------")
print0()
print0(project.name.capitalize(), color=4)
print0(project.pitch)
print0("-------------------------")
print0()
print0("Budget", end=": ")
print0("$" + str(int(project.money)), color=2)
print0("Cash Flow", end=": ")
print0("$" + str(int(project.cash_flow)), color=1)
print0("Productivity", end=": ")
print_info(project, last_state, 'productivity', char="%", multiplier=100)
print0("Rema. Features", end=": ")
print_info(project, last_state, 'features', reverse=True)
print0("Bugs", end=": ")
print_info(project, last_state, 'bugs', reverse=True)
print0("Technical Debt", end=": ")
print_info(project, last_state, 'technical_debt', reverse=True)
print0("Documentation", end=": ")
print_info(project, last_state, 'documentation')
print0("Server Costs", end=": ")
print_info(project, last_state, 'server_maintenance', char="$", reverse=True)
print0("Design Need", end=": ")
print_info(project, last_state, 'design_need', reverse=True)
print0("Security Issues", end=": ")
print_info(project, last_state, 'security_issues', reverse=True)
print0()
print0('-------------------------')
print0()
print0("Customers", end=": ", color=4)
print0(project.number_of_customers)
print0("Influence", end=": ", color=4)
print_info(project, last_state, 'influence')
print0("Monthly Price", end=": ", color=4)
print0(project.price)
def dialog(text):
a,b = alert(windows[4], str(text), wait=False)
response = read(windows[4])
del a
del b
clear(windows[1])
return response
def cli(objects, entities, used_resources, turn_events, last_state):
player = objects[0]
project = objects[1]
for event in turn_events:
a, b = alert(windows[4], str(event))
del a
del b
project.turn_events = []
clear(windows[1])
print_project(project, used_resources, player, last_state)
unlocked_entities = [entity for entity in entities if entity.unlocked and not entity.limit_reached()]
right_menu = print_limited(objects)
action = select("What do you do?", unlocked_entities, right_menu)
if not action:
return None
return action
def print_limited(entities):
clear(windows[2])
print2("You have: (Enter to fire)")
right_menu = RightMenu(entities, windows[2], which_menu="right")
right_menu.item_message = '{1.formatted}'
right_menu.init_display()
return right_menu
def select(question, choices, right_menu):
print1(question)
answer_menu = Menu(choices, windows[1])
answer_menu.next_window = right_menu
right_menu.next_window = answer_menu
answer = answer_menu.display()
try:
answer = int(answer)
except (ValueError, TypeError):
answer = False
if not answer:
return None
else:
if answer <= len(choices) - 1 :
return choices[int(answer)]
else:
return None
def select_idea(question, choices):
print1(question)
answer_menu = IdeaMenu(choices, windows[1])
answer = answer_menu.display()
try:
answer = int(answer)
except (ValueError, TypeError):
answer = 0
return choices[int(answer)]
def win(project, player):
clear(windows[1])
win_amount = (player.shares/100) * project.score
print1("---------", color=2)
print1("Congratulations!", color=2)
print1("Big Tech company decided to buy your company for ${}!".format(project.score))
print1("You own %{} of the shares, so you get ${}!".format(player.shares, win_amount))
print1("Your total money:", end=": ")
print1("${}".format(win_amount + player.money), color=2)
print1("---------", color=2)
print1()
print1("Press Q to exit.", color=1)
while True:
key = windows[1].getkey()
if key == "Q" or key == 'q':
[clear(w) for w in windows]
exit(0)
def over(project, player):
clear(windows[1])
print1("---------", color=1)
print1("GAME OVER", color=1)
print1("---------", color=1)
print1("You are bankrupt:/ Score: {}".format(project.score))
print1()
print1("Press Q to exit.", color=1)
while True:
key = windows[1].getkey()
if key == "Q" or key == 'q':
[clear(w) for w in windows]
exit(0)