-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathque.py
73 lines (66 loc) · 2.42 KB
/
que.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
import node
import pygame
import sys
import time
class Queue:
def __init__(self, screen, img_list, menu, buttons_set_active):
self.nodeList = []
self.queueList = []
self.screen = screen
self.center = self.screen.get_rect().center
self.img_list = img_list
self.menu = menu
self.currentSize = 0
self.buttons_set_active = buttons_set_active
def displayUpdate(self):
# pygame.event.pump()
self.buttons_set_active(0)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
self.menu.react(event)
# odświeżenie screena
for i in range(len(self.nodeList)):
self.nodeList[i].nodeBG()
for i in range(len(self.nodeList)):
self.nodeList[i].grow_cvp(-5, -40)
pygame.display.update()
self.buttons_set_active(1)
def shift_nodes(self):
for i in range(self.currentSize):
self.nodeList[i].nodeX += 50
self.displayUpdate()
def push(self, value):
if not self.nodeList:
n = node.Node(self.center[0] - 128, self.center[1], str(value), self.screen, self.img_list[7])
else:
n = node.Node(self.nodeList[0].nodeX - 100, self.nodeList[0].nodeY, str(value), self.screen,
self.img_list[7])
self.currentSize += 1
self.nodeList.insert(0, n)
self.queueList.insert(0, value)
while self.nodeList[0].nodeSize < self.nodeList[0].oriSize[0]:
self.displayUpdate()
if self.currentSize > 1:
self.shift_nodes()
time.sleep(0.5)
self.nodeList[0].nodeSize = self.nodeList[0].oriSize[0]
if self.nodeList[0].nodeSize == self.nodeList[0].oriSize[0]:
self.nodeList[0].oriNodeImg = self.img_list[4]
self.displayUpdate()
def pop(self):
self.nodeList[len(self.nodeList) - 1].oriNodeImg = self.img_list[6]
self.displayUpdate()
time.sleep(0.5)
if self.currentSize > 1:
del self.nodeList[len(self.nodeList) - 1]
self.queueList.pop()
self.currentSize -= 1
self.shift_nodes()
return
if self.currentSize == 1:
self.nodeList[0].nodeBG()
del self.nodeList[0]
self.queueList.pop()
self.currentSize -= 1
pygame.display.update()