-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaitingline.lua
44 lines (36 loc) · 899 Bytes
/
waitingline.lua
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
require "human"
WaitingLine = {}
WaitingLine.__index = WaitingLine
function WaitingLine:create()
local waitingline = {}
setmetatable(waitingline, WaitingLine)
waitingline.first = 0
waitingline.last = -1
return waitingline
end
function WaitingLine:push(human)
local first = self.first - 1
self.first = first
self[first] = human
end
function WaitingLine:pushFront(human)
local last = self.last + 1
self.last = last
self[last] = human
end
function WaitingLine:pop()
local last = self.last
if self.first > self.last then return nil end
local human = self[last]
self[last] = nil
self.last = last - 1
return human
end
function WaitingLine:getSize()
return self.last - self.first + 1
end
function WaitingLine:draw(x, y, turn)
for i = self.last, self.first, -1 do
self[i]:draw(x, y, self.last - i, turn)
end
end