-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
363 lines (329 loc) · 16.2 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
import flet as ft
import os
import sys
import json
from time import sleep
dir_app = os.path.dirname(__file__)
with open(dir_app + "/user_data.json", mode="r", encoding="UTF-8") as file:
user_data = json.load(file)
class Buttons_Main(ft.ElevatedButton):
def __init__(self, text, on_click=""):
super().__init__()
self.bgcolor = ft.colors.BLUE_500
self.color = ft.colors.WHITE
self.style = ft.ButtonStyle(overlay_color="blue800")
self.text = text
self.width = 150
self.on_click = on_click
class Application:
def __init__(self, page: ft.Page):
self.page = page
self.page.title = "3 Clue Game"
self.page.theme_mode = ft.ThemeMode.DARK
self.page.window.width = 360
self.page.window.height = 640
self.page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
self.page.bgcolor = ft.colors.TRANSPARENT
self.page.decoration = ft.BoxDecoration(
image=ft.DecorationImage(
src="images/fundoApp.jpg",
fit=ft.ImageFit.COVER,
opacity=0.4,
),
)
# HEADER BAR --------------------------------------------------------------
self.bar = ft.AppBar(
leading=ft.IconButton(ft.icons.HOME, tooltip="Tela Inicial", on_click=self.home),
bgcolor=ft.colors.TRANSPARENT,
toolbar_height=35,
actions=[
ft.PopupMenuButton(tooltip="Configurações",
items=[
ft.PopupMenuItem(text="Preferências"),
ft.PopupMenuItem(),
ft.PopupMenuItem(text="Sair"),
],
),
],
)
self.page.appbar = self.bar
# MODAL REGRAS -------------------------------------------------------------------------
self.rules_modal = ft.AlertDialog(
modal=True,
alignment=ft.alignment.center,
title=ft.Text("Regras do Jogo", font_family="Lilita One",
text_align=ft.TextAlign.CENTER),
content=ft.Column(
width=200,
height=100,
controls=[
ft.Divider(height=1, color="white"),
ft.Text("DESCUBRA A PALAVRA SECRETA, USANDO ATÉ 03 DICAS!",
font_family="Bauhaus 93", size=16,
text_align=ft.TextAlign.CENTER),
]
),
actions=[
ft.TextButton("Entendi", on_click=lambda e: self.page.close(self.rules_modal)),
],
)
# --------------------------------------------------------------------------------------
self.page.add(
self.build(),
)
def home(self, e):
self.page.clean()
self.page.add(self.build())
def edit_user(self, e):
from UI_editUser import EditUser
self.page.clean()
self.page.add(EditUser(self.page))
def restart_app(self, e):
self.page.window.destroy()
sleep(0.5)
python = sys.executable
os.execl(python, python, *sys.argv)
def button_Continuar(self, e):
from UI_gameSolo import UI_GameSolo2
with open(dir_app + "/word_list_copy.json", mode="r", encoding="UTF-8") as file:
words = json.load(file)
if not words:
end_modal = ft.AlertDialog(
modal=True,
title=ft.Text("FIM DE JOGO!", font_family="Lilita One",
text_align=ft.TextAlign.CENTER),
content=ft.Text("Parabéns, você jogou todas as palavras!",
text_align=ft.TextAlign.CENTER,
font_family="Baskerville Old Face", size=18),
actions=[ft.TextButton(
"Continuar", on_click=lambda _: self.page.close(end_modal)),
],
)
self.page.open(end_modal)
else:
self.page.clean()
self.page.add(UI_GameSolo2(self.page))
def button_NovoJogo(self, e):
with open(dir_app + "/user_data.json", mode="r", encoding="UTF-8") as file:
user_data = json.load(file)
if user_data["words_played"][1] > 0:
self.alert_modal = ft.AlertDialog(
modal=True,
title=ft.Text("Novo Jogo", font_family="Lilita One",
text_align=ft.TextAlign.CENTER),
content=ft.Text(
"Isso reiniciará seu jogo, zerando sua pontuação. \n\nDeseja continuar?",
font_family="Baskerville Old Face", size=18),
actions=[
ft.TextButton(text="Confirmar", on_click=self.new_game),
ft.TextButton(text="Cancelar",
on_click=lambda _: self.page.close(self.alert_modal)),
]
)
self.page.open(self.alert_modal)
else:
self.new_game(e)
def new_game(self, e):
from UI_gameSolo import UI_GameSolo2
from gameSolo import restart_game
if e.control.text == "Confirmar":
self.page.close(self.alert_modal)
sleep(0.5)
self.page.overlay.append(
ft.Container(
alignment=ft.alignment.center,
width=360,
height=640,
content=ft.CupertinoActivityIndicator(
radius=50, color=ft.colors.BLUE, animating=True
)
)
)
self.main_container.opacity = 0.30
self.page.update()
sleep(3)
self.page.overlay.clear()
self.main_container.opacity = 1
self.page.update()
restart_game()
self.page.clean()
self.page.add(UI_GameSolo2(self.page))
# BUILD HOME -----------------------------------------------------------------------------------------
def build(self):
with open(dir_app + "/user_data.json", mode="r", encoding="UTF-8") as file:
user_data = json.load(file)
self.btn_continuar = ft.ElevatedButton(
text="Continuar",
width=150,
color=ft.colors.WHITE,
bgcolor=ft.colors.BLUE_500,
on_click=self.button_Continuar,
disabled=True,
opacity=0.6,
style=ft.ButtonStyle(overlay_color="blue800")
)
if user_data["words_played"][1]:
self.btn_continuar.disabled = False
self.btn_continuar.opacity = 1
self.main_container = ft.Container(
width=360,
height=640,
margin=ft.margin.only(top=-10, left=-10, right=-10),
content=ft.Stack([
ft.Container(
width=360,
height=640,
margin=ft.margin.only(top=25),
content=ft.Column(
horizontal_alignment="center",
controls=[
ft.Container(
margin=ft.margin.only(top=-20),
width=250,
height=35,
alignment=ft.alignment.center,
border_radius=ft.border_radius.all(20),
border=ft.border.only(bottom=ft.border.BorderSide(3)),
image_src="images/logo.png"
),
ft.Text("Bem Vindo!", size=20, weight="bold"),
ft.Container(
width=100,
height=100,
border_radius=ft.border_radius.all(100),
bgcolor="white",
alignment=ft.alignment.center,
content=ft.Image(src=user_data["avatar"],
fit=ft.ImageFit.COVER,
width=150,
),
on_click=self.edit_user,
tooltip="Editar Perfil"
),
ft.Text(user_data["user"],
font_family="DaddyTimeMono Nerd Font",
size=16, weight="bold"),
ft.Row(
alignment=ft.MainAxisAlignment.CENTER,
controls=[
ft.Container(
width=95,
height=100,
bgcolor="white",
border=ft.border.all(1, "BLUE"),
border_radius=ft.border_radius.only(
top_left=5, top_right=5,
bottom_left=50, bottom_right=50),
gradient=ft.PaintLinearGradient(
begin=ft.alignment.top_center,
end=ft.alignment.bottom_center,
colors=[ft.colors.BLUE, ft.colors.BLUE_900],
),
padding=5,
content=ft.Column(
horizontal_alignment="center",
spacing=0,
controls=[
ft.Container(
width=30,
height=30,
alignment=ft.alignment.center,
content=ft.Image(
src="images/fire.png")
),
ft.Text(user_data["record"][1],
color=ft.colors.BLACK, size=20, weight="bold"),
ft.Text("Melhor Score",
color=ft.colors.BLACK, size=10, weight="bold"),
],
)
),
ft.Container(
width=95,
height=115,
bgcolor="white",
border=ft.border.all(1, "PURPLE"),
border_radius=ft.border_radius.only(
top_left=5, top_right=5,
bottom_left=50, bottom_right=50),
padding=-13,
gradient=ft.PaintLinearGradient(
begin=ft.alignment.top_center,
end=ft.alignment.bottom_center,
colors=[ft.colors.PURPLE, ft.colors.PINK_900],
),
content=ft.Column(
horizontal_alignment="center",
spacing=0,
controls=[
ft.Container(
width=50,
height=50,
alignment=ft.alignment.center,
content=ft.Image(
src="images/stars.png")
),
ft.Text(
user_data["words_played"][2],
color=ft.colors.BLACK, size=20, weight="bold"),
ft.Text(
" Palavras\nDescobertas",
color=ft.colors.BLACK, size=10, weight="bold"),
],
)
),
ft.Container(
width=95,
height=100,
bgcolor="white",
border=ft.border.all(1, "YELLOW"),
border_radius=ft.border_radius.only(
top_left=5, top_right=5,
bottom_left=50, bottom_right=50),
padding=5,
gradient=ft.PaintLinearGradient(
begin=ft.alignment.top_center,
end=ft.alignment.bottom_center,
colors=[ft.colors.YELLOW, ft.colors.GREEN_500],
),
content=ft.Column(
horizontal_alignment="center",
spacing=0,
controls=[
ft.Container(
width=30,
height=30,
alignment=ft.alignment.center,
content=ft.Image(
src="images/coin.png")
),
ft.Text(user_data["score"],
color=ft.colors.BLACK, size=20, weight="bold"),
ft.Text("Pontuação",
color=ft.colors.BLACK, size=10, weight="bold"),
],
)
),
],
),
ft.Container(
margin=ft.margin.only(top=20),
content=ft.Column(
controls=[
self.btn_continuar,
Buttons_Main(text="Novo Jogo", on_click=self.button_NovoJogo),
Buttons_Main(text="Duelo"),
Buttons_Main(text="Regras",
on_click=lambda e: self.page.open(self.rules_modal)),
]
),
),
],
),
)
]),
)
return self.main_container
# ----------------------------------------------------------------------------------------------------
if __name__ == "__main__":
ft.app(target=Application, assets_dir="_internal/Assets")