-
Notifications
You must be signed in to change notification settings - Fork 1
/
GUI.py
34 lines (30 loc) · 968 Bytes
/
GUI.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
import sys
import time
from config import *
from field import Field
field = Field(WIDTH, HEIGHT, CELLSIZE)
last_upd = time.time()
isRunning = True
isUpd = True
while isRunning:
for event in pg.event.get():
if event.type == pg.QUIT:
isRunning = False
sys.exit()
elif event.type == pg.KEYDOWN:
pos = pg.mouse.get_pos()
if event.key == pg.K_1:
field.changeStatus(pos, STATUS.EMPTY)
elif event.key == pg.K_2:
field.changeStatus(pos, STATUS.CONDUCTOR)
elif event.key == pg.K_3:
field.changeStatus(pos, STATUS.HEAD)
elif event.key == pg.K_4:
field.changeStatus(pos, STATUS.TAIL)
elif event.key == pg.K_SPACE:
isUpd = not isUpd
if time.time() - last_upd >= FREQUENCY and isUpd:
field.update()
last_upd = time.time()
field.draw()
pg.display.flip()