-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeck.lua
More file actions
50 lines (37 loc) · 1.21 KB
/
deck.lua
File metadata and controls
50 lines (37 loc) · 1.21 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
require('lib/middleclass/middleclass')
require('cardcontainer')
BaseDeck = class("BaseDeck")
--Base class that other decks can inherit from
function BaseDeck:initialize()
self.library = CardContainer:new()
self.hand = CardContainer:new()
self.graveyard = CardContainer:new()
end
function BaseDeck:gain( card, location, order )
location = location or "library"
order = order or "top"
assert(card ~= nil, 'Must specify a card')
--Add the card to the location, in the order specified
self[location]:gain(card, order)
end
--Trash a card from a location
function BaseDeck:trash( index, location )
assert(location ~= nil, "Must specify a location")
assert(index ~= nil, "Must specify a card")
--Remove the card from the location?
self[location]:trash(index)
end
function BaseDeck:shuffle( location )
location = location or "library"
--Redo ordering of that location
self[location]:shuffle()
end
--Convenience function to draw a card from library to hand
function BaseDeck:draw()
self:movecard("library", "hand", 1, "top")
end
--Move a card from one location to another
function BaseDeck:movecard( from_loc, to_loc, from_index, to_pos )
card = self[from_loc]:pop(from_index)
self[to_loc]:gain(card, to_pos)
end