diff --git a/README.md b/README.md
index be6e1e7..80f2a33 100644
--- a/README.md
+++ b/README.md
@@ -2,9 +2,37 @@
> Tugas Besar - IF1210 Dasar Pemrograman 2024
# About
+> Program Game Fungsional Monster
# Contributors
+Jovandra Otniel P. S. (19623032)
+Muhammad Iqbal Haidar (19623242)
+Teresa Dillen Tshia (16523142)
+Muthia Nabilla Azzahra (16523012)
+Syauqi Muhammad Fatih (16523272)
# Features
+Register: Menambah akun baru
+Login: Masuk dengan akun
+Logout: Keluar dari akun
+Help: Menampilkan bantuan berdasarkan role akun (admin/agent)
-# How to Run
\ No newline at end of file
+Inventory: Menampilkan monster dan potion agent
+Battle: Mempertarungkan monster agent dengan monster lawan (CPU)
+Arena: Melatih kekuatan monster agent dengan monster lawan (CPU)
+Shop: Membeli monster dan potion dari toko (agent)
+Lab: Meningkatkan level monster dari agent
+
+Shop Management: Mengubah etalase toko (admin)
+Monster Management: Menambahkan daftar monster di game (admin)
+
+Load: Memuat data CSV dari folder ```data/(nama_folder)```
+Save: Menyimpan data CSV ke folder ```data/(data_folder)```
+Exit: Keluar dari program
+
+# How to Run
+1. Jalankan main.py di terminal dengan perintah ```py main.py dataset_default``` dengan ```dataset_default``` dapat diganti dengan nama folder lain dalam folder ```data```.
+2. Masukkan feature yang ingin dijalankan.
+3. Beberapa fitur memerlukan user login terlebih dahulu.
+4. Beberapa fitur hanya memperbolehkan user dengan role tertentu untuk bisa dijalankan.
+5. Untuk keluar dari game, ketik ```quit``` pada program utama.
diff --git a/data/dataset_default/item_inventory.csv b/data/dataset_default/item_inventory.csv
new file mode 100644
index 0000000..75e0c8a
--- /dev/null
+++ b/data/dataset_default/item_inventory.csv
@@ -0,0 +1,6 @@
+user_id;type;quantity
+2;strength;5
+2;resilience;3
+3;resilience;7
+4;healing;3
+5;strength;20
diff --git a/data/dataset_default/item_shop.csv b/data/dataset_default/item_shop.csv
new file mode 100644
index 0000000..b0800e6
--- /dev/null
+++ b/data/dataset_default/item_shop.csv
@@ -0,0 +1,4 @@
+type;stock;price
+strength;10;50
+resilience;5;30
+healing;3;20
diff --git a/data/dataset_default/monster.csv b/data/dataset_default/monster.csv
new file mode 100644
index 0000000..0902521
--- /dev/null
+++ b/data/dataset_default/monster.csv
@@ -0,0 +1,6 @@
+id;type;atk_power;def_power;hp
+1;Pikachow;125;10;600
+2;Bulbu;50;50;1200
+3;Zeze;300;10;100
+4;Zuko;100;25;800
+5;Chacha;80;30;700
diff --git a/data/dataset_default/monster_inventory.csv b/data/dataset_default/monster_inventory.csv
new file mode 100644
index 0000000..1e1448b
--- /dev/null
+++ b/data/dataset_default/monster_inventory.csv
@@ -0,0 +1,6 @@
+user_id;monster_id;level
+2;1;1
+3;2;2
+3;3;1
+4;4;1
+5;5;5
diff --git a/data/dataset_default/monster_shop.csv b/data/dataset_default/monster_shop.csv
new file mode 100644
index 0000000..3e2f5d0
--- /dev/null
+++ b/data/dataset_default/monster_shop.csv
@@ -0,0 +1,6 @@
+monster_id;stock;price
+1;10;500
+2;4;700
+3;3;1000
+4;8;550
+5;7;600
diff --git a/data/dataset_default/user.csv b/data/dataset_default/user.csv
new file mode 100644
index 0000000..f1b7604
--- /dev/null
+++ b/data/dataset_default/user.csv
@@ -0,0 +1,6 @@
+id;username;password;role;oc
+1;Mr_Monogram;monogrammer77;admin;0
+2;Asep_Spakbor;asepwow123;agent;9999
+3;Agen_P;platypus123;agent;0
+4;B4ngk1dd0ssss;bangkitganteng;agent;1337
+5;Kenny_agen_rahasia;kribogeming55;agent;6699
diff --git a/doc/IF1210_FormAsistensiTB_[1]_K[02-H].docx.pdf b/doc/IF1210_FormAsistensiTB_[1]_K[02-H].docx.pdf
new file mode 100644
index 0000000..a16dd6b
Binary files /dev/null and b/doc/IF1210_FormAsistensiTB_[1]_K[02-H].docx.pdf differ
diff --git a/doc/IF1210_FormAsistensiTB_[2]_K[02-H].docx.pdf b/doc/IF1210_FormAsistensiTB_[2]_K[02-H].docx.pdf
new file mode 100644
index 0000000..5c23793
Binary files /dev/null and b/doc/IF1210_FormAsistensiTB_[2]_K[02-H].docx.pdf differ
diff --git a/doc/IF1210_LaporanTB_K[02-H].pdf b/doc/IF1210_LaporanTB_K[02-H].pdf
new file mode 100644
index 0000000..08a3bbc
Binary files /dev/null and b/doc/IF1210_LaporanTB_K[02-H].pdf differ
diff --git a/main.py b/main.py
index e69de29..8539da0 100644
--- a/main.py
+++ b/main.py
@@ -0,0 +1,80 @@
+from src.F01 import register
+from src.F02 import login
+from src.F03 import logout
+from src.F04 import help
+from src.F05 import custom_zip
+from src.F07 import inventory
+from src.F08 import battle
+from src.F09 import arena
+from src.F10 import shop
+from src.F11 import laboratory
+from src.F12 import shop_management
+from src.F13 import monster_management
+from src.F14 import load
+from src.F15 import save
+from src.F16 import exit_game
+
+li_user, li_monster, li_item, li_item_inventory, li_monster_inventory, li_item_shop, li_monster_shop = load()
+login_id = None # Asumsi user login
+
+while True:
+ a = input("register/login/logout/help/inventory/battle/arena/shop/lab/shop_mgmt/monster_mgmt/save/quit: ").lower()
+ if a == 'register':
+ li_user,li_monster_inventory = register(li_user,li_monster,li_monster_inventory)
+ elif a == 'login':
+ login_id = login(login_id,li_user)
+ elif a == 'logout':
+ login_id = logout(login_id)
+ elif a == 'help':
+ help(login_id,li_user)
+ elif a == 'inventory':
+ inventory(login_id,li_user,li_monster,li_item_inventory,li_monster_inventory)
+ elif a == 'battle':
+ li_user,li_monster,li_item_inventory,li_monster_inventory = battle(login_id,li_user,li_monster,li_item_inventory,li_monster_inventory)
+ elif a == 'arena':
+ li_user,li_monster,li_item_inventory,li_monster_inventory = arena(login_id,li_user,li_monster,li_item_inventory,li_monster_inventory)
+ elif a == 'shop':
+ li_user,li_monster,li_item_inventory,li_monster_inventory,li_item_shop,li_monster_shop = shop(login_id,li_user,li_monster,li_item_inventory,li_monster_inventory,li_item_shop,li_monster_shop)
+ elif a == 'lab':
+ li_user,li_monster_inventory = laboratory(login_id,li_user,li_monster,li_monster_inventory)
+ elif a == 'shop_mgmt':
+ headers = li_user[0]
+ data = []
+ for i in range(1,len(li_user)):
+ data.append(li_user[i])
+ user_data = [dict(custom_zip(headers, row)) for row in data]
+ if login_id:
+ user_login = [u for u in user_data if u['id'] == int(login_id)]
+ if user_login:
+ user_login = user_login[0]
+ role = str(user_login['role']).lower()
+ if role != 'admin':
+ print("Yah, hanya admin saja yang boleh masuk Shop Management.")
+ else:
+ li_monster, li_monster_shop, li_item_shop = shop_management(li_monster, li_item, li_monster_shop, li_item_shop)
+ else:
+ print("Anda belum login!")
+ elif a =='monster_mgmt':
+ headers = li_user[0]
+ data = []
+ for i in range(1,len(li_user)):
+ data.append(li_user[i])
+ user_data = [dict(custom_zip(headers, row)) for row in data]
+ if login_id:
+ user_login = [u for u in user_data if u['id'] == int(login_id)]
+ if user_login:
+ user_login = user_login[0]
+ role = str(user_login['role']).lower()
+ if role != 'admin':
+ print("Yah, hanya admin saja yang boleh masuk Monster Management.")
+ else:
+ li_monster = monster_management(li_monster)
+ else:
+ print("Anda belum login!")
+ elif a == 'save':
+ save(li_user, li_monster, li_item_inventory, li_monster_inventory, li_item_shop, li_monster_shop)
+ elif a == 'quit' or a == 'exit':
+ exit_game(li_user, li_monster, li_item_inventory, li_monster_inventory, li_item_shop, li_monster_shop)
+ else:
+ continue
+
diff --git a/src/F00.py b/src/F00.py
new file mode 100644
index 0000000..e5e17a6
--- /dev/null
+++ b/src/F00.py
@@ -0,0 +1,11 @@
+def random_num(min_value, max_value):
+ import time
+ seed = time.time()
+
+ a = 110351524512
+ c = 12345
+ m = 2**31
+
+ random_number = ((seed * a + c) % m) / (m - 1)
+
+ return int(random_number * (max_value - min_value + 1)) + min_value
\ No newline at end of file
diff --git a/src/F01.py b/src/F01.py
new file mode 100644
index 0000000..8dd3767
--- /dev/null
+++ b/src/F01.py
@@ -0,0 +1,99 @@
+def check_valid(username):
+ acceptable_chars = set("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-")
+ return all(char in acceptable_chars for char in username)
+
+def register(list_user,list_monster,list_monster_inventory):
+ from src.F05 import custom_zip
+ from src.F05 import custom_isdigit
+ list_user = [[str(item) for item in row] for row in list_user]
+ list_monster = [[str(item) for item in row] for row in list_monster]
+ list_monster_inventory = [[str(item) for item in row] for row in list_monster_inventory]
+
+ headers = list_user[0]
+ data = []
+ for i in range(1,len(list_user)):
+ data.append(list_user[i])
+ user_data = [dict(custom_zip(headers, row)) for row in data]
+
+
+ headers = list_monster[0]
+ data = []
+ for i in range(1,len(list_monster)):
+ data.append(list_monster[i])
+ monster_data = [dict(custom_zip(headers, row)) for row in data]
+
+ headers = list_monster_inventory[0]
+ data = []
+ for i in range(1,len(list_monster_inventory)):
+ data.append(list_monster_inventory[i])
+ monster_inventory = [dict(custom_zip(headers, row)) for row in data]
+
+ new_user_id = 1
+ # User input for registration
+ while True:
+ username = input("Masukkan username: ")
+ if not check_valid(username):
+ print("Username hanya boleh mengandung huruf kapital/kecil, angka ,garis bawah _, dan garis hubung -")
+ continue
+ full = False
+ for user in user_data:
+ if user['username'] == username:
+ print("Username sudah terdaftar! Silakan coba masukkan username lain")
+ full = True
+ continue
+ if full:
+ continue
+ password = input("Masukkan password: ")
+ for user in user_data:
+ while user['id'] == str(new_user_id):
+ new_user_id += 1
+ break
+ while True:
+ print("Pilih monster sebagai monster awalmu:")
+ for monster in monster_data:
+ print(f"{monster['id']}. {monster['type']}")
+ monster_benar = False
+ selected_monster_id = input("Masukkan ID monster yang ingin dipilih: ")
+ if not custom_isdigit(selected_monster_id):
+ print("Masukkan format valid!")
+ continue
+ for monster in monster_data:
+ if monster['id'] == str(selected_monster_id):
+ monster_benar = True
+ if not monster_benar:
+ print("Monster ID tidak ada! Silakan masukkan ID monster yang tersedia.")
+ continue
+ new_user = {
+ 'id': str(new_user_id),
+ 'username': username,
+ 'password': password,
+ 'role' : 'agent',
+ 'oc': '0'
+ }
+ user_data.append(new_user)
+
+ # Add selected monster to monster_inventory
+ new_inventory = {
+ 'user_id': new_user_id,
+ 'monster_id': selected_monster_id,
+ 'level': '1'
+ }
+ monster_inventory.append(new_inventory)
+ break
+
+ # Write updated data
+ headers = list(user_data[0].keys())
+ list_user = [headers] + [[d[key] for key in headers] for d in user_data]
+
+ headers = list(monster_inventory[0].keys())
+ list_monster_inventory = [headers] + [[d[key] for key in headers] for d in monster_inventory]
+
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+
+ print(f"User {username} successfully registered with user ID {new_user_id} and selected monster ID {selected_monster_id}")
+ return list_user,list_monster_inventory
+
+# Call the register function to register a new user and update the monster inventory
+# from src.F01 import register
+# li_user,li_monster_inventory = register(li_user,li_monster,li_monster_inventory)
diff --git a/src/F02.py b/src/F02.py
new file mode 100644
index 0000000..9e0a487
--- /dev/null
+++ b/src/F02.py
@@ -0,0 +1,28 @@
+def login(login_id,list_user):
+ if login_id:
+ print("Anda sudah login")
+ return login_id
+ username = input("Masukkan username: ")
+ user_found = False
+ for i in range (0, len(list_user)):
+ if username == list_user[i][1]:
+ user_found = True
+ password = input("Masukkan password: ")
+ if password == list_user[i][2]:
+ print(f"Selamat datang {list_user[i][3]} {list_user[i][1]}")
+ user_id = list_user[i][0]
+ return str(user_id)
+ else:
+ print("Password salah")
+ return None
+ else:
+ continue
+ if not user_found:
+ print("Username tidak ditemukan")
+ return None
+
+
+# Aplikasi pada main.py
+
+# from src.F02 import *
+# login_id = login(li_user) # login_id dipakai sebagai variabel global di main.py untuk menentukan kepemilikan item, akses fungsi tertentu, dan status login user
diff --git a/src/F03.py b/src/F03.py
new file mode 100644
index 0000000..7edec09
--- /dev/null
+++ b/src/F03.py
@@ -0,0 +1,12 @@
+def logout(login_id):
+ if login_id:
+ print("Kamu telah logout")
+ return None
+ else:
+ print("Tidak bisa logout karena kamu belum login")
+ return
+
+# Aplikasi pada main.py
+
+# from src.F03 import *
+# login_id = logout(login_id) # login_id dipakai sebagai variabel global di main.py untuk menentukan kepemilikan item, akses fungsi tertentu, dan status login user
\ No newline at end of file
diff --git a/src/F04.py b/src/F04.py
new file mode 100644
index 0000000..69eca13
--- /dev/null
+++ b/src/F04.py
@@ -0,0 +1,61 @@
+def help(login_id,list_user):
+ from src.F05 import custom_zip
+ list_user = [[str(item) for item in row] for row in list_user]
+
+ headers = list_user[0]
+ data = []
+ for i in range(1,len(list_user)):
+ data.append(list_user[i])
+ user_data = [dict(custom_zip(headers, row)) for row in data]
+ user_data = [u for u in user_data if u['id'] == str(login_id)] # Filter username yang terlogin
+
+ if not login_id: # Jika belum login
+ print("Kamu belum login sebagai role apapun. Silahkan login terlebih dahulu.\n")
+ print("Login: Masuk ke dalam akun yang sudah terdaftar\n")
+ print("Register: Membuat akun baru\n")
+ print("Quit: Keluar dari game\n")
+ print("\nFootnote:")
+ print("Untuk menggunakan aplikasi, silahkan masukkan nama fungsi yang terdaftar\n")
+ print("Jangan lupa untuk memasukkan input yang valid")
+ return
+
+ user_data = user_data[0] # To select the user data dictionary
+
+ role = str(user_data['role']).lower() # Mencari role user
+ if role == 'agent':
+ print("Halo Agent Purry. Kamu memanggil command HELP. \nKamu memilih jalan yang benar, semoga kamu tidak sesat kemudian. \nBerikut adalah hal-hal yang dapat kamu lakukan sekarang:")
+ print("Logout: Keluar dari akun yang sedang digunakan\n")
+ print("Inventory: Melihat owca-dex yang dimiliki oleh Agent\n")
+ print("Battle: Memulai pertarungan dengan monster lain\n")
+ print("Arena: Melatih monster Agent di Arena\n")
+ print("Shop: Melihat dan membeli potion dan monster yang dijual\n")
+ print("Lab: Meningkatkan level monster Agent\n")
+ print("Save: Menyimpan data game\n")
+ print("Quit: Keluar dari game\n")
+ # Add more commands or actions
+ print("\nFootnote:")
+ print("Untuk menggunakan aplikasi, silahkan masukkan nama fungsi yang terdaftar\n")
+ print("Jangan lupa untuk memasukkan input yang valid")
+ elif role == 'admin':
+ print("Selamat datang, Admin. Berikut adalah hal-hal yang dapat lakukan:\n")
+ print("Logout: Keluar dari akun yang sedang digunakan\n")
+ print("Shop_mgmt: Melakukan manajemen pada SHOP sebagai tempat jual beli peralatan Agent\n")
+ print("Monster_mgmt: Melakukan manajemen pada MONSTER yang tersedia di game\n")
+ print("Save: Menyimpan data game\n")
+ print("Quit: Keluar dari game\n")
+ # Add more commands or actions
+ print("\nFootnote:")
+ print("Untuk menggunakan aplikasi, silahkan masukkan nama fungsi yang terdaftar")
+ print("Jangan lupa untuk memasukkan input yang valid")
+ else:
+ print("Kamu belum login sebagai role apapun. Silahkan login terlebih dahulu.")
+ print("Login: Masuk ke dalam akun yang sudah terdaftar")
+ print("Register: Membuat akun baru")
+ print("\nFootnote:")
+ print("Untuk menggunakan aplikasi, silahkan masukkan nama fungsi yang terdaftar")
+ print("Jangan lupa untuk memasukkan input yang valid")
+
+# Aplikasi fungsi help pada file main.py
+
+# from src.F04 import help
+# help(login_id,li_user)
diff --git a/src/F05.py b/src/F05.py
new file mode 100644
index 0000000..86884b1
--- /dev/null
+++ b/src/F05.py
@@ -0,0 +1,59 @@
+def maxi(a,b):
+ if a > b:
+ return a
+ else:
+ return b
+
+def mini(a,b):
+ if a < b:
+ return a
+ else:
+ return b
+
+def custom_zip(*args):
+ def zipper(**attr):
+ return attr
+ iterators = [iter(iterable) for iterable in args]
+ sentinel = zipper()
+
+ while True:
+ result = tuple(next(iterator, sentinel) for iterator in iterators)
+ if any(val is sentinel for val in result):
+ return
+ yield result
+
+def custom_isdigit(s):
+ if isinstance(s, int):
+ return True
+ return all('0' <= char <= '9' for char in str(s))
+
+def adjust(monster):
+ level = int(monster['level'])
+ if level == 1:
+ return monster
+ else:
+ factor = 1 + (int(level) - 1) * 0.1
+ monster['atk_power'] = int(int(monster['atk_power']) * factor)
+ monster['def_power'] = int(int(monster['def_power']) * factor)
+ monster['hp'] = int(int(monster['hp']) * factor)
+ return monster
+
+def attack(attacker, defender): # Fungsi attack untuk F08
+ from src.F00 import random_num
+ n = random_num(-30, 30) # Randomize n from -3 to 3
+ atk_multiplier = 1 + n / 100
+ attacker_atk_power = int(attacker['atk_power']) * atk_multiplier
+ defender_def_power = mini(int(defender['def_power']), 50) # Ensure def power does not exceed 50
+ damage = int(attacker_atk_power * (1 - defender_def_power / 100))
+ defender['hp'] = maxi(int(defender['hp']) - maxi(damage, 0), 0) # Ensure damage is non-negative
+ return attacker,defender
+
+def attack_arena(attacker, defender): # Fungsi attack untuk F09
+ from src.F00 import random_num
+ n = random_num(-30, 30) # Randomize n from -3 to 3
+ atk_multiplier = 1 + n / 100
+ attacker_atk_power = int(attacker['atk_power']) * atk_multiplier
+ defender_def_power = mini(int(defender['def_power']), 50) # Ensure def power does not exceed 50
+ damage = int(attacker_atk_power * (1 - defender_def_power / 100))
+ defender['hp'] = maxi(int(defender['hp']) - maxi(damage, 0), 0) # Ensure damage is non-negative
+ return attacker,defender,damage
diff --git a/src/F06.py b/src/F06.py
new file mode 100644
index 0000000..620288a
--- /dev/null
+++ b/src/F06.py
@@ -0,0 +1,25 @@
+def mini(a,b):
+ if a < b:
+ return a
+ else:
+ return b
+
+def potion(selected_potion_name, selected_user_monster, login_id, potion_inventory,monster_data):
+ for potion in potion_inventory:
+ if potion['user_id'] == login_id and potion['type'] == selected_potion_name:
+ if int(potion['quantity']) > 0:
+ if selected_potion_name.lower() == 'strength':
+ selected_user_monster['atk_power'] = str(int(int(selected_user_monster['atk_power']) * 1.05))
+ potion['quantity'] = str(int(potion['quantity']) - 1)
+ elif selected_potion_name.lower() == 'resilience':
+ selected_user_monster['def_power'] = str(int(int(selected_user_monster['def_power']) * 1.05))
+ potion['quantity'] = str(int(potion['quantity']) - 1)
+ elif selected_potion_name.lower() == 'healing':
+ level = int(selected_user_monster['level'])
+ factor = 1 + (int(level) - 1) * 0.1 # Kapasitas maksimum HP monster dari CSV dikali faktor berdasarkan levelnya
+ monster = [m for m in monster_data if selected_user_monster['id'] == m['id']][0]
+ selected_user_monster['hp'] = str(mini(int(int(selected_user_monster['hp']) * 1.25),int(int(monster["hp"]) * factor)))
+ potion['quantity'] = str(int(potion['quantity']) - 1)
+ else:
+ print("Potion habis")
+ return selected_user_monster, potion_inventory
diff --git a/src/F07.py b/src/F07.py
new file mode 100644
index 0000000..9cd374c
--- /dev/null
+++ b/src/F07.py
@@ -0,0 +1,117 @@
+def inventory(login_id,list_user,list_monster,list_item_inventory,list_monster_inventory):
+ from src.F05 import custom_zip
+ from src.F05 import custom_isdigit
+ def display_shop_items(items):
+ for idx, item in enumerate(items, start=1):
+ print(f"{idx}. {item}")
+ list_user = [[str(item) for item in row] for row in list_user]
+ list_monster = [[str(item) for item in row] for row in list_monster]
+ list_item_inventory = [[str(item) for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[str(item) for item in row] for row in list_monster_inventory]
+
+ headers = list_user[0]
+ data = []
+ for i in range(1,len(list_user)):
+ data.append(list_user[i])
+ user_data = [dict(custom_zip(headers, row)) for row in data]
+
+ user_login = [u for u in user_data if u['id'] == str(login_id)]
+ if user_login:
+ user_login = user_login[0]
+ else:
+ print("User_id tidak terdaftar!")
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster]
+ list_item_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+ return list_user,list_monster,list_item_inventory,list_monster_inventory
+ role = str(user_login['role']).lower()
+ if role != 'agent':
+ print("Yah, hanya agent saja yang boleh masuk Inventory.")
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster]
+ list_item_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+ return list_user,list_monster,list_item_inventory,list_monster_inventory
+
+ headers = list_monster[0]
+ data = []
+ for i in range(1,len(list_monster)):
+ data.append(list_monster[i])
+ monster_data = [dict(custom_zip(headers, row)) for row in data]
+
+ headers = list_item_inventory[0]
+ data = []
+ for i in range(1,len(list_item_inventory)):
+ data.append(list_item_inventory[i])
+ potion_inventory = [dict(custom_zip(headers, row)) for row in data]
+
+ headers = list_monster_inventory[0]
+ data = []
+ for i in range(1,len(list_monster_inventory)):
+ data.append(list_monster_inventory[i])
+ monster_inventory = [dict(custom_zip(headers, row)) for row in data]
+ while True:
+ print(f"Halo, user_id {login_id}, jumlah OWCA Coin Anda {user_login['oc']}")
+ print(">>> Lihat Barang Apa? (potion/monster/quit):")
+ item_type = input().lower()
+ if item_type == "potion":
+ print("Potion yang tersedia: ")
+ potion_info = [f"Nama: {potion['type']}, Jumlah: {potion['quantity']}" for potion in potion_inventory if potion['user_id'] == str(login_id)]
+ if potion_info:
+ display_shop_items(potion_info)
+ else:
+ print("Anda tidak mempunyai potion apapun di inventory")
+ continue
+ print("Pilih nomor urut potion untuk informasi lebih lanjut: ")
+ while True:
+ idx = input()
+ if not custom_isdigit(idx):
+ print("Pilihan tidak valid, silakan masukkan angka")
+ continue
+ idx = int(idx) - 1
+ if idx < 0 or idx > len(potion_info) - 1:
+ print("Pilihan tidak valid, silakan masukkan nomor yang tersedia")
+ continue
+ selected_potion_info = potion_info[idx]
+ print(f"{selected_potion_info}")
+ break
+ elif item_type == "monster":
+ print("Monster yang tersedia: ")
+ monster_inventory_details = []
+ mns_info = []
+ mns_inv = [monster_inventory[i] for i in range(len(monster_inventory)) if monster_inventory[i]['user_id'] == str(login_id)]
+ for monster in mns_inv:
+ monster_info = [m for m in monster_data if m['id'] == monster['monster_id']][0]
+ monster_inventory_details.append(f"{monster['monster_id']}. {monster_info['type']} (HP: {monster_info['hp']})")
+ mns_info.append(f"{monster['monster_id']}. {monster_info['type']} (ATK: {monster_info['atk_power']}, DEF: {monster_info['def_power']}, HP: {monster_info['hp']})")
+ display_shop_items(monster_inventory_details)
+ print("Pilih nomor urut monster untuk informasi lebih lanjut: ")
+ while True:
+ idx = input()
+ if not custom_isdigit(idx):
+ print("Pilihan tidak valid, silakan masukkan angka")
+ continue
+ idx = int(idx) - 1
+ if idx < 0 or idx > len(mns_info) - 1:
+ print("Pilihan tidak valid, silakan masukkan nomor yang tersedia")
+ continue
+ selected_monster_info = mns_info[idx]
+ print(f"{selected_monster_info}")
+ break
+ elif item_type == "quit":
+ break
+ else:
+ continue
+ return
+
+# Aplikasi pada main.py
+
+# Asumsi semua list telah diload
+
+# from src.F07 import *
+# login_id = str(input())
+# if login_id:
+# inventory(login_id,li_user,li_monster,li_item_inventory,li_monster_inventory)
+# else:
+# print("Silakan login dahulu")
diff --git a/src/F08.py b/src/F08.py
new file mode 100644
index 0000000..de65a19
--- /dev/null
+++ b/src/F08.py
@@ -0,0 +1,244 @@
+def battle(login_id,list_user,list_monster,list_item_inventory,list_monster_inventory):
+ from time import sleep
+ from src.F00 import random_num
+ from src.F05 import adjust
+ from src.F05 import attack
+ from src.F05 import custom_zip
+ from src.F05 import custom_isdigit
+ from src.F06 import potion
+ # Konversi List ke Dict
+ list_user = [[str(item) for item in row] for row in list_user]
+ list_monster = [[str(item) for item in row] for row in list_monster]
+ list_item_inventory = [[str(item) for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[str(item) for item in row] for row in list_monster_inventory]
+
+ headers = list_user[0]
+ data = []
+ for i in range(1,len(list_user)):
+ data.append(list_user[i])
+ user_data = [dict(custom_zip(headers, row)) for row in data]
+
+ user_login = [u for u in user_data if u['id'] == str(login_id)]
+ if user_login:
+ user_login = user_login[0]
+ else:
+ print("User_id tidak terdaftar!")
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster]
+ list_item_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+ return list_user,list_monster,list_item_inventory,list_monster_inventory
+ role = str(user_login['role']).lower()
+ if role != 'agent':
+ print("Yah, hanya agent saja yang boleh masuk Battle.")
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster]
+ list_item_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+ return list_user,list_monster,list_item_inventory,list_monster_inventory
+
+ headers = list_monster[0]
+ data = []
+ for i in range(1,len(list_monster)):
+ data.append(list_monster[i])
+ monster_data = [dict(custom_zip(headers, row)) for row in data]
+
+ headers = list_item_inventory[0]
+ data = []
+ for i in range(1,len(list_item_inventory)):
+ data.append(list_item_inventory[i])
+ potion_inventory = [dict(custom_zip(headers, row)) for row in data]
+
+ headers = list_monster_inventory[0]
+ data = []
+ for i in range(1,len(list_monster_inventory)):
+ data.append(list_monster_inventory[i])
+ monster_inventory = [dict(custom_zip(headers, row)) for row in data]
+
+ mns = []
+ for monster_inv in monster_inventory:
+ for monster_data_entry in monster_data:
+ if monster_inv['monster_id'] == monster_data_entry['id']:
+ monster = {**monster_data_entry, 'level': monster_inv['level']} # Combining only the 'level' attribute
+ monster = adjust(monster) # Adjust monster attributes based on level
+ mns.append(monster)
+
+ opponent_idx = random_num(0,len(mns)-1)
+ opponent_monster = mns[opponent_idx]
+ opponent_monster['level'] = str(random_num(1, 5))
+ opponent_monster = adjust(opponent_monster)
+ sleep(1)
+ print("\nMonster Lawan:")
+ print("Nama: ", opponent_monster['type'])
+ print("ATK Power: ", opponent_monster['atk_power'])
+ print("DEF Power: ", opponent_monster['def_power'])
+ print("HP: ", opponent_monster['hp'])
+ print("Level: ", opponent_monster['level'])
+ sleep(1)
+
+ user_monsters = []
+ for monster_inv in monster_inventory:
+ for monster_data_entry in monster_data:
+ if monster_inv['monster_id'] == monster_data_entry['id'] and monster_inv['user_id'] == login_id:
+ monster = {**monster_data_entry, 'level': monster_inv['level']} # Combining only the 'level' attribute
+ monster = adjust(monster) # Adjust monster attributes based on level
+ user_monsters.append(monster)
+ print("\nMonster Anda:")
+ for idx, user_monster in enumerate(user_monsters):
+ print(f"{idx + 1}. Name: {user_monster['type']} | ATK Power: {user_monster['atk_power']} | DEF Power: {user_monster['def_power']} | HP: {user_monster['hp']} | Level: {user_monster['level']}")
+ while True:
+ user_choice = input("\nPilih monster untuk dipertarungkan: ")
+ if custom_isdigit(user_choice):
+ user_choice = int(user_choice) - 1
+ if len(user_monsters) - 1 >= user_choice:
+ break
+
+ selected_user_monster = user_monsters[user_choice]
+ print("\nAnda memilih:")
+ print("Nama: ", selected_user_monster['type'])
+ print("ATK Power: ", selected_user_monster['atk_power'])
+ print("DEF Power: ", selected_user_monster['def_power'])
+ print("HP: ", selected_user_monster['hp'])
+ print("Level: ", selected_user_monster['level'])
+ sleep(1)
+
+
+
+ is_strength_used = False
+ is_healing_used = False
+ is_resilience_used = False
+ user_quit = False
+ ronde = 0
+ while int(opponent_monster['hp']) > 0 and int(selected_user_monster['hp']) > 0:
+ sleep(1)
+ print(f"\nRONDE {ronde + 1}")
+ sleep(1)
+ print("\nGiliran Anda menyerang monster lawan!")
+ sleep(1)
+ action = input("Pilih aksi Anda - Attack, Potion, Quit: ").lower()
+
+ if action == 'attack':
+ selected_user_monster,opponent_monster = attack(selected_user_monster, opponent_monster)
+ print(f"{selected_user_monster['type']} menyerang monster {opponent_monster['type']}. HYAH!")
+ sleep(1)
+ print(f"MONSTER LAWAN ({opponent_monster['type']}): ")
+ print(f"ATK Power: {opponent_monster['atk_power']}")
+ print(f"DEF Power: {opponent_monster['def_power']}")
+ print(f"HP: {opponent_monster['hp']}")
+ print(f"Level: {opponent_monster['level']}")
+ sleep(1)
+ if opponent_monster['hp'] <= 0:
+ break
+ elif action == 'potion':
+ print("\nPotion Tersedia:")
+ user_potions = [potion for potion in potion_inventory if potion['user_id'] == login_id]
+ if not user_potions:
+ print("Anda tidak mempunyai potion apapun")
+ continue
+ for idx, user_potion in enumerate(user_potions):
+ print(f"{idx + 1}. {user_potion['type']} - Quantity: {user_potion['quantity']}")
+ while True:
+ potion_choice = input("\nPilih potion yang akan digunakan: ")
+ if custom_isdigit(potion_choice):
+ potion_choice = int(potion_choice) - 1
+ if potion_choice <= len(user_potions) - 1:
+ break
+ selected_potion = user_potions[potion_choice]['type']
+
+ if selected_potion == 'strength' and not is_strength_used:
+ selected_user_monster,potion_inventory = potion(selected_potion, selected_user_monster, login_id, potion_inventory, monster_data)
+ is_strength_used = True
+ elif selected_potion == 'healing' and not is_healing_used:
+ selected_user_monster,potion_inventory = potion(selected_potion, selected_user_monster, login_id, potion_inventory, monster_data)
+ is_healing_used = True
+ elif selected_potion == 'resilience' and not is_resilience_used:
+ selected_user_monster,potion_inventory = potion(selected_potion, selected_user_monster, login_id, potion_inventory, monster_data)
+ is_resilience_used = True
+ else:
+ print("You cannot use that potion again in this battle.")
+ print("\nMonster Anda:")
+ print("Name: ", selected_user_monster['type'])
+ print("ATK Power: ", selected_user_monster['atk_power'])
+ print("DEF Power: ", selected_user_monster['def_power'])
+ print("HP: ", selected_user_monster['hp'])
+ print("Level: ", selected_user_monster['level'])
+ sleep(1)
+ continue
+ elif action == 'quit':
+ user_quit = True
+ break
+ else:
+ continue
+ if not user_quit:
+ print(f"Sekarang giliran monster {opponent_monster['type']} melawan monstermu! HYAH!")
+ opponent_monster,selected_user_monster = attack(opponent_monster, selected_user_monster)
+ sleep(1)
+ print(f"MONSTER ANDA ({selected_user_monster['type']}): ")
+ print(f"atk Power: {selected_user_monster['atk_power']}")
+ print(f"def Power: {selected_user_monster['def_power']}")
+ print(f"HP: {selected_user_monster['hp']}")
+ print(f"Level: {selected_user_monster['level']}")
+ sleep(1)
+ if opponent_monster['hp'] <= 0:
+ break
+ else:
+ ronde += 1
+ if not user_quit:
+ if opponent_monster['hp'] <= 0:
+ oc_coin = random_num(10, 100)
+ for user in user_data:
+ if user['id'] == login_id:
+ user['oc'] = str(int(user['oc']) + oc_coin)
+ print(f"Selamat, Anda Menang! Anda memperoleh {oc_coin} OC coins!")
+ # Konversi balik ke List of List untuk menyimpan data
+ headers = list(user_data[0].keys())
+ list_user = [headers] + [[d[key] for key in headers] for d in user_data]
+
+ headers = list(monster_data[0].keys())
+ list_monster = [headers] + [[d[key] for key in headers] for d in monster_data]
+
+ headers = list(potion_inventory[0].keys())
+ list_item_inventory = [headers] + [[d[key] for key in headers] for d in potion_inventory]
+
+ headers = list(monster_inventory[0].keys())
+ list_monster_inventory = [headers] + [[d[key] for key in headers] for d in monster_inventory]
+
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster]
+ list_item_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+
+ return list_user,list_monster,list_item_inventory,list_monster_inventory
+ else:
+ print("Yah, Anda dikalahkan monster lawan! Jangan menyerah, terus kembangkan monstermu!")
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster]
+ list_item_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+ return list_user,list_monster,list_item_inventory,list_monster_inventory
+ else:
+ print("Anda berhasil kabur dari pertarungan!")
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster]
+ list_item_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+ return list_user,list_monster,list_item_inventory,list_monster_inventory
+
+# Aplikasi pada main.py
+
+# Asumsi semua list telah diload sebelumnya
+
+# list_user = [['id', 'username', 'password', 'role', 'oc'], ['12345', 'abc', 'koolabis', 'agent', '1500'], ['54321', 'aasd', 'rgerwfa', 'admin', '1500']]
+# list_monster = [['id', 'type', 'atk_power', 'def_power', 'hp'], ['67890', 'pokemon', '200', '25', '500'], ['11111', 'pikachu', '245', '23', '245'], ['22222', 'charmander', '180', '20', '220'], ['33333', 'squirtle', '190', '22', '210'], ['44444', 'bulbasaur', '210', '19', '230'], ['55555', 'jigglypuff', '150', '18', '200'], ['66666', 'eevee', '170', '16', '190'], ['77777', 'snorlax', '250', '30', '350'], ['88888', 'gengar', '230', '10', '260']]
+# list_item_inventory = [['user_id', 'type', 'quantity'], ['12345', 'strength', '5'], ['12345', 'healing', '5'], ['12345', 'resilience', '5']]
+# list_monster_inventory = [['user_id', 'monster_id', 'level'], ['12345', '67890', '1'], ['12345', '55555', '2'], ['54321', '77777', '3']]
+
+# Asumsi user sudah login (login_id terdefinisi sebagai sebuah string)
+# File F08.py disimpan di folder src
+
+# from src.F08 import *
+# login_id = str(input())
+# if login_id:
+# li_user,li_monster,li_item_inventory,li_monster_inventory = battle(login_id,li_user,li_monster,li_item_inventory,li_monster_inventory)
+# else:
+# print("Silakan login dahulu")
diff --git a/src/F09.py b/src/F09.py
new file mode 100644
index 0000000..e84a91a
--- /dev/null
+++ b/src/F09.py
@@ -0,0 +1,259 @@
+def arena(login_id,list_user,list_monster,list_item_inventory,list_monster_inventory):
+ from time import sleep
+ from src.F00 import random_num
+ from src.F05 import adjust
+ from src.F05 import attack_arena
+ from src.F05 import custom_zip
+ from src.F05 import custom_isdigit
+ from src.F06 import potion
+
+
+ # Konversi List ke Dict
+ list_user = [[str(item) for item in row] for row in list_user]
+ list_monster = [[str(item) for item in row] for row in list_monster]
+ list_item_inventory = [[str(item) for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[str(item) for item in row] for row in list_monster_inventory]
+
+ headers = list_user[0]
+ data = []
+ for i in range(1,len(list_user)):
+ data.append(list_user[i])
+ user_data = [dict(custom_zip(headers, row)) for row in data]
+
+ user_login = [u for u in user_data if u['id'] == str(login_id)]
+ if user_login:
+ user_login = user_login[0]
+ else:
+ print("User_id tidak terdaftar!")
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster]
+ list_item_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+ return list_user,list_monster,list_item_inventory,list_monster_inventory
+ role = str(user_login['role']).lower()
+ if role != 'agent':
+ print("Yah, hanya agent saja yang boleh masuk Arena.")
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster]
+ list_item_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+ return list_user,list_monster,list_item_inventory,list_monster_inventory
+
+ headers = list_monster[0]
+ data = []
+ for i in range(1,len(list_monster)):
+ data.append(list_monster[i])
+ monster_data = [dict(custom_zip(headers, row)) for row in data]
+
+ headers = list_item_inventory[0]
+ data = []
+ for i in range(1,len(list_item_inventory)):
+ data.append(list_item_inventory[i])
+ potion_inventory = [dict(custom_zip(headers, row)) for row in data]
+
+ headers = list_monster_inventory[0]
+ data = []
+ for i in range(1,len(list_monster_inventory)):
+ data.append(list_monster_inventory[i])
+ monster_inventory = [dict(custom_zip(headers, row)) for row in data]
+
+
+
+ user_monsters = []
+ for monster_inv in monster_inventory:
+ for monster_data_entry in monster_data:
+ if monster_inv['monster_id'] == monster_data_entry['id'] and monster_inv['user_id'] == login_id:
+ monster = {**monster_data_entry, 'level': monster_inv['level']} # Combining only the 'level' attribute
+ monster = adjust(monster) # Adjust monster attributes based on level
+ user_monsters.append(monster)
+ print("\nMonster Anda:")
+ for idx, user_monster in enumerate(user_monsters):
+ print(f"{idx + 1}. Name: {user_monster['type']} | ATK Power: {user_monster['atk_power']} | DEF Power: {user_monster['def_power']} | HP: {user_monster['hp']} | Level: {user_monster['level']}")
+ while True:
+ user_choice = input("\nPilih monster untuk dipertarungkan: ")
+ if custom_isdigit(user_choice):
+ user_choice = int(user_choice) - 1
+ if len(user_monsters) - 1 >= user_choice:
+ break
+ selected_user_monster = user_monsters[user_choice]
+ print("\nAnda memilih:")
+ print("Nama: ", selected_user_monster['type'])
+ print("ATK Power: ", selected_user_monster['atk_power'])
+ print("DEF Power: ", selected_user_monster['def_power'])
+ print("HP: ", selected_user_monster['hp'])
+ print("Level: ", selected_user_monster['level'])
+ sleep(1)
+
+
+ oc_coin = 0
+ stage = 0
+ attacks = 0
+ defends = 0
+ user_quit = False
+ ronde = 0
+ while stage <= 4 and not user_quit:
+ mns = []
+ for monster_inv in monster_inventory:
+ for monster_data_entry in monster_data:
+ if monster_inv['monster_id'] == monster_data_entry['id']:
+ monster = {**monster_data_entry, 'level': monster_inv['level']} # Combining only the 'level' attribute
+ monster = adjust(monster) # Adjust monster attributes based on level
+ mns.append(monster)
+ opponent_idx = random_num(0,len(mns)-1)
+ opponent_monster = mns[opponent_idx]
+ opponent_monster['level'] = str(stage + 1)
+ opponent_monster = adjust(opponent_monster)
+ print(f"---------- STAGE {stage + 1} ----------")
+ sleep(1)
+ print("\nMonster Lawan:")
+ print("Nama: ", opponent_monster['type'])
+ print("ATK Power: ", opponent_monster['atk_power'])
+ print("DEF Power: ", opponent_monster['def_power'])
+ print("HP: ", opponent_monster['hp'])
+ print("Level: ", opponent_monster['level'])
+ sleep(1)
+ is_strength_used = False
+ is_healing_used = False
+ is_resilience_used = False
+ while int(opponent_monster['hp']) > 0 and int(selected_user_monster['hp']) > 0:
+ sleep(1)
+ print(f"\nRONDE {ronde + 1}")
+ sleep(1)
+ print("\nGiliran Anda menyerang monster lawan!")
+ sleep(1)
+ action = input("Pilih aksi Anda - Attack, Potion, Quit: ").lower()
+
+ if action == 'attack':
+ selected_user_monster,opponent_monster,damage = attack_arena(selected_user_monster, opponent_monster)
+ attacks += damage
+ print(f"{selected_user_monster['type']} menyerang monster {opponent_monster['type']}. HYAH!")
+ sleep(1)
+ print(f"MONSTER LAWAN ({opponent_monster['type']}): ")
+ print(f"ATK Power: {opponent_monster['atk_power']}")
+ print(f"DEF Power: {opponent_monster['def_power']}")
+ print(f"HP: {opponent_monster['hp']}")
+ print(f"Level: {opponent_monster['level']}")
+ sleep(1)
+ if opponent_monster['hp'] <= 0:
+ break
+ elif action == 'potion':
+ print("\nPotion Tersedia:")
+ user_potions = [potion for potion in potion_inventory if potion['user_id'] == login_id]
+ if not user_potions:
+ print("Anda tidak mempunyai potion apapun")
+ continue
+ for idx, user_potion in enumerate(user_potions):
+ print(f"{idx + 1}. {user_potion['type']} - Quantity: {user_potion['quantity']}")
+ while True:
+ potion_choice = input("\nPilih potion yang akan digunakan: ")
+ if custom_isdigit(potion_choice):
+ potion_choice = int(potion_choice) - 1
+ if potion_choice <= len(user_potions) - 1:
+ break
+ selected_potion = user_potions[potion_choice]['type']
+
+ if selected_potion == 'strength' and not is_strength_used:
+ selected_user_monster,potion_inventory = potion(selected_potion, selected_user_monster, login_id, potion_inventory, monster_data)
+ is_strength_used = True
+ elif selected_potion == 'healing' and not is_healing_used:
+ selected_user_monster,potion_inventory = potion(selected_potion, selected_user_monster, login_id, potion_inventory, monster_data)
+ is_healing_used = True
+ elif selected_potion == 'resilience' and not is_resilience_used:
+ selected_user_monster,potion_inventory = potion(selected_potion, selected_user_monster, login_id, potion_inventory, monster_data)
+ is_resilience_used = True
+ else:
+ print("You cannot use that potion again in this battle.")
+ print("\nMonster Anda:")
+ print("Name: ", selected_user_monster['type'])
+ print("ATK Power: ", selected_user_monster['atk_power'])
+ print("DEF Power: ", selected_user_monster['def_power'])
+ print("HP: ", selected_user_monster['hp'])
+ print("Level: ", selected_user_monster['level'])
+ sleep(1)
+ continue
+ elif action == 'quit':
+ user_quit = True
+ break
+ else:
+ continue
+ if not user_quit:
+ print(f"Sekarang giliran monster {opponent_monster['type']} melawan monstermu! HYAH!")
+ opponent_monster,selected_user_monster,damage = attack_arena(opponent_monster, selected_user_monster)
+ defends += damage
+ sleep(1)
+ print(f"MONSTER ANDA ({selected_user_monster['type']}): ")
+ print(f"atk Power: {selected_user_monster['atk_power']}")
+ print(f"def Power: {selected_user_monster['def_power']}")
+ print(f"HP: {selected_user_monster['hp']}")
+ print(f"Level: {selected_user_monster['level']}")
+ sleep(1)
+ if selected_user_monster['hp'] <= 0:
+ break
+ else:
+ ronde += 1
+ else:
+ break
+ if not user_quit:
+ if opponent_monster['hp'] <= 0:
+ oc_coin += 10*(stage+1)^2
+ print(f"Selamat, Anda Lolos Stage {stage + 1} ! Anda memperoleh {oc_coin} OC coins!")
+ stage += 1
+ else:
+ break
+
+ if user_quit:
+ print("Anda berhasil kabur dari pertarungan!")
+ elif stage == 5:
+ print("Selamat, Anda berhasil melalui kelima stage arena ini.")
+ elif 0 < stage < 5:
+ print(f"Selamat, Anda telah menempuh stage {stage}. Semangat!")
+ else:
+ print("Yah, monster Anda kalah putaran pertama. Semangat, pasti bisa!")
+
+ print("\n---------- STATS ----------")
+ print(f"Jumlah stage lolos: {stage}")
+ print(f"Total hadiah koin: {oc_coin} OC")
+ print(f"Serangan diberikan: {attacks}") # Serangan bersih user terhadap lawan
+ print(f"Serangan diterima: {defends}") # Serangan bersih lawan terhadap user
+
+ for user in user_data:
+ if user['id'] == login_id:
+ user['oc'] = str(int(user['oc']) + oc_coin)
+ # Konversi balik ke List of List untuk menyimpan data
+ headers = list(user_data[0].keys())
+ list_user = [headers] + [[d[key] for key in headers] for d in user_data]
+
+ headers = list(monster_data[0].keys())
+ list_monster = [headers] + [[d[key] for key in headers] for d in monster_data]
+
+ headers = list(potion_inventory[0].keys())
+ list_item_inventory = [headers] + [[d[key] for key in headers] for d in potion_inventory]
+
+ headers = list(monster_inventory[0].keys())
+ list_monster_inventory = [headers] + [[d[key] for key in headers] for d in monster_inventory]
+
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster]
+ list_item_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+
+ return list_user,list_monster,list_item_inventory,list_monster_inventory
+
+# Aplikasi pada main.py
+
+# Asumsi semua list telah diload sebelumnya
+
+# list_user = [['id', 'username', 'password', 'role', 'oc'], ['12345', 'abc', 'koolabis', 'agent', '1500'], ['54321', 'aasd', 'rgerwfa', 'admin', '1500']]
+# list_monster = [['id', 'type', 'atk_power', 'def_power', 'hp'], ['67890', 'pokemon', '200', '25', '500'], ['11111', 'pikachu', '245', '23', '245'], ['22222', 'charmander', '180', '20', '220'], ['33333', 'squirtle', '190', '22', '210'], ['44444', 'bulbasaur', '210', '19', '230'], ['55555', 'jigglypuff', '150', '18', '200'], ['66666', 'eevee', '170', '16', '190'], ['77777', 'snorlax', '250', '30', '350'], ['88888', 'gengar', '230', '10', '260']]
+# list_item_inventory = [['user_id', 'type', 'quantity'], ['12345', 'strength', '5'], ['12345', 'healing', '5'], ['12345', 'resilience', '5']]
+# list_monster_inventory = [['user_id', 'monster_id', 'level'], ['12345', '67890', '1'], ['12345', '55555', '2'], ['54321', '77777', '3']]
+
+# Asumsi user sudah login (login_id terdefinisi sebagai sebuah string)
+# File F08.py disimpan di folder src
+
+# from src.F09 import *
+# login_id = str(input())
+# if login_id:
+# li_user,li_monster,li_item_inventory,li_monster_inventory = arena(login_id,li_user,li_monster,li_item_inventory,li_monster_inventory)
+# else:
+# print("Silakan login dahulu")
diff --git a/src/F10.py b/src/F10.py
new file mode 100644
index 0000000..18f71e0
--- /dev/null
+++ b/src/F10.py
@@ -0,0 +1,249 @@
+def shop(login_id,list_user,list_monster,list_item_inventory,list_monster_inventory,list_item_shop,list_monster_shop):
+ from src.F05 import custom_zip
+ from src.F05 import custom_isdigit
+ list_user = [[str(item) for item in row] for row in list_user]
+ list_monster = [[str(item) for item in row] for row in list_monster]
+ list_item_inventory = [[str(item) for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[str(item) for item in row] for row in list_monster_inventory]
+ list_item_shop = [[str(item) for item in row] for row in list_item_shop]
+ list_monster_shop = [[str(item) for item in row] for row in list_monster_shop]
+ # Konversi 'List of List' ke 'List of Dict' untuk pemrosesan data
+ headers = list_user[0]
+ data = []
+ for i in range(1,len(list_user)):
+ data.append(list_user[i])
+ user_data = [dict(custom_zip(headers, row)) for row in data]
+
+ user_login = [u for u in user_data if u['id'] == str(login_id)]
+ if not user_login:
+ print("User_id tidak terdaftar!")
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster]
+ list_item_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+ list_item_shop = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_shop]
+ list_monster_shop = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_shop]
+ return list_user,list_monster,list_item_inventory,list_monster_inventory,list_item_shop,list_monster_shop
+ user_login = user_login[0]
+ role = str(user_login['role']).lower()
+ if role != 'agent':
+ print("Yah, hanya agent saja yang boleh masuk Shop and Currency.")
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster]
+ list_item_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+ list_item_shop = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_shop]
+ list_monster_shop = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_shop]
+ return list_user,list_monster,list_item_inventory,list_monster_inventory,list_item_shop,list_monster_shop
+
+ headers = list_monster[0]
+ data = []
+ for i in range(1,len(list_monster)):
+ data.append(list_monster[i])
+ monster_data = [dict(custom_zip(headers, row)) for row in data]
+
+ headers = list_item_inventory[0]
+ data = []
+ for i in range(1,len(list_item_inventory)):
+ data.append(list_item_inventory[i])
+ potion_inventory = [dict(custom_zip(headers, row)) for row in data]
+
+ headers = list_monster_inventory[0]
+ data = []
+ for i in range(1,len(list_monster_inventory)):
+ data.append(list_monster_inventory[i])
+ monster_inventory = [dict(custom_zip(headers, row)) for row in data]
+
+ headers = list_item_shop[0]
+ data = []
+ for i in range(1,len(list_item_shop)):
+ data.append(list_item_shop[i])
+ potion_shop = [dict(custom_zip(headers, row)) for row in data]
+
+ headers = list_monster_shop[0]
+ data = []
+ for i in range(1,len(list_monster_shop)):
+ data.append(list_monster_shop[i])
+ monster_shop = [dict(custom_zip(headers, row)) for row in data]
+
+ def display_shop_items(items):
+ for idx, item in enumerate(items, start=1):
+ print(f"{idx}. {item}")
+
+ # Iterasi Shop and Currency oleh User
+ while True:
+ print("\n>>> Selamat datang di Toko Mr. Yanto! Pilih aksi (beli/lihat/keluar):")
+ action = input().lower()
+
+ if action == "lihat":
+ while True:
+ print(">>> Mau lihat apa? (potion/monster):")
+ item_type = input().lower()
+ if item_type == "potion":
+ print("\nPotion yang tersedia: ")
+ display_shop_items([f"{potion['type']} (Stok: {potion['stock']}, Harga: {potion['price']} koin)" for potion in potion_shop])
+ break
+ elif item_type == "monster":
+ print("\nMonster yang tersedia: ")
+ monster_shop_details = []
+ for monster in monster_shop:
+ monster_info = [m for m in monster_data if m['id'] == monster['monster_id']][0]
+ monster_shop_details.append(f"{monster['monster_id']}. {monster_info['type']} (ATK: {monster_info['atk_power']}, DEF: {monster_info['def_power']}, HP: {monster_info['hp']}, Stok: {monster['stock']}, Harga: {monster['price']} koin)")
+ display_shop_items(monster_shop_details)
+ break
+ else:
+ continue
+
+ elif action == "beli":
+ user_id = str(login_id)
+ print(f"Username Anda: {user_id}")
+ while True:
+ print(">>> Mau beli apa? (potion/monster):")
+ item_type = input().lower()
+
+ if item_type == "potion":
+ while True:
+ for user in user_data:
+ if user['id'] == user_id:
+ user_coins = int(user['oc'])
+ print(f"Jumlah koin Anda: {user['oc']}")
+ print("\nPotion yang dijual:")
+ display_shop_items([f"{potion['type']} (Stok: {potion['stock']}, Harga: {potion['price']} koin)" for potion in potion_shop])
+
+ print(">>> Pilih nomor urut potion yang ingin dibeli:")
+ idx = input()
+ if not custom_isdigit(idx):
+ print("Pilihan tidak valid. Silakan masukkan format yang benar.")
+ continue
+ selected_potion_idx = int(idx) - 1
+ if selected_potion_idx > len(potion_shop) - 1:
+ print("Pilihan tidak valid, silakan masukkan nomor pilihan yang tersedia")
+ continue
+ quantity = input("Masukkan banyaknya potion yang ingin dibeli: ")
+ if not custom_isdigit(quantity):
+ print("Pilihan tidak valid. Silakan masukkan format yang benar.")
+ continue
+ quantity = int(quantity)
+ selected_potion = potion_shop[selected_potion_idx]
+ if int(selected_potion['stock']) > 0 and int(selected_potion['stock']) - quantity >= 0:
+ for user in user_data:
+ if user['id'] == user_id:
+ user_coins = int(user['oc'])
+ if user_coins >= int(selected_potion['price']) * quantity:
+ user_coins -= int(selected_potion['price']) * quantity
+ selected_potion_name = selected_potion['type']
+ user_potion = [p for p in potion_inventory if p['user_id'] == user_id and p['type'] == selected_potion_name]
+ if user_potion:
+ user_potion[0]['quantity'] = str(int(user_potion[0]['quantity']) + quantity)
+ else:
+ potion_inventory.append({'user_id': user_id, 'type': selected_potion_name, 'quantity': f'{quantity}'})
+ selected_potion['stock'] = str(int(selected_potion['stock']) - quantity)
+ user['oc'] = str(user_coins)
+ print(f"\nBerhasil membeli {selected_potion_name}.")
+ else:
+ print("\nKoin Anda tidak mencukupi.")
+ break
+ break
+
+ else:
+ print("\nStok potion habis atau tidak mencukupi.")
+ break
+ break
+
+ elif item_type == "monster":
+ for user in user_data:
+ if user['id'] == user_id:
+ user_coins = int(user['oc'])
+ print(f"Jumlah koin Anda: {user['oc']}")
+ print("\nMonster yang dijual:")
+ monster_shop_details = []
+ for monster in monster_shop:
+ monster_info = [m for m in monster_data if m['id'] == monster['monster_id']][0]
+ monster_shop_details.append(f"{monster['monster_id']}. {monster_info['type']} (ATK: {monster_info['atk_power']}, DEF: {monster_info['def_power']}, HP: {monster_info['hp']}, Stok: {monster['stock']}, Harga: {monster['price']} koin)")
+ display_shop_items(monster_shop_details)
+ while True:
+ print(">>> Pilih nomor urut monster yang ingin dibeli:")
+ idx = input()
+ if not custom_isdigit(idx):
+ print("Pilihan tidak valid. Silakan masukkan format yang benar.")
+ continue
+ selected_monster_idx = int(idx) - 1
+ if selected_monster_idx > len(monster_shop) - 1:
+ print("Pilihan tidak valid, silakan masukkan nomor pilihan yang tersedia")
+ continue
+ selected_monster = monster_shop[selected_monster_idx]
+ existing_monster = [m for m in monster_inventory if m['user_id'] == user_id and m['monster_id'] == selected_monster['monster_id']]
+ if int(selected_monster['stock']) > 0:
+ if existing_monster:
+ print("Anda sudah memiliki monster ini.")
+ else:
+ for user in user_data:
+ if user['id'] == user_id:
+ user_coins = int(user['oc'])
+ if int(selected_monster['price']) < user_coins:
+ user_coins -= int(selected_monster['price'])
+ monster_inventory.append({'user_id': user_id, 'monster_id': selected_monster['monster_id'], 'level': '1'})
+ selected_monster['stock'] = str(int(selected_monster['stock']) - 1)
+ user['oc'] = str(user_coins)
+ print("\nBerhasil membeli monster.")
+ else:
+ print("\nKoin tidak mencukupi.")
+ break
+ break
+ break
+
+ else:
+ print("\nPilihan tidak valid. Silakan coba lagi.")
+ continue
+
+ elif action == "keluar":
+ print("Terima kasih telah berbelanja. Sampai jumpa lagi!")
+
+ # Konversi balik ke List of List untuk menyimpan data
+ headers = list(user_data[0].keys())
+ list_user = [headers] + [[d[key] for key in headers] for d in user_data]
+
+ headers = list(monster_data[0].keys())
+ list_monster = [headers] + [[d[key] for key in headers] for d in monster_data]
+
+ headers = list(potion_inventory[0].keys())
+ list_item_inventory = [headers] + [[d[key] for key in headers] for d in potion_inventory]
+
+ headers = list(monster_inventory[0].keys())
+ list_monster_inventory = [headers] + [[d[key] for key in headers] for d in monster_inventory]
+
+ headers = list(potion_shop[0].keys())
+ list_item_shop = [headers] + [[d[key] for key in headers] for d in potion_shop]
+
+ headers = list(monster_shop[0].keys())
+ list_monster_shop = [headers] + [[d[key] for key in headers] for d in monster_shop]
+ break
+ else:
+ continue
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster]
+ list_item_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_inventory]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+ list_item_shop = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_item_shop]
+ list_monster_shop = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_shop]
+ return list_user,list_monster,list_item_inventory,list_monster_inventory,list_item_shop,list_monster_shop
+
+# APLIKASI FUNGSI shop() PADA main.py
+
+# Asumsi list sudah diload dari CSV sebelumnya
+
+# list_user = [['id', 'username', 'password', 'role', 'oc'], ['12345', 'abc', 'koolabis', 'agent', '1500'], ['54321', 'def', 'rgerwfa', 'admin', '1500']]
+# list_monster = [['id', 'type', 'atk_power', 'def_power', 'hp'], ['67890', 'pokemon', '200', '250', '500'], ['11111', 'pikachu', '245', '235', '245']]
+# list_item_inventory = [['user_id', 'type', 'quantity'], ['12345', 'power', '1']]
+# list_monster_inventory = [['user_id', 'monster_id', 'level'], ['12345', '67890', '1']]
+# list_item_shop = [['type', 'stock', 'price'], ['power', '5', '100']]
+# list_monster_shop = [['monster_id', 'stock', 'price'], ['67890', '5', '700'], ['11111', '5', '500']]
+
+# Asumsi username sudah ada (user sudah login)
+
+# from src.F10 import shop
+# login_id = int(input())
+# if login_id:
+# li_user,li_monster,li_item_inventory,li_monster_inventory,li_item_shop,li_monster_shop = shop(login_id,li_user,li_monster,li_item_inventory,li_monster_inventory,li_item_shop,li_monster_shop)
+# else:
+# print("Anda belum login. Silakan login dahulu.")
diff --git a/src/F11.py b/src/F11.py
new file mode 100644
index 0000000..f94ac20
--- /dev/null
+++ b/src/F11.py
@@ -0,0 +1,140 @@
+def laboratory(login_id,list_user,list_monster,list_monster_inventory):
+ from src.F05 import custom_isdigit
+ from src.F05 import custom_zip
+ list_user = [[str(item) for item in row] for row in list_user]
+ list_monster = [[str(item) for item in row] for row in list_monster]
+ list_monster_inventory = [[str(item) for item in row] for row in list_monster_inventory]
+
+ headers = list_user[0]
+ data = []
+ for i in range(1,len(list_user)):
+ data.append(list_user[i])
+ user_data = [dict(custom_zip(headers, row)) for row in data]
+
+ user_login = [u for u in user_data if u['id'] == str(login_id)]
+ if user_login:
+ user_login = user_login[0]
+ else:
+ print("User_id tidak terdaftar!")
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+ return list_user,list_monster_inventory
+ role = str(user_login['role']).lower()
+ if role != 'agent':
+ print("Yah, hanya agent saja yang boleh masuk Laboratory.")
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+ return list_user,list_monster_inventory
+
+ headers = list_monster[0]
+ data = []
+ for i in range(1,len(list_monster)):
+ data.append(list_monster[i])
+ monster_data = [dict(custom_zip(headers, row)) for row in data]
+
+ headers = list_monster_inventory[0]
+ data = []
+ for i in range(1,len(list_monster_inventory)):
+ data.append(list_monster_inventory[i])
+ monster_inventory = [dict(custom_zip(headers, row)) for row in data]
+ while True:
+ # Menampilkan monster yang dimiliki agent
+ print("============ MONSTER LIST ============")
+ index = 1
+ user_monsters = [monster for monster in monster_inventory if monster['user_id'] == login_id]
+ for monster in user_monsters:
+ monster_id = monster['monster_id']
+ level = monster['level']
+
+ # Mencari nama monster yang dimiliki
+ monster_name = ""
+ for monster in monster_data:
+ if monster['id'] == monster_id:
+ monster_name = monster['type']
+ break
+
+ # Menampilkan nama monster dan levelnya
+ print(f"{index}. {monster_name} (Level: {level})")
+ index += 1
+
+ # Menampilkan daftar harga untuk upgrade
+ print("\n============ UPGRADE PRICE ============")
+ print("1. Level 1 -> Level 2: 300 OC")
+ print("2. Level 2 -> Level 3: 500 OC")
+ print("3. Level 3 -> Level 4: 800 OC")
+ print("4. Level 4 -> Level 5: 1000 OC")
+
+ # Meminta input pilihan monster
+ monster_choice = (input(">>> Pilih monster: "))
+ if not custom_isdigit(monster_choice):
+ print("Format tidak valid")
+ continue
+ monster_choice = int(monster_choice)
+
+ # Cek Validasi
+ if monster_choice < 1 or monster_choice > len(user_monsters):
+ print("Pilihan monster tidak valid. Silakan pilih lagi.\n")
+ continue
+
+ # Mencari data monster yang dimiliki user
+ selected_monster_data = user_monsters[monster_choice - 1]
+ monster_id = selected_monster_data['monster_id']
+ current_level = int(selected_monster_data['level'])
+
+ # Menghitung biaya upgrade
+ if current_level == 1:
+ upgrade_cost = 300
+ elif current_level == 2:
+ upgrade_cost = 500
+ elif current_level == 3:
+ upgrade_cost = 800
+ elif current_level == 4:
+ upgrade_cost = 1000
+ elif current_level >= 5:
+ print("Maaf, monster yang Anda pilih sudah memiliki level maksimum.\n")
+ break
+
+ # Memeriksa kembali data monster
+ for monster in monster_data:
+ if monster['id'] == monster_id:
+ monster_name = monster['type']
+ break
+ print(f"\n{monster_name} akan di-upgrade ke level {current_level + 1}.")
+ print(f"Harga untuk melakukan upgrade adalah {upgrade_cost} OC.")
+ confirm = input(">>> Lanjutkan upgrade (Y/N): ").upper()
+
+ # Memeriksa hasil konfirmasi
+ if confirm == 'Y':
+ for user in user_data:
+ if user['id'] == login_id:
+ user_coins = int(user['oc'])
+ if int(user_coins) >= upgrade_cost:
+ # Proses transaksi
+ user_coins = str(int(user_coins) - upgrade_cost)
+ selected_monster_data['level'] = str(current_level + 1)
+ user['oc'] = user_coins
+ print(f"Selamat, {monster_name} berhasil di-upgrade ke level {selected_monster_data['level']}!")
+ print(f"Besar OC setelah upgrade: {user_coins}\n")
+ else:
+ print("Maaf, OC Anda tidak mencukupi untuk melakukan upgrade.\n")
+ break
+ break
+ elif confirm == 'N':
+ print("Upgrade dibatalkan.\n")
+ break
+ else:
+ print("Input tidak valid. Upgrade dibatalkan.\n")
+ break
+ headers = list(user_data[0].keys())
+ list_user = [headers] + [[d[key] for key in headers] for d in user_data]
+
+
+
+ headers = list(monster_inventory[0].keys())
+ list_monster_inventory = [headers] + [[d[key] for key in headers] for d in monster_inventory]
+
+ list_user = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_user]
+ list_monster_inventory = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster_inventory]
+
+ return list_user,list_monster_inventory
+
diff --git a/src/F12.py b/src/F12.py
new file mode 100644
index 0000000..9003820
--- /dev/null
+++ b/src/F12.py
@@ -0,0 +1,493 @@
+#fungsi illegal: pop, slicing
+#ubah nama loadshop, ubah isPInt, 0 add, 0 change, 0 delete, tli_potion -> tli_item, none = loadtlinot, tambah, ubah, hapus
+def shop_management(li_monster, li_item, li_monster_shop, li_item_shop): #yang bisa masuk pasti rolenya admin
+ def load_tli(li_monster, li_item, li_monster_shop, li_item_shop):
+ def capital(string): #kapital huruf pertama
+ if ord(string[0]) in range (97, 123):
+ capital_string = string[0].upper()
+ for i in range (1, len(string)):
+ capital_string += string[i]
+ return capital_string
+ else:
+ return string
+
+ def pops(li, index): #index start 0
+ result = []
+ for idx, elmt in enumerate (li):
+ if idx != index:
+ result.append(elmt)
+ return result
+
+ def findrow(elmt, index_column, li): #cari index row, index_column start 0
+ for index, row in enumerate (li):
+ if row[index_column] == elmt:
+ return index
+
+ tli_monster = [['ID', 'Type', 'ATK Power', 'DEF Power', 'HP', 'Stock', 'Price']] #tli_monster = list untuk table monster (gabungan list)
+ for index, row in enumerate (li_monster_shop):
+ if index != 0: #exclude row pertama (column)
+ tli_monster.append(li_monster[findrow(row[0], 0, li_monster)] + pops(row, 0))
+
+ tli_item = [['ID', 'Type', 'Stok', 'Harga']] #tli_item = list untuk table item (gabungan list)
+ for index, row in enumerate (li_item_shop):
+ if index != 0: #exclude row pertama (column)
+ id = pops(li_item[findrow(row[0], 1, li_item)], 1)
+ tli_item.append(id + row)
+ for index, row in enumerate (tli_item):
+ if index != 0:
+ row[1] = capital(row[1]) + ' Potion'
+
+ return tli_monster, tli_item
+
+ def load_tlinot(li_monster, li_item, li_monster_shop, li_item_shop):
+ def capital(string): #kapital huruf pertama
+ if ord(string[0]) in range (97, 123):
+ capital_string = string[0].upper()
+ for i in range (1, len(string)):
+ capital_string += string[i]
+ return capital_string
+ else:
+ return string
+
+ def findrow(elmt, index_column, li): #cari index row, index_column start 0
+ for index, row in enumerate (li):
+ if row[index_column] == elmt:
+ return index
+
+ tlinot_monster = [['ID', 'Type', 'ATK Power', 'DEF Power', 'HP']]
+ for index, row in enumerate (li_monster):
+ if index != 0 and findrow(row[0], 0, li_monster_shop) == None:
+ tlinot_monster.append(row)
+
+ tlinot_item = [['ID', 'Type']]
+ for index, row in enumerate (li_item):
+ if index != 0 and findrow(row[1], 0, li_item_shop) == None:
+ new_row = [row[0], capital(row[1]) + ' Potion']
+ tlinot_item.append(new_row)
+
+ return tlinot_monster, tlinot_item
+
+ def tableprint(tli): #tli matrix 3x3, minimal ada header, tiap row elmtnya lengkap
+ def maxs(li):
+ max_value = li[0]
+ for elmt in li:
+ if elmt > max_value:
+ max_value = elmt
+ return max_value
+
+ columnlength = [(maxs([len(str(row[column])) for row in tli])) for column in range (len(tli[0]))]
+ for row in tli:
+ for indeks, elmt in enumerate(row):
+ if indeks != len(row)-1:
+ print(f"{elmt:<{columnlength[indeks]}} | ", end="")
+ else:
+ print(f"{elmt:<{columnlength[indeks]}}")
+ print()
+
+ def tambahmonster(li_monster_shop, tlinot_monster):
+ def isPInt(input):
+ if len(input) == 0:
+ return False
+ else:
+ for elmt in input:
+ if ord(elmt) not in range (48, 58):
+ return False
+ return True
+
+ def findrow(elmt, index_column, li): #cari index row, index_column start 0
+ for index, row in enumerate (li):
+ if row[index_column] == elmt:
+ return index
+
+ idValid = False
+ while not idValid:
+ id = input("Masukkan id monster: ")
+ if isPInt(id):
+ if findrow(int(id), 0, tlinot_monster) == None:
+ print('Input tidak valid. Ulangi')
+ else:
+ idValid = True
+ else:
+ print('Input tidak valid. Ulangi')
+
+ stock = input("Masukkan stok awal: ")
+ while not isPInt(stock):
+ print('Input tidak valid. Ulangi')
+ stock = input("Masukkan stok awal: ")
+
+ price = input("Masukkan harga: ")
+ while not isPInt(price):
+ print('Input tidak valid. Ulangi')
+ price = input("Masukkan harga: ")
+
+ li_monster_shop.append([int(id), int(stock), int(price)])
+ print(f"{tlinot_monster[findrow(int(id), 0, tlinot_monster)][1]} telah berhasil ditambahkan ke dalam shop!") #type selalu pada indeks kolom 1
+
+ return li_monster_shop
+
+ def tambahitem(li_item, li_item_shop, tlinot_item):
+ def isPInt(input):
+ if len(input) == 0:
+ return False
+ else:
+ for elmt in input:
+ if ord(elmt) not in range (48, 58):
+ return False
+ return True
+
+ def findrow(elmt, index_column, li): #cari index row, index_column start 0
+ for index, row in enumerate (li):
+ if row[index_column] == elmt:
+ return index
+
+ idValid = False
+ while not idValid:
+ id = input("Masukkan id potion: ")
+ if isPInt(id):
+ if findrow(int(id), 0, tlinot_item) == None:
+ print('Input tidak valid. Ulangi')
+ else:
+ idValid = True
+ else:
+ print('Input tidak valid. Ulangi')
+
+ stock = input("Masukkan stok awal: ")
+ while not isPInt(stock):
+ print('Input tidak valid. Ulangi')
+ stock = input("Masukkan stok awal: ")
+
+ price = input("Masukkan harga: ")
+ while not isPInt(price):
+ print('Input tidak valid. Ulangi')
+ price = input("Masukkan harga: ")
+
+ li_item_shop.append([li_item[findrow(int(id), 0, li_item)][1], int(stock), int(price)])
+ print(f"{tlinot_item[findrow(int(id), 0, tlinot_item)][1]} telah berhasil ditambahkan ke dalam shop!")
+
+ return li_item_shop
+
+ def ubahmonster(li_monster_shop, tli_monster):
+ def isPInt(input):
+ if len(input) == 0:
+ return False
+ else:
+ for elmt in input:
+ if ord(elmt) not in range (48, 58):
+ return False
+ return True
+
+ def findrow(elmt, index_column, li): #cari index row, index_column start 0
+ for index, row in enumerate (li):
+ if row[index_column] == elmt:
+ return index
+
+ idValid = False
+ while not idValid:
+ id = input("Masukkan id monster: ")
+ if isPInt(id):
+ if findrow(int(id), 0, tli_monster) == None:
+ print('Input tidak valid. Ulangi')
+ else:
+ idValid = True
+ else:
+ print('Input tidak valid. Ulangi')
+
+ stock = input("Masukkan stok awal: ")
+ while not isPInt(stock) and not len(stock) == 0:
+ print('Input tidak valid. Ulangi')
+ stock = input("Masukkan stok awal: ")
+
+ price = input("Masukkan harga: ")
+ while not isPInt(price) and not len(price) == 0:
+ print('Input tidak valid. Ulangi')
+ price = input("Masukkan harga: ")
+
+ isStockChange, isPriceChange = False, False
+ if len(stock) != 0:
+ li_monster_shop[findrow(int(id), 0, li_monster_shop)][1] = int(stock)
+ isStockChange = True
+ if len(price) != 0:
+ li_monster_shop[findrow(int(id), 0, li_monster_shop)][2] = int(price)
+ isPriceChange = True
+
+ if isStockChange and isPriceChange:
+ print(f"{tli_monster[findrow(int(id), 0, tli_monster)][1]} telah berhasil diubah dengan stok baru sejumlah {stock} dan dengan harga baru {price}!")
+ elif isStockChange and not isPriceChange:
+ print(f"{tli_monster[findrow(int(id), 0, tli_monster)][1]} telah berhasil diubah dengan stok baru sejumlah {stock}!")
+ elif not isStockChange and isPriceChange:
+ print(f"{tli_monster[findrow(int(id), 0, tli_monster)][1]} telah berhasil diubah dengan harga baru {price}!")
+ else:
+ print(f"{tli_monster[findrow(int(id), 0, tli_monster)][1]} sama sekali tidak diubah")
+
+ return li_monster_shop
+
+ def ubahitem(li_item, li_item_shop, tli_item):
+ def isPInt(input):
+ if len(input) == 0:
+ return False
+ else:
+ for elmt in input:
+ if ord(elmt) not in range (48, 58):
+ return False
+ return True
+
+ def findrow(elmt, index_column, li): #cari index row, index_column start 0
+ for index, row in enumerate (li):
+ if row[index_column] == elmt:
+ return index
+
+ idValid = False
+ while not idValid:
+ id = input("Masukkan id potion: ")
+ if isPInt(id):
+ if findrow(int(id), 0, tli_item) == None:
+ print('Input tidak valid. Ulangi')
+ else:
+ idValid = True
+ else:
+ print('Input tidak valid. Ulangi')
+
+ stock = input("Masukkan stok awal: ")
+ while not isPInt(stock) and not len(stock) == 0:
+ print('Input tidak valid. Ulangi')
+ stock = input("Masukkan stok awal: ")
+
+ price = input("Masukkan harga: ")
+ while not isPInt(price) and not len(price) == 0:
+ print('Input tidak valid. Ulangi')
+ price = input("Masukkan harga: ")
+
+ isStockChange, isPriceChange = False, False
+ if len(stock) != 0:
+ li_item_shop[findrow(li_item[findrow(int(id), 0, li_item)][1], 0, li_item_shop)][1] = int(stock)
+ isStockChange = True
+ if len(price) != 0:
+ li_item_shop[findrow(li_item[findrow(int(id), 0, li_item)][1], 0, li_item_shop)][2] = int(price)
+ isPriceChange = True
+
+ if isStockChange and isPriceChange:
+ print(f"{tli_item[findrow(int(id), 0, tli_item)][1]} telah berhasil diubah dengan stok baru sejumlah {stock} dan dengan harga baru {price}!")
+ elif isStockChange and not isPriceChange:
+ print(f"{tli_item[findrow(int(id), 0, tli_item)][1]} telah berhasil diubah dengan stok baru sejumlah {stock}!")
+ elif not isStockChange and isPriceChange:
+ print(f"{tli_item[findrow(int(id), 0, tli_item)][1]} telah berhasil diubah dengan harga baru {price}!")
+ else:
+ print(f"{tli_item[findrow(int(id), 0, tli_item)][1]} sama sekali tidak diubah")
+
+ return li_item_shop
+
+ def hapusmonster(li_monster_shop, tli_monster):
+ def isPInt(input):
+ if len(input) == 0:
+ return False
+ else:
+ for elmt in input:
+ if ord(elmt) not in range (48, 58):
+ return False
+ return True
+
+ def isyorn(input):
+ if len(input) == 0:
+ return False
+ else:
+ if input.lower() in ['y', 'n']:
+ return True
+ else:
+ return False
+
+ def findrow(elmt, index_column, li): #cari index row, index_column start 0
+ for index, row in enumerate (li):
+ if row[index_column] == elmt:
+ return index
+
+ def pops(li, index): #index start 0
+ result = []
+ for idx, elmt in enumerate (li):
+ if idx != index:
+ result.append(elmt)
+ return result
+
+ idValid = False
+ while not idValid:
+ id = input("Masukkan id monster: ")
+ if isPInt(id):
+ if findrow(int(id), 0, tli_monster) == None:
+ print('Input tidak valid. Ulangi')
+ else:
+ idValid = True
+ else:
+ print('Input tidak valid. Ulangi')
+
+ choiceValid = False
+ while not choiceValid:
+ choice = input(f"Apakah anda yakin ingin menghapus {tli_monster[findrow(int(id), 0, tli_monster)][1]} dari shop (y/n)? ")
+ if isyorn(choice):
+ choiceValid = True
+ else:
+ print('Input tidak valid. Ulangi')
+
+ if choice.lower() == "y":
+ li_monster_shop = pops(li_monster_shop, findrow(int(id), 0, li_monster_shop))
+ print(f"{tli_monster[findrow(int(id), 0, tli_monster)][1]} telah berhasil dihapus dari shop!")
+ else:
+ print(f"{tli_monster[findrow(int(id), 0, tli_monster)][1]} batal dihapus dari shop!")
+
+ return li_monster_shop
+
+ def hapusitem(li_item, li_item_shop, tli_item):
+ def isPInt(input):
+ if len(input) == 0:
+ return False
+ else:
+ for elmt in input:
+ if ord(elmt) not in range (48, 58):
+ return False
+ return True
+
+ def isyorn(input):
+ if len(input) == 0:
+ return False
+ else:
+ if input.lower() in ['y', 'n']:
+ return True
+ else:
+ return False
+
+ def findrow(elmt, index_column, li): #cari index row, index_column start 0
+ for index, row in enumerate (li):
+ if row[index_column] == elmt:
+ return index
+
+ def pops(li, index): #index start 0
+ result = []
+ for idx, elmt in enumerate (li):
+ if idx != index:
+ result.append(elmt)
+ return result
+
+ idValid = False
+ while not idValid:
+ id = input("Masukkan id potion: ")
+ if isPInt(id):
+ if findrow(int(id), 0, tli_item) == None:
+ print('Input tidak valid. Ulangi')
+ else:
+ idValid = True
+ else:
+ print('Input tidak valid. Ulangi')
+
+ choiceValid = False
+ while not choiceValid:
+ choice = input(f"Apakah anda yakin ingin menghapus {tli_item[findrow(int(id), 0, tli_item)][1]} dari shop (y/n)? ")
+ if isyorn(choice):
+ choiceValid = True
+ else:
+ print('Input tidak valid. Ulangi')
+
+ if choice.lower() == "y":
+ li_item_shop = pops(li_item_shop, findrow(li_item[findrow(int(id), 0, li_item)][1], 0, li_item_shop))
+ print(f"{tli_item[findrow(int(id), 0, tli_item)][1]} telah berhasil dihapus dari shop!")
+ else:
+ print(f"{tli_item[findrow(int(id), 0, tli_item)][1]} batal dihapus dari shop!")
+
+ return li_item_shop
+
+ def isActionValid(input):
+ if len(input) == 0:
+ return False
+ else:
+ if input.lower() in ['lihat', 'tambah', 'ubah', 'hapus', 'keluar']:
+ return True
+ else:
+ return False
+
+ def isMonsterOrPotion(input):
+ if len(input) == 0:
+ return False
+ else:
+ if input.lower() in ['monster', 'potion']:
+ return True
+ else:
+ return False
+
+ print("\nIrasshaimase! Selamat datang kembali, Mr. Monogram!\n")
+ exit = False
+ while not exit:
+ action = input("\nPilih aksi (lihat/tambah/ubah/hapus/keluar): ")
+ while not isActionValid(action):
+ action = input("Input tidak valid. Ulangi\nPilih aksi (lihat/tambah/ubah/hapus/keluar): ")
+
+ tli_monster, tli_item = load_tli(li_monster, li_item, li_monster_shop, li_item_shop)
+ tlinot_monster, tlinot_item = load_tlinot(li_monster, li_item, li_monster_shop, li_item_shop)
+
+ if action.lower() == "lihat":
+ choice = input("Mau lihat apa? (monster/potion): ")
+ while not isMonsterOrPotion(choice):
+ choice = input("Input tidak valid. Ulangi\nMau lihat apa? (monster/potion): ")
+ if choice.lower() == "monster":
+ tableprint(tli_monster)
+ else:
+ tableprint(tli_item)
+
+ elif action.lower() == "tambah":
+ choice = input("Mau nambahin apa? (monster/potion): ")
+ while not isMonsterOrPotion(choice):
+ choice = input("Input tidak valid. Ulangi\nMau nambahin apa? (monster/potion): ")
+ if choice.lower() == "monster":
+ if len(tlinot_monster) == 1:
+ print("Tidak ada monster yang tersedia")
+ else:
+ tableprint(tlinot_monster)
+ li_monster_shop = tambahmonster(li_monster_shop, tlinot_monster)
+ else:
+ if len(tlinot_item) == 1:
+ print("Tidak ada potion yang tersedia")
+ else:
+ tableprint(tlinot_item)
+ li_item_shop = tambahitem(li_item, li_item_shop, tlinot_item)
+
+ elif action.lower() == "ubah":
+ choice = input("Mau ubah apa? (monster/potion): ")
+ while not isMonsterOrPotion(choice):
+ choice = input("Input tidak valid. Ulangi\nMau ubah apa? (monster/potion): ")
+ if choice.lower() == "monster":
+ if len(tli_monster) == 1:
+ print("Tidak ada monster yang tersedia")
+ else:
+ tableprint(tli_monster)
+ li_monster_shop = ubahmonster(li_monster_shop, tli_monster)
+ else:
+ if len(tli_item) == 1:
+ print("Tidak ada item yang tersedia")
+ else:
+ tableprint(tli_item)
+ li_item_shop = ubahitem(li_item, li_item_shop, tli_item)
+
+ elif action.lower() == "hapus":
+ choice = input("Mau hapus apa? (monster/potion): ")
+ while not isMonsterOrPotion(choice):
+ choice = input("Input tidak valid. Ulangi\nMau hapus apa? (monster/potion): ")
+ if choice.lower() == "monster":
+ if len(tli_monster) == 1:
+ print("Tidak ada monster yang tersedia")
+ else:
+ tableprint(tli_monster)
+ li_monster_shop = hapusmonster(li_monster_shop, tli_monster)
+ else:
+ if len(tli_item) == 1:
+ print("Tidak ada item yang tersedia")
+ else:
+ tableprint(tli_item)
+ li_item_shop = hapusitem(li_item, li_item_shop, tli_item)
+ else:
+ print("Dadah Mr. Yanto, sampai jumpa lagi!\n")
+ exit = True
+ return li_monster, li_monster_shop, li_item_shop
+
+# li_monster = [['id', 'type', 'atk_power', 'def_power', 'hp'], [1, 'Pikachow', 11, 111, 1111], [2, 'Bulbu', 22, 222, 2222], [3, 'Zeze', 33, 333, 3333], [4, 'Iqbal', 44, 444, 4444]]
+# li_monster_shop = [['monster_id', 'stock', 'price'], [1, 10, 100], [2, 20, 200], [3, 30, 300]]
+# li_item_shop = [["type", 'stock', 'price'], ['strength', 10, 50], ['resilience', 5, 30]]
+# li_item = [['potion_id', 'type'], [1, 'strength'], [2, 'resilience'], [3, 'healing']]
+
+# li_monster, li_monster_shop, li_item_shop = shop_management(li_monster, li_item, li_monster_shop, li_item_shop)
+# print(li_monster, '\n', li_item, '\n', li_monster_shop, '\n', li_item_shop)
diff --git a/src/F13.py b/src/F13.py
new file mode 100644
index 0000000..e7474b6
--- /dev/null
+++ b/src/F13.py
@@ -0,0 +1,81 @@
+# Function for managing monsters (viewing, adding, deleting) with validation
+def monster_management(list_monster):
+ from src.F05 import custom_isdigit
+ from src.F05 import custom_zip
+ list_monster = [[str(item) for item in row] for row in list_monster]
+
+ headers = list_monster[0]
+ data = []
+ for i in range(1,len(list_monster)):
+ data.append(list_monster[i])
+ monster_data = [dict(custom_zip(headers, row)) for row in data]
+
+ while True:
+ print("\nMonster Management Menu:")
+ print("1. Tampilkan semua monster")
+ print("2. Tambahkan monster baru")
+ print("3. Keluar\n")
+ choice = input("Masukkan pilihan (1, 2, or 3): ")
+ if choice == "1": # View all monsters
+ print("Semua Monster:")
+ for monster in monster_data:
+ print(f"{monster['id']}. {monster['type']} (ATK: {monster['atk_power']}, DEF: {monster['def_power']}, HP: {monster['hp']})")
+ continue
+ elif choice == "2": # Add a new monster
+ new_monster_name = input("Masukkan nama monster baru: ")
+
+ # Check if the new monster_name already exists in monster_data
+ monster_full = False
+ for monster in monster_data:
+ if monster['type'] == new_monster_name:
+ print("Monster ini sudah tersedia di menu. Silakan masukkan nama yang berbeda.\n")
+ monster_full = True
+ if monster_full:
+ continue
+
+ # Collect other monster details
+ new_monster_id = 1
+ for monster in monster_data:
+ if monster['id'] == str(new_monster_id):
+ new_monster_id += 1
+
+ new_hp = input("Masukkan hit points (integer positif): ")
+ new_attack_power = input("Masukkan attack power (integer positif): ")
+ new_defence_power = input("Masukkan defence power (integer 1-50): ")
+
+ if custom_isdigit(new_attack_power) and custom_isdigit(new_defence_power) and custom_isdigit(new_hp):
+ new_hp = int(new_hp)
+ new_attack_power = int(new_attack_power)
+ new_defence_power = int(new_defence_power)
+ if not (0 < new_defence_power <= 50):
+ print("Defence power harus di dalam rentang 1-50")
+ continue
+ if new_hp <= 0 and new_attack_power <= 0 and new_defence_power <= 0:
+ print("Masukan harus bilangan bulat positif!")
+ continue
+ else:
+ print("Silakan masukkan format yang benar!")
+ continue
+
+ new_monster = {
+ 'id': str(new_monster_id),
+ 'type': str(new_monster_name),
+ 'atk_power': str(new_attack_power),
+ 'def_power': str(new_defence_power),
+ 'hp': str(new_hp)
+ }
+ monster_data.append(new_monster)
+ print("Monster baru berhasil ditambahkan.")
+ continue
+ elif choice == "3":
+ print("Menutup monster management...")
+ headers = list(monster_data[0].keys())
+ list_monster = [headers] + [[d[key] for key in headers] for d in monster_data]
+ list_monster = [[int(item) if custom_isdigit(item) else item for item in row] for row in list_monster]
+ return list_monster
+ else:
+ print("Silakan masukkan pilihan yang tersedia")
+ continue
+
+# from src.F13 import monster_management
+# li_monster = monster_management(li_monster)
diff --git a/src/F14.py b/src/F14.py
new file mode 100644
index 0000000..0074ac8
--- /dev/null
+++ b/src/F14.py
@@ -0,0 +1,60 @@
+def load():
+ def custom_isdigit(s): # Implementasi fungsi isDigit
+ return all('0' <= char <= '9' for char in s)
+ def csvtolist(csv_file, index_columnint): #index_columnint = index kolom yang bertipe data integer
+ li, row, elmt = [], [], ''
+ with open(csv_file, 'r') as f:
+ for line in f:
+ for i in line:
+ if i == ';':
+ row.append(elmt)
+ elmt = ''
+ elif i == '\n':
+ row.append(elmt)
+ li.append(row)
+ row, elmt = [], ''
+ else:
+ elmt += i
+ if elmt: # Include last row
+ row.append(elmt)
+ li.append(row)
+ for i in index_columnint: #mengubah kolom string menjadi int (sesuai tipe data kolom masing2)
+ for j in range (1, len(li)):
+ if custom_isdigit(li[j][i]): # Memastikan string yang berisi angka saja yang diubah menjadi int
+ li[j][i] = int(li[j][i])
+
+ return li
+
+ import argparse, sys, os
+ parser = argparse.ArgumentParser()
+ parser.add_argument('folder')
+ if len(sys.argv) != 2:
+ print("\nTidak ada nama folder yang diberikan!\nUsage : python/py main.py ")
+ sys.exit()
+ else:
+ args = parser.parse_args()
+ path = 'data/' + args.folder #parent foldernya ./data (./data/folder/.csv), didalam folder data ada folder lagi baru kumpulan csv
+ if not os.path.exists(path):
+ print(f"\nFolder {args.folder} tidak ditemukan.")
+ sys.exit()
+ else:
+ print("\nLoading...\n")
+ li_user = csvtolist((path + '/user.csv'), [0, 4])
+ li_monster = csvtolist((path + '/monster.csv'), [0, 2, 3, 4])
+ li_item_inventory = csvtolist((path + '/item_inventory.csv'), [0, 2])
+ li_monster_inventory = csvtolist((path + '/monster_inventory.csv'), [0, 1, 2])
+ li_item_shop = csvtolist((path + '/item_shop.csv'), [1, 2])
+ li_monster_shop = csvtolist((path + '/monster_shop.csv'), [0, 1, 2])
+ li_item = [['potion_id', 'type'], [1, 'strength'], [2, 'resilience'], [3, 'healing']]
+ print("Selamat datang di program OWCA!")
+ return li_user, li_monster, li_item, li_item_inventory, li_monster_inventory, li_item_shop, li_monster_shop
+
+#Aplikasi main.py
+#from src.F14_Load import load
+#li_user, li_monster, li_item, li_item_inventory, li_monster_inventory, li_item_shop, li_monster_shop = load()
+
+#saat menjalankan file main.py (langsung ketikkan di terminal)
+#py main.py atau python main.py
+
+#Catatan
+#file csv disimpan didalam folder yang disimpan dalam parent folder data/ (saat menjalankan main.py, cukup ketikkan folder saja tanpa ./data/folder/.csv)
diff --git a/src/F15.py b/src/F15.py
new file mode 100644
index 0000000..53a6ba3
--- /dev/null
+++ b/src/F15.py
@@ -0,0 +1,48 @@
+def save(li_user, li_monster, li_item_inventory, li_monster_inventory, li_item_shop, li_monster_shop):
+ import os
+
+ def listtocsv(li_name, csv_file): #listtocsv mengubah list menjadi file .csv
+ with open(csv_file, 'w') as f:
+ line = ''
+ for row in li_name:
+ for index, elmt in enumerate(row):
+ if index == len(row)-1:
+ line += str(elmt)
+ else:
+ line += str(elmt) + ';'
+ line += '\n'
+ f.write(line)
+
+ parentsave = 'data'
+ folder = input("Masukkan nama folder: ")
+ while len(folder) == 0:
+ print('Input tidak valid')
+ print()
+ folder = input("Masukkan nama folder: ")
+ path = parentsave + '/' + folder
+
+ print("\nSaving...\n")
+
+ if not os.path.exists(parentsave):
+ os.makedirs(parentsave)
+ print(f"Membuat folder {parentsave}...")
+
+ if not os.path.exists(path):
+ os.makedirs(path)
+ print(f"Membuat folder {path}...")
+
+ listtocsv(li_user, (path + '/user.csv'))
+ listtocsv(li_monster, (path + '/monster.csv'))
+ listtocsv(li_item_inventory, (path + '/item_inventory.csv'))
+ listtocsv(li_monster_inventory, (path + '/monster_inventory.csv'))
+ listtocsv(li_item_shop, (path + '/item_shop.csv'))
+ listtocsv(li_monster_shop, (path + '/monster_shop.csv'))
+
+ print(f"Berhasil menyimpan data di folder {path}")
+
+#Aplikasi main.py
+#from src.F14_Save import save
+#save(li_user, li_monster, li_item_inventory, li_monster_inventory, li_item_shop, li_monster_shop)
+
+#Catatan
+#file csv disimpan didalam folder yang disimpan dalam parent folder data/
diff --git a/src/F16.py b/src/F16.py
new file mode 100644
index 0000000..0a618a9
--- /dev/null
+++ b/src/F16.py
@@ -0,0 +1,18 @@
+def exit_game(list_user, list_monster, list_item_inventory, list_monster_inventory, list_item_shop, list_monster_shop):
+ from src.F15 import save
+ while True:
+ user_input = input("Apakah Anda mau melakukan penyimpanan file yang sudah diubah? (y/n) ").lower()
+ if user_input == 'y':
+ # Menjalankan prosedur save
+ save(list_user, list_monster, list_item_inventory, list_monster_inventory, list_item_shop, list_monster_shop)
+ exit()
+ elif user_input == 'n':
+ # Keluar program
+ exit()
+ else:
+ continue
+
+# Aplikasi fungsi exit_game pada file main.py
+
+# from src.F16 import exit_game
+# exit_game(li_user, li_monster, li_item_inventory, li_monster_inventory, li_item_shop, li_monster_shop)