-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
92 lines (76 loc) · 2.53 KB
/
main.py
File metadata and controls
92 lines (76 loc) · 2.53 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
import pygame
import concurrent.futures
import time
import sys
import itertools
from gameoflife import pool
from ui import uicontroller, displayedobject, controlbar, colors, labelbutton
import entities
from settings import *
#LIFE_STATUS_CODE = {
# 'DEAD': 0,
# 'BORD': 1,
# 'LIVE': 2,
# }
FOR_EVER_AND_EVER = True
def dump_board(board):
print('\n'.join(''.join(str(x) for x in y) for y in board))
def loop():
while FOR_EVER_AND_EVER:
ui.get_mouse_event()
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
while not ui.events.empty():
event = ui.events.get_nowait()
for object in itertools.chain(ui.pools, ui.controlbars):
if object.is_in_range(event.pos):
object.interact(event.pos)
ui.events.task_done()
for pool in ui.pools:
if not pool.obj.paused:
pool.obj.populate()
ui.display_life(pool.obj.map)
#ui.delay()
if __name__ == "__main__":
pool1 = pool.Pool(
(CELLS_X, CELLS_Y),
threads=THREADS,
entities=[
#(entities.GOSPER_GLIDER_GUN, 0, 0),
])
with uicontroller.UIcontroller() as ui:
ui.add_pool(
displayedobject.DisplayedObject(
pool1,
(0, 0),
(CELLS_X * CELL_SPX, CELLS_Y * CELL_SPX)))
ui.add_controlbar(
displayedobject.DisplayedObject(
controlbar.ControlBar(
(WIN_SX, ACTION_BOX_H),
bg_color=colors.HEXA['grey'],
content=[
labelbutton.LabelButton(
"Pause/Resume",
pool1.pause,
font_size=15,
margin=5,
padding=5),
labelbutton.LabelButton(
"Reset",
pool1.restore_seed,
font_size=15,
margin=5,
padding=5),
labelbutton.LabelButton(
"Save",
pool1.save_seed,
font_size=15,
margin=5,
padding=5)
]),
(0, SANDBOX_SY),
(WIN_SX, ACTION_BOX_H)))
ui.generate()
loop()