-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
119 lines (92 loc) · 3.68 KB
/
main.py
File metadata and controls
119 lines (92 loc) · 3.68 KB
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
import pygame as pg
from assets.color import *
from assets.button import Intro_Button
#====================================================================================#
def title(screen):
text = "8 Puzzle"
font_size = 130
font = pg.font.SysFont('Montserrat', font_size, bold=True)
main_color = baby_blue
glow_color = cream
text_surface = font.render(text, True, main_color)
for offset in range(1, 6):
glow_surface = font.render(text, True, glow_color)
glow_surface.set_alpha(30)
screen.blit(glow_surface, (300 - offset, 50 - offset))
screen.blit(glow_surface, (300 + offset, 50 - offset))
screen.blit(glow_surface, (300 - offset, 50 + offset))
screen.blit(glow_surface, (300 + offset, 50 - offset))
shadow_surface = font.render(text, True, (0, 0, 0))
shadow_surface.set_alpha(80)
screen.blit(shadow_surface, (303, 53))
screen.blit(text_surface, (300, 50))
def load_music():
pg.mixer.init()
pg.mixer.music.load(r'assets\wave.mp3')
pg.mixer.music.play(loops=-1)
def intro_panel(screen, width, height=None):
panel = pg.Surface((width - 2 * 330, 330), pg.SRCALPHA)
pg.draw.rect(panel, color_algo_panel, (0, 0, panel.get_width(), panel.get_height()), border_radius=50)
font = pg.font.SysFont('Montserrat', 28, bold=True)
info_lines = [
"ID: 23110312",
"Name: Lê Thị Thanh Tâm",
"ARIN330585_04",
"Mentor: Phan Thị Huyền Trang"
]
for i, line in enumerate(info_lines):
text = font.render(line, True, '#000000')
screen.blit(text, (100, 280 + i * 50))
screen.blit(panel, (600, 220))
#====================================================================================#
def intro():
pg.init()
width = 1200
height = 600
screen = pg.display.set_mode((width, height), pg.RESIZABLE)
pg.display.set_caption("8-Puzzle")
# Load and scale background
bg = pg.image.load(r'assets\beach3.png').convert()
bg = pg.transform.scale(bg, (width, height))
# Buttons
btn_real_env = Intro_Button('Real Environment', 280, 50, (720, 250), 2)
btn_complex_env = Intro_Button('Complex Environment', 320, 50, (700, 320), 2)
btn_csp = Intro_Button('Constraint Satisfaction Problem', 500, 50, (620, 390), 2)
btn_rl = Intro_Button('Reinforcement Learning', 460, 50, (650, 460), 2)
btn_quit = Intro_Button('Quit', 150, 50, (100, height - 80), 2)
running = True
while running:
for event in pg.event.get():
if event.type == pg.QUIT or (
event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE):
running = False
if event.type == pg.VIDEORESIZE:
width, height = event.w, event.h
screen = pg.display.set_mode((width, height), pg.RESIZABLE)
bg = pg.transform.scale(bg, (width, height))
screen.blit(bg, (0, 0))
title(screen)
intro_panel(screen, width)
btn_real_env.draw(screen)
btn_complex_env.draw(screen)
btn_csp.draw(screen)
btn_rl.draw(screen)
btn_quit.draw(screen)
# Kiểm tra click
if btn_real_env.check_click(None):
from gui.real import base
base()
elif btn_complex_env.check_click(None):
from gui.belief2 import base
base()
elif btn_csp.check_click(None):
from gui.csp import base
base()
elif btn_rl.check_click(None):
from gui.qlearning import base
base()
elif btn_quit.check_click(None):
running = False
pg.display.flip()
pg.quit()
intro()