-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.py
More file actions
226 lines (199 loc) · 9.37 KB
/
Menu.py
File metadata and controls
226 lines (199 loc) · 9.37 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
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
import sys
import os
import math
import World as wd
from Hotel import *
import Tools
from GlobalDeclaration import *
from StockController import *
from BankController import *
class Menu:
def __init__(self,player,env,hc,sc,bc):
self.player = player
self.env = env
self.hc = hc
self.sc = sc
self.bc = bc
#Check whether the key press is "ENTER",if yes, continue
def EnterGame(self):
print "Welcome to Neil's World! " + '\n'+ "Make your own fortune to buy Jinjing a BMW ~ "
print "Press Enter to paly.Press q to exit the game"
x = raw_input()
if x == "":
#need to add link to next level. Now just an empty action
os.system("clear")
return
#if press q, then exit the whole program
if x == "q":
sys.exit()
#if the keypress is not "ENTER", print the prompt again
else:
os.system("clear")
print "please press the right key "
self.EnterGame()
def WeeklyReport(self):
while G.reported != round(self.env.now/7) :
G.reported = round(self.env.now/7)
yield self.env.timeout(0)
yield self.env.process(Tools.weekly_report_notice(self.env))
print "Week %d has passed." %math.ceil(G.reported) #announce the current week
#hand control back to simpy
self.revenue_report()
#check if we need to pay back loan
print G.tillPay
print self.player.loan
if G.tillPay == 0 and self.player.loan != 0:
self.bc.pay_loan() #has to pay loan before doing other stuff
if G.tillWithdraw !=0 :
G.tillWithdraw -= 1
if G.tillPay != 0:
G.tillPay -= 1 #loan payment countdown
while True:
choice = int(Tools.get_option("Enter 1 for hotel upgrade. Enter 2 to check out bank. Enter 3 to check out stock.Enter 4 to skip and continue.",[1,2,3,4]))
os.system("clear") #clear screen
if choice == 1:
yield self.env.process(self.hotel_upgrade())
if choice == 2:
#ToDo : add in the bank part
yield self.env.process(self.bank_business())
if choice == 3:
yield self.env.process(self.stock_business())
if choice == 4 :
break
print "Done weekly report." +'\n' + "Starting week %d " %(G.reported+1)
Tools.Continue()
def revenue_report(self):
for hotel in self.hc.hotels:
hotel.str() #announce the money made, hotel room numbers
self.player.add_money(hotel.revenue)
print "You now have %d dollars. " % self.player.checking_account.balance
def hotel_upgrade(self):
while True:
print "Would you want to updrade any of your hotel ?" #ask whether the user wanna upgrade the hotel
upgrade = Tools.check_confirm("Print Y for yes. Print N to continue playing")
if not upgrade:
os.system("clear") #clear the screen
break
os.system("clear") #clear screen
choice = int(Tools.get_option("""You have several upgrade options:
Enter 1 to build more rooms in your original hotel. The upper limit for each type of rooms is 50.
Enter 2 to upgrade your hotel to a higher level.
Enter 3 to build a new hotel """,[1,2,3]))
if choice == 1 :
yield self.env.process(self.build_hotel_rooms())
if choice == 2:
yield self.env.process(self.upgrade_hotel())
if choice == 3:
yield self.env.process(self.new_hotel())
def build_hotel_rooms(self):
os.system("clear")
print "Enter the corresponding number for the hotel you want to build more rooms"
i = 1
for hotel in self.hc.hotels:
print "Enter %d for %s" %(i,hotel.name)
hotel = self.hc.hotels[int(Tools.get_option('Your choice: ',Tools.produce_hotel_option(self.hc)))-1]
os.system("clear")
print "you choose to upgrade %s " %hotel.name
print "%s now have %d Queen Standard rooms,%d King Standard rooms, \
%d Queen Deluxe rooms and %d King Deluxe rooms" %(hotel.name,hotel.simpy_rooms['Queen Standard'].capacity,\
hotel.init_room_number['King Standard'],hotel.init_room_number['Queen Deluxe'],\
hotel.init_room_number['King Deluxe'])
roomtype = hotel.ROOM_TYPES[int(Tools.get_option("""Which type of rooms would you like to build more?
Enter 1 for Queen Standard,
Enter 2 for King Standard,
Enter 3 for Queen Deluxe,
Enter 4 for King Deluxe """,[1,2,3,4]))-1]
m = "Sorry, you do not have enough money to build this many rooms." + '\n' + "With all your money,\
you can only build %d rooms of this type" %(self.player.checking_account.balance/hotel.room_cost[roomtype])
roomnumber = hotel.simpy_rooms[roomtype].capacity + 1
upgrade_cost = self.player.checking_account.balance + 1
while True :
while roomnumber > (hotel.simpy_rooms[roomtype].capacity - hotel.init_room_number[roomtype]):
message = "How many more rooms would you want to build ? Can only buy %d more" %(hotel.simpy_rooms[roomtype].capacity - hotel.init_room_number[roomtype])
roomnumber = Tools.check_positive_valid_input(message)
upgrade_cost = hotel.room_cost[roomtype]*roomnumber
if self.player.buy_property(upgrade_cost,m):
break
#change the record of room number for that type of room
hotel.init_room_number[roomtype] += roomnumber
yield hotel.simpy_rooms[roomtype].put(roomnumber) #actually build the roomssimpy_rooms[roomtype].put[roomnumber] #actually build the rooms
print "Successfully built %d more %s rooms for your %s" %(roomnumber,roomtype,hotel.name)
def upgrade_hotel(self):
os.system("clear")
print "Enter the corresponding number for the hotel you want to upgrade"
i = 1
for hotel in self.hc.hotels:
print "Enter %d for %s" %(i,hotel.name)
i += 1
hotel = self.hc.hotels[int(Tools.get_option('Your choice: ',Tools.produce_hotel_option(self.hc)))-1]
os.system("clear")
print "You choose to upgrade %s. " %hotel.name
print "Your %s is a %s now" %(hotel.name,hotel.level)
upgrade_options = Tools.upgrade_option(hotel)
i = 0
choice = []
while i< len(upgrade_options):
if upgrade_options[i] is None:
print "Can't upgrade anymore."
break
return
else :
print "Press %d to upgrade %s to a %s. " %(i+1,hotel.name,upgrade_options[i])
choice.append(i+1)
i += 1
option = int(Tools.get_option("Enter your choice:",choice))-1
cost_after_upgrade = Hotel(self.env,'test',upgrade_options[option],hotel.simpy_rooms['Queen Standard'].capacity,\
hotel.simpy_rooms['King Standard'].capacity,hotel.simpy_rooms['Queen Deluxe'].capacity,\
hotel.simpy_rooms['King Deluxe'].capacity).initial_cost()
if self.player.buy_property(cost_after_upgrade - hotel.initial_cost(),"You don't have enough money to upgrade your hotel "):
hotel.level = upgrade_options[option]
print "Successfully upgrade your hotel to %s" %hotel.level
yield self.env.timeout(0)
def new_hotel(self):
os.system("clear")
self.hc.build_new_hotel()
yield self.env.timeout(0)
def bank_business(self):
os.system("clear")
print "Welcome to Jinjing's Bank!"
while True :
self.bc.check_checking()
self.bc.check_saving()
choice1 = int(Tools.get_option("""Enter 1 to transfer money from cheking account to saving account.
Enter 2 to transfer money from saving account to checking account.
Enter 3 to loan money from bank.
Enter 4 to exit.""",[1,2,3,4]))
if choice1 == 1:
os.system("clear")
self.bc.checking_to_saving()
if choice1 == 2:
os.system("clear")
self.bc.saving_to_checking()
if choice1 == 3 :
os.system("clear")
self.bc.loan()
if choice1 == 4 :
break
yield self.env.timeout(0)
def stock_business(self):
os.system("clear")
print "Welcome to Jinjing's stock exchange center ! "
owned_stock = self.sc.update_stock()
if not owned_stock:
print "You currently don't have any stocks. Please buy a stock first."
else :
print "The stocks you currently own are :"
for ticker in self.sc.update_stock().keys():
print ticker
while True:
choice = int(Tools.get_option("""
Enter 1 to buy stock.
Enter 2 to sell stock.
Enter 3 to exit. """,[1,2,3]))
if choice == 1 :
self.sc.buyStock()
if choice == 2 :
self.sc.sellStock()
if choice == 3:
break
yield self.env.timeout(0)