-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
147 lines (117 loc) · 5.23 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
import time
from body.function_mgc import kerangajaib
from body.function_tictactoe import tictactoe
from utils.ui import printWarning, printCenter, clearScreen
from utils.file import folderExist
from utils.user import getSessionAccount, isAdmin
from front.ui import ExitPage, LoginPage, RegisterPage, header, RegisterPage, LandingPage, MainMenu
from constants import emptySessionAccount
from body.function_main import register, login, riwayat, search_game_at_store, search_my_game, tambah_game, topup, ubah_game, ubah_stok, list_game_toko, buy_game, list_game, help , Load, Save, exit
######## PARSER ##########
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('folderName', nargs='?')
args = parser.parse_args()
#########################
# fungsi utama
def main():
sessionAccount = emptySessionAccount #username, name, saldo, role, id
folderPath = ''
if args.folderName != None : # pengguna memberikan nama folder
folderPath = './'+str(args.folderName)+'/'
printCenter('Loading ...')
time.sleep(2)
if(not folderExist(folderPath)): # folder tidak ditemukan
printWarning(f'folder "{args.folderName}" tidak ditemukan')
time.sleep(1)
quit()
else: # folder ditemukan
userArray, gameArray, riwayatArray, kepemilikanArray = Load(folderPath)
time.sleep(1)
else:
printWarning('Folder tidak diberikan') # nama folder tidak diberikan pengguna
quit()
##############################
finished = False
while not finished:
choiceAnswer : str = ''
# cetak header
header()
print()
###################################################
name = username = password = ''
# Belum memiliki sesi login akun
if sessionAccount[0] == '':
choiceAnswer = LandingPage() # login, register, exit
if choiceAnswer == 1:
username, password = LoginPage()
sessionAccount = login(userArray, username, password)
else: # 2
exit(folderPath, userArray, gameArray, riwayatArray, kepemilikanArray)
finished = True
# memiliki sesi login akun
else :
# lakukan pilihan command
choiceAnswer = MainMenu(sessionAccount)
print()
if isAdmin(sessionAccount):
if choiceAnswer == 1 :
name, username, password = RegisterPage()
userArray = register(userArray, name, username, password)
elif choiceAnswer == 2:
gameArray = tambah_game(gameArray)
elif choiceAnswer == 3:
gameArray = ubah_game(gameArray)
elif choiceAnswer == 4:
gameArray = ubah_stok(gameArray)
elif choiceAnswer == 5:
list_game_toko(gameArray)
elif choiceAnswer == 6:
search_game_at_store(gameArray)
elif choiceAnswer == 7:
userArray = topup(userArray)
elif choiceAnswer == 8:
help(sessionAccount)
elif choiceAnswer == 9:
Save(folderPath, userArray, gameArray, riwayatArray, kepemilikanArray)
elif choiceAnswer == 10:
exit(folderPath, userArray, gameArray, riwayatArray, kepemilikanArray)
clearScreen()
finished = True
elif choiceAnswer == 11:
kerangajaib()
elif choiceAnswer == 12:
tictactoe()
else:
if choiceAnswer == 1:
list_game_toko(gameArray)
elif choiceAnswer == 2:
gameArray, kepemilikanArray, userArray, riwayatArray = buy_game(gameArray, kepemilikanArray, userArray, riwayatArray, sessionAccount[4])
elif choiceAnswer == 3:
list_game(gameArray, kepemilikanArray, sessionAccount[4])
elif choiceAnswer == 4:
search_my_game(gameArray, kepemilikanArray, sessionAccount[4])
elif choiceAnswer == 5:
search_game_at_store(gameArray)
elif choiceAnswer == 6:
riwayat(riwayatArray, sessionAccount[4])
elif choiceAnswer == 8:
help(sessionAccount)
elif choiceAnswer == 9:
Save(folderPath, userArray, gameArray, riwayatArray, kepemilikanArray)
elif choiceAnswer == 10:
exit(folderPath, userArray, gameArray, riwayatArray, kepemilikanArray)
#clearScreen()
finished = True
elif choiceAnswer == 11:
kerangajaib()
elif choiceAnswer == 12:
tictactoe()
if finished : ExitPage()
input()
clearScreen()
# update nilai sesi akun
sessionAccount = getSessionAccount(userArray, sessionAccount[0])
########################################
if __name__ == '__main__':
main()