generated from Labpro-21/kit-if1210-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
212 lines (199 loc) · 7.9 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
"""
TUGAS BESAR IF1210 DASAR PEMROGRAMAN
K06-C
19623116 Zulfaqqar Nayaka Athadiansyah
19623296 Muhammad Ra'if Alkautsar
19623076 Daniel A. M. Sipayung
16523106 Naufal Fakhri Fadhlurrahman
16523146 Sacca Kovida Kasmaji
SEKOLAH TEKNIK ELEKTRO DAN INFORMATIKA
INSTITUT TEKNOLOGI BANDUNG
2024
"""
# Mengimpor library yang dibutuhkan
from nt import error
import os, argparse
# Mengimpor fungsi-fungsi yang sudah dibuat dengan penuh jerih payah
from src.x01 import *
from src.F01_Register import *
from src.F02_Login import *
from src.F03_Logout import *
from src.F15_Save import *
from src.F16_Exit import *
from src.F03_Logout import *
from src.F04_MenuHelp import *
# from src.F07_Inventory import *
from src.B05_PetaKotaDanville import *
from src.F12_ShopManagement import *
from src.F08_Battle import *
from src.F09_Arena import *
from src.F11_Laboratory import *
from src.F13_MonsterManagement import *
from src.B04_JACKPOT import *
from global_var import *
# argparse
parser = argparse.ArgumentParser(description="Menjalankan program dan memuat database csv")
parser.add_argument("dir", help="Direktori penyimpanan database CSV", nargs='?')
args = parser.parse_args()
if args.dir is None:
os.system('cls')
print("Tidak ada nama folder yang diberikan!")
print("Penggunaan: python main.py <nama_folder>")
sys.exit(1)
else:
os.system('cls')
csv_dir = str(args.dir)
while not validate_dir("data/" + csv_dir):
if validate_dir("data/" + csv_dir):
break
else:
print(f"Folder {csv_dir} tidak ditemukan! Mohon masukkan nama folder yang valid dalam direktori 'data'.")
sys.exit(1)
database = load_data(csv_dir)
user_db = database[0]
monster_db = database[1]
monster_shop_db = database[2]
monster_inv_db = database[3]
item_shop_db = database[4]
item_inv_db = database[5]
# Loading Screen
print("Mohon maximize window command prompt Anda untuk pengalaman terbaik.")
time.sleep(3)
for i in range(5):
remove_nth_line(1)
print(f"Memulai program dalam {5-i} detik...")
time.sleep(1)
remove_nth_line(1)
print("Selesai!")
time.sleep(2)
remove_nth_line(1)
remove_nth_line(1)
def title_screen():
username = ""
logged_in = False
while True:
print_text("data/title_screen.txt")
action = input(">>> ")
remove_nth_line(1)
match lower(action):
case "login":
# os.system('cls')
username = login(user_db)
logged_in = True
print("Berhasil login!")
if user_db["role"][get_idx(username, user_db["username"])] == "admin":
admin_gameplay(user_db, monster_db, monster_shop_db, item_shop_db)
else:
main_gameplay(username, user_db, monster_db, monster_shop_db, monster_inv_db, item_shop_db, item_inv_db)
case "register":
# os.system('cls')
register(user_db)
print("Berhasil register!")
case "menu":
menu(username, logged_in, user_db)
case "save":
# os.system('cls')
save_dir = input("Folder savegame: ")
if not validate_dir('data/' + save_dir):
os.makedirs('data/' + save_dir)
save(user_db, 'data/' + save_dir + '/user.csv')
print("Berhasil menyimpan!")
case "exit":
# os.system('cls')
exit(csv_dir)
break
case _:
continue
## BEDAKAN user_id, user_idx, DAN username!!
## user_id adalah id dari user di database (mulai dari 1)!
## user_idx adalah index dari user di database (mulai dari 0 atau user_id - 1)!
## username adalah username dari user yang sedang login!
def main_gameplay(username, user_db, monster_db, monster_shop_db, monster_inv_db, item_shop_db, item_inv_db):
print("Selamat berpetualang!")
print("Ketik 'help' untuk menerima bantuan.")
user_idx = get_idx(username, user_db["username"])
user_id = user_db["id"][user_idx]
posx, posy = user_db["posx"][user_idx], user_db["posy"][user_idx]
worldmap = read_map(10, 10, "data/map.txt", posx, posy)
oc = user_db["oc"][user_idx]
while True:
print_map(worldmap, 10, 10)
action = input(">>> ")
remove_nth_line(1)
if action == "up" or action == "u":
worldmap, posx, posy = moveUp(worldmap, posx, posy)
elif action == "right" or action == "r":
worldmap, posx, posy = moveRight(worldmap, posx, posy)
elif action == "left" or action == "l":
worldmap, posx, posy = moveLeft(worldmap, posx, posy)
elif action == "down" or action == "d":
worldmap, posx, posy = moveDown(worldmap, posx, posy)
elif action == "inventory":
show_inventory(item_inv_db, monster_inv_db, monster_db, user_id)
elif action == "logout":
print("Berhasil logout!")
title_screen()
break
elif action == "save":
save(user_db, 'data/' + csv_dir + '/user.csv')
print("Berhasil menyimpan!")
elif action == "help":
menu("agent")
elif action == "exit":
exit(csv_dir)
break
elif action == "shop":
if checkProximity(action, posx, posy, worldmap):
monster_inv_db, item_inv_db, monster_shop_db, item_shop_db, oc = shop(monster_inv_db, item_inv_db, monster_shop_db, item_shop_db, monster_db, oc, user_id)
elif action == "battle":
if checkProximity(action, posx, posy, worldmap):
monster_inv_db, item_inv_db, damage_dealt, damage_received = battle(monster_db, monster_inv_db, user_idx, rng(0, 5, time.time()), item_inv_db, oc, "wild")
elif action == "laboratory":
if checkProximity(action, posx, posy, worldmap):
monster_inv_db, oc = laboratory(user_id, monster_db, monster_inv_db, oc)
elif action == "arena":
if checkProximity(action, posx, posy, worldmap):
arena(monster_db, monster_inv_db, user_id, item_inv_db, oc)
elif action == "jackpot":
if checkProximity(action, posx, posy, worldmap):
oc, monster_inv_db = jackpot(oc, user_id, monster_db, monster_inv_db)
elif action == "debug":
print("Username:", username)
print("user_db:", user_db)
print("monster_db:", monster_db)
print("monster_shop_db:", monster_shop_db)
print("monster_inv_db:", monster_inv_db)
print("item_shop_db:", item_shop_db)
print("item_inv_db:", item_inv_db)
print("OC:", oc)
else:
print("Pergerakan tidak valid!")
def admin_gameplay(user_db, monster_db, monster_shop_db, item_shop_db):
print("Selamat datang di kursi admin! ('Kursi ini sangat empuk!', pikirmu.)")
print("Pilihan opsi: monster (untuk monster management), shop (untuk shop management), logout, save, help, dan exit.")
while True:
action = str(input(">>>"))
remove_nth_line(1)
if action == "monster":
monster_management(monster_db)
elif action == "shop":
shop_management(monster_shop_db, item_shop_db)
elif action == "logout":
print("Berhasil logout!")
title_screen()
break
elif action == "save":
save(user_db, 'data/' + csv_dir + '/user.csv')
print("Berhasil menyimpan!")
elif action == "help":
menu("admin")
elif action == "exit":
exit(csv_dir)
elif action == "debug":
print("user_db:", user_db)
print("monster_db:", monster_db)
print("monster_shop_db:", monster_shop_db)
print("item_shop_db:", item_shop_db)
else:
print("Pilihan tidak valid!")
title_screen()