-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
161 lines (158 loc) · 6.71 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# https://github.com/luca4s/urna-eletronica
import pygame, sys, json
with open('data.json', encoding="utf8") as data:
f = data.read()
data = json.loads(f)
pygame.init()
confirma = pygame.mixer.Sound("CONFIRMA.wav")
fim = pygame.mixer.Sound("FIM.wav")
screen = pygame.display.set_mode([1366, 768], pygame.FULLSCREEN)
clock = pygame.time.Clock()
font = pygame.font.SysFont('arial', 56)
mediumfont = pygame.font.SysFont('arial', 32)
smallfont = pygame.font.SysFont('arial', 22)
bigfont = pygame.font.SysFont('arial', 112)
SEC = 1
CC = False
RA = ""
NV = ""
V = ""
info = ""
running = True
sec3lastpressed = ""
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == 27:
running = False
elif event.key == pygame.K_KP_ENTER and CC:
if SEC == 1:
CC = False
info = ""
SEC = 2
confirma.play()
elif SEC == 2:
data["eleitores"][RA]["votou"] = True
data["candidatos"][V]["votos"] += 1
info = ""
RA = ""
V = ""
NV = ""
CC = False
SEC = 3
fim.play()
with open("data.json", "w") as outfile:
json.dump(data, outfile)
elif event.key == pygame.K_KP_PLUS:
info = ""
CC = False
if SEC == 1:
RA = ""
elif SEC == 2:
V = ""
NV = ""
elif event.key == 1073741923:
if SEC == 2:
NV = ""
CC = True
V = "BRANCO"
info = "VOTO EM BRANCO"
else:
if SEC == 1:
if len(RA) < 9:
info = ""
RA += event.unicode
if len(RA) == 9:
if data["eleitores"].get(RA) is not None:
if not data["eleitores"][RA]["votou"]:
info = data["eleitores"][RA]["nome"]
CC = True
else:
info = "JÁ VOTOU"
else:
info = "RA INVÁLIDO"
elif SEC == 2:
if len(NV) < 2:
NV += event.unicode
if len(NV) == 2:
V = NV
if data["candidatos"].get(V) is None:
V = "NULO"
info = "VOTO NULO"
CC = True
elif SEC == 3:
sec3lastpressed += str(event.key)
if sec3lastpressed.endswith("107374191410737419131073741919"):
sec3lastpressed = ""
SEC = 1
screen.fill((255, 255, 255))
line = pygame.Rect(0, 700, 1366, 3)
pygame.draw.rect(screen, (0, 0, 0), line)
helpstr = ["Aperte VERDE para confirmar.", "Aperte VERMELHO para corrigir.", "Aperte BRANCO para votar em branco."]
for i, stg in enumerate(helpstr):
helptext = smallfont.render(stg, True, (0, 0, 0))
screen.blit(helptext, helptext.get_rect(bottom=728+i*20))
if SEC == 1:
xs = [683-220, 683-165, 683-110, 683-55, 683, 683+55, 683+110, 683+165, 683+220]
for x in xs:
rect = pygame.Rect(x, 384, 50, 80)
rect.center = (rect.x, rect.y)
pygame.draw.rect(screen, (0, 0, 0), rect, 1)
for i, char in enumerate(RA):
chartext = font.render(char, True, (0, 0, 0))
screen.blit(chartext, chartext.get_rect(center=(xs[i], 384)))
text = font.render("Insira seu RA.", True, (0, 0, 0))
infotext = font.render(info, True, (0, 0, 0))
screen.blit(text, text.get_rect(center=(683, 384-100)))
screen.blit(infotext, infotext.get_rect(center=(683, 384+100)))
elif SEC == 2:
seuvotopara = smallfont.render("SEU VOTO PARA", True, (128, 128, 128))
candidatotext = font.render("Candidato", True, (0, 0, 0))
numero = mediumfont.render("Número: ", True, (0, 0, 0))
xs = [200, 255]
for x in xs:
rect = pygame.Rect(x, 261, 50, 80)
rect.center = (rect.x, rect.y)
pygame.draw.rect(screen, (0, 0, 0), rect, 1)
for i, char in enumerate(NV):
chartext = font.render(char, True, (0, 0, 0))
screen.blit(chartext, chartext.get_rect(center=(xs[i], 261)))
if V != "":
if V == "NULO":
numeroerrado = font.render("NÚMERO ERRADO", True, (0, 0, 0))
votonulo = bigfont.render(info, True, (0, 0, 0))
screen.blit(numeroerrado, (25, 311))
screen.blit(votonulo, votonulo.get_rect(center=(683, 504)))
elif V == "BRANCO":
votobranco = bigfont.render(info, True, (0, 0, 0))
screen.blit(votobranco, votobranco.get_rect(center=(683, 504)))
else:
candidato = data["candidatos"][V]["candidato"]
vice = data["candidatos"][V]["vice"]
partido = data["candidatos"][V]["partido"]
fotocandidato = pygame.image.load(f"fotos/{candidato}.png")
fotovice = pygame.image.load(f"fotos/{vice}.png")
rectcandidato = pygame.Rect(1041, 25, 300, 400)
rectvice = pygame.Rect(1191, 450, 150, 200)
pygame.draw.rect(screen, (0, 0, 0), rectcandidato, 0)
pygame.draw.rect(screen, (0, 0, 0), rectvice, 0)
nome = mediumfont.render(f'Nome: {data["eleitores"][candidato]["nome"]}', True, (0, 0, 0))
partido = mediumfont.render(f'Partido: {partido}', True, (0, 0, 0))
vicecandidato = mediumfont.render(f'Vice-Candidato: {data["eleitores"][vice]["nome"]}', True, (0, 0, 0))
screen.blit(fotocandidato, rectcandidato)
screen.blit(fotovice, rectvice)
screen.blit(nome, (25, 311))
screen.blit(partido, (25, 361))
screen.blit(vicecandidato, (25, 411))
screen.blit(seuvotopara, (25, 10))
screen.blit(candidatotext, candidatotext.get_rect(center=(643, 150)))
screen.blit(numero, (25, 241))
elif SEC == 3:
text = bigfont.render("FIM", True, (0, 0, 0))
screen.blit(text, text.get_rect(center=(683, 384)))
pygame.display.flip()
clock.tick(60)
pygame.quit()
sys.exit()