-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.py
78 lines (63 loc) · 2.74 KB
/
dashboard.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
import pygame
import os
pygame.init()
def write(screen, text, font, text_size, center, color):
text_font = pygame.font.Font(font, text_size)
text_to_write = text_font.render(text, True, color)
text_rect = text_to_write.get_rect()
text_rect.center = center
screen.blit(text_to_write, text_rect)
class GameLink:
def __init__(self, window, name, image, x, y, size, game, color):
self.window = window
self.color = color
self.name = name
self.image = image
self.x, self.y = x, y
self.size = size
self.game = game
def draw(self):
pygame.draw.rect(self.window, self.color, (self.x, self.y, self.size[0], self.size[1]))
write(self.window, self.name, 'tahoma.ttf', 20, (self.x + self.size[0] / 2, self.y + self.size[0] + (self.size[1] - self.size[0]) / 2), (255, 255, 255))
def click(self, mx, my):
print(self.x, self.y, mx, my)
if self.x <= mx <= self.x+260 and self.y <= my <= self.y+290:
return True
return False
class Dashboard:
def __init__(self, window, clock):
self.window = window
self.clock = clock
self.run = True
self.bgColor = (231, 173, 153)
self.navColor = (40, 0, 3)
self.gameNames = os.listdir('Games')
self.colors = [(255,0,0),(255,0,255),(0,0,255),(0,0,255),(255,0,255), (255,0,0)]
self.images = {}
self.games = []
self.gameList = ['agm', 'bts', '', 'c4', 'nim', 'ttt']
self.dest = ""
# self.images[self.gameNames[i]]
for i in range(6):
x_val = (i if i < 3 else i - 3)
y_val = (1 if i < 3 else 2)
self.games.append(GameLink(self.window, self.gameNames[i], 'image', (55*(x_val+1) + 260*x_val), (40*y_val + 290*(y_val-1)), (260, 290), self.gameList[i], self.colors[i]))
while self.run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.run = False
if event.type == pygame.MOUSEBUTTONDOWN:
mx, my = pygame.mouse.get_pos()
for i in self.games:
if i.click(mx, my):
print('true')
self.dest=i.game
self.run = False
self.draw()
def draw(self):
self.window.fill(self.bgColor)
for game in self.games:
game.draw()
if game.x <= pygame.mouse.get_pos()[0] <= game.x + game.size[0] and game.y <= pygame.mouse.get_pos()[1] <= game.y + game.size[1]:
pygame.draw.rect(self.window, (255, 255, 255), ((game.x - 8), (game.y - 8), game.size[0] + 16, game.size[1] + 16), 8)
pygame.display.update()