-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhand.lua
More file actions
61 lines (50 loc) · 1.25 KB
/
hand.lua
File metadata and controls
61 lines (50 loc) · 1.25 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
local class = require "middleclass"
local love = require "love"
local Hand = class("Hand")
function Hand:initialize(cards, belongs_to)
self.cards = cards
self.belongs_to = belongs_to -- player ID
self.subdecks = {}
self.numsubdecks = 0
self:update()
end
function Hand:update()
self:updatesubdecks()
end
function Hand:draw()
end
function Hand:add(card)
print('added card ' .. card.id .. ' to our hand')
table.insert(self.cards, card)
end
function Hand:updatesubdecks()
self.numsubdecks = 0
self.subdecks = {}
for i = 1, #self.cards, 1 do
local card = self.cards[i]
if self.subdecks[card.suit .. card.subdeck] == nil then
self.numsubdecks = self.numsubdecks + 1
self.subdecks[card.suit .. card.subdeck] = {}
end
table.insert(self.subdecks[card.suit .. card.subdeck], card)
end
end
function Hand:count()
return #self.cards
end
function Hand:remove(cardid)
local idx = -1
for i = 1, #self.cards, 1 do
if self.cards[i].id == cardid then
idx = i
break
end
end
if idx > -1 then
local removed = table.remove(self.cards, idx)
return removed
else
return nil
end
end
return Hand