generated from Labpro-21/kit-if1210-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
188 lines (176 loc) · 8.2 KB
/
main.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
import sys
sys.path.append('src')
import B04, F01, F02, F03, F04, F07, F08, F09, F10, F11, F12, F13, F14, F15, F16
import operateCSV, testloader
user_data, monster_data, item_inventory, item_shop, monster_inventory, monster_shop = F14.load()
# user_data = operateCSV.baca_csv(r"data\user.csv")
# monster_data = operateCSV.baca_csv(r'data\monster.csv')
# item_inventory = operateCSV.baca_csv(r'data\item_inventory.csv')
# item_shop = operateCSV.baca_csv(r'data\item_shop.csv')
# monster_inventory = operateCSV.baca_csv(r'data\monster_inventory.csv')
# monster_shop = operateCSV.baca_csv(r'data\monster_shop.csv')
#dependencies array for loading datas
user_monster=[['monster_id','monster_level']]
#mobile inventories
player_monster_arr=[['type','atk','def','hp','lv']]
player_inv_arr=[['type','quantity']]
#potion state
potion_check=[False,False,False]
#mobile inventory load state
loaded=False
(username, user_id, role, coin, win) = ('', '', '', 0, False)
berhenti = False
while not(berhenti):
menu = input(">>> ").upper()
if menu == 'REGISTER':
(username, monster_id, user_data, monster_inventory) = (F01.register(username, user_data, monster_data, monster_inventory))
role, coin = 'agent', '0'
elif menu == 'LOGIN':
(username, role, coin) = (F02.login(username, role, coin, user_data))
elif menu == 'LOGOUT':
if username != "" :
(username, role, coin) = (F03.logout(username, role, coin))
else:
print("Logout gagal!")
print("Anda belum login, silahkan login terlebih dahulu sebelum melakukan logout")
elif menu == "HELP":
if username != '':
F04.help(username,role)
else:
print ("Kamu belum login sebagai role apapun. Silahkan login terlebih dahulu.")
print (" "*5+"1. Login : Masuk ke dalam akun yang sudah terdaftar")
print (" "*5+"2. Register : Membuat akun baru")
elif (menu == "INVENTORY") :
if username != "" :
if role == "agent":
user_monster=[['monster_id','monster_type','atk_power','def_power','hp']]
user_id = testloader.get_uid(user_data, username) # untuk mendapatkan user_id
#strage
storage = testloader.get_storage(item_inventory, user_id, monster_data)
user_inventory=[]
#monster_list =
F07.finventory(user_data, username, user_id, monster_data , user_monster, monster_inventory, storage,user_inventory, item_inventory, monster_data )
elif role=='admin':
print("Maaf, Anda bukan seorang agent! Anda tidak memiliki izin untuk menggunakan perintah ini.")
else :
print("Anda belum masuk ke akun apapun, silakan login terlebih dahulu\n")
elif (menu == "SHOP"):
print()
if username != '':
if role == "admin":
(username, role, coin, monster_shop, item_shop) = (F12.shop_management(username, role, coin, monster_data, monster_shop, item_shop))
elif role =='agent':
(username, role, coin, user_data, monster_inventory, monster_shop, item_inventory, item_shop) = (F10.shop_currency(username, role, coin, user_data, monster_data, monster_inventory, monster_shop, item_inventory, item_shop))
else:
print("Anda belum masuk ke akun apapun, silakan login terlebih dahulu\n")
elif (menu == "LABORATORY"):
if username != '':
if role == "agent":
(username, role, coin, user_data, monster_inventory) = (F11.laboratory(username, role, coin, user_data, monster_inventory, monster_data))
elif role=='admin':
print("Maaf, Anda bukan seorang agent! Anda tidak memiliki izin untuk menggunakan perintah ini.")
else:
print("Anda belum masuk ke akun apapun, silakan login terlebih dahulu\n")
elif (menu == "BATTLE"):
if username != '':
if role == "agent":
#find uid
userid=testloader.get_uid(user_data,username)
if not loaded:
#load datas to mobile inventory
# print(player_inv_arr)
player_monster_arr=(testloader.monster_inventory(monster_data,testloader.filter_monster(monster_inventory,userid,user_monster),player_monster_arr))
# print(monster_inventory)
# print(monster_data)
player_inv_arr=(testloader.filter_item(item_inventory,userid,player_inv_arr))
loaded=True
# print(player_inv_arr)
(username, role, coin) = (F08.battle(username, role, coin, menu, 0, monster_data, player_monster_arr, player_inv_arr, potion_check))
#reset potion states
potion_check=[False,False,False]
#change item in item_inventory from mobile inventory
F08.ubah_potion(item_inventory,userid,player_inv_arr)
# print(item_inventory)
#unload
user_monster=[['monster_id','monster_level']]
player_monster_arr=[['type','atk','def','hp','lv']]
player_inv_arr=[['type','quantity']]
loaded=False
# print(player_inv_arr)
elif role=='admin':
print("Maaf, Anda bukan seorang agent! Anda tidak memiliki izin untuk menggunakan perintah ini.")
else:
print("Anda belum masuk ke akun apapun, silakan login terlebih dahulu\n")
elif (menu == "ARENA"):
if username != '':
if role == "agent":
#find uid
userid=testloader.get_uid(user_data,username)
stage=1
alive=True
total_taken=0
total_dealt=0
total_oc=0
while (not stage>5) and alive:
if not loaded:
#load datas to mobile inventory
player_monster_arr=(testloader.monster_inventory(monster_data,testloader.filter_monster(monster_inventory,userid,user_monster),player_monster_arr))
player_inv_arr=(testloader.filter_item(item_inventory,userid,player_inv_arr))
loaded=True
(username,role,coin,damage_taken,damage_dealt,win,gained) = (F09.arena(username, role, coin, menu, monster_data, player_monster_arr, player_inv_arr, potion_check, stage))
#reset potion states
potion_check=[False,False,False]
#change item in item_inventory from mobile inventory
F08.ubah_potion(item_inventory,userid,player_inv_arr)
#unload
user_monster=[['monster_id','monster_level']]
player_monster_arr=[['type','atk','def','hp','lv']]
player_inv_arr=[['type','quantity']]
loaded=False
if win:
stage+=1
if stage>5:
print('Selamat, kamu berhasil menamatkan sesi Arena!!!')
else: #stage<=5 and stage>0
print(f'Lanjut ke stage {stage}.\n')
total_taken+=damage_taken
total_dealt+=damage_dealt
total_oc+=gained
else:
alive=False
total_taken+=damage_taken
total_dealt+=damage_dealt
total_oc+=gained
print(f"""============== STATS ==============
Total hadiah : {total_oc} OC
Jumlah stage : {stage-1}
Damage diberikan : {total_dealt:.2f}
Damage diterima : {total_taken:.2f}
""")
elif role=='admin':
print("Maaf, Anda bukan seorang agent! Anda tidak memiliki izin untuk menggunakan perintah ini.")
else:
print("Anda belum masuk ke akun apapun, silakan login terlebih dahulu\n")
elif (menu == "MONSTER"):
if username != '':
if role == "admin":
(username, role, coin, monster_data) = (F13.monster_management(username, role, coin, monster_data))
elif role=='agent':
print("Maaf, Anda bukan seorang admin! Anda tidak memiliki hak untuk menggunakan perintah ini.")
else:
print("Anda belum masuk ke akun apapun, silakan login terlebih dahulu\n")
elif (menu == "JACKPOT"):
if username != '':
if role == "agent":
coin, monster_inventory = B04.jackpot(username, coin, user_data, monster_data, monster_inventory)
elif role == 'admin':
print("Maaf, Anda bukan seorang agent! Anda tidak memiliki izin untuk menggunakan perintah ini.")
else:
print("Anda belum masuk ke akun apapun, silakan login terlebih dahulu\n")
elif (menu == "SAVE"):
F15.save(username, coin, user_data, monster_data, monster_inventory, monster_shop, item_inventory, item_shop)
elif (menu == "EXIT"):
F16.exit_program(username, coin, user_data, monster_data, monster_inventory, monster_shop, item_inventory, item_shop)
break
else:
print("Perintah tidak dikenal.")