-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCardManager.lua
More file actions
59 lines (54 loc) · 1.58 KB
/
CardManager.lua
File metadata and controls
59 lines (54 loc) · 1.58 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
require "cards.BaseCard"
require "cards.FireballCard"
require "cards.HealCard"
require "cards.BoltCard"
require "cards.TorrentCard"
require "cards.PoisonCard"
require "cards.RageCard"
require "cards.BlessingCard"
require "cards.TyphoonCard"
require "cards.PunchCard"
require "cards.SliceCard"
require "cards.PortalCard"
require "cards.ForceFieldCard"
-- Static class responsible for creating card instances based on their names
CardManager = {}
CardManager.__index = CardManager
function CardManager:new(ctx)
if not ctx then
error("CardManager:new(ctx) requires ctx")
end
local manager = {
ctx = ctx,
cardTypes = {
["fireball"] = FireballCard,
["heal"] = HealCard,
["bolt"] = BoltCard,
["torrent"] = TorrentCard,
["poison"] = PoisonCard,
["rage"] = RageCard,
["blessing"] = BlessingCard,
["typhoon"] = TyphoonCard,
["punch"] = PunchCard,
["slice"] = SliceCard,
["portal"] = PortalCard,
["forcefield"] = ForceFieldCard
},
cardNames = {}
}
for cardName, _ in pairs(manager.cardTypes) do
table.insert(manager.cardNames, cardName)
end
return setmetatable(manager, self)
end
function CardManager:createCard(cardName)
local CardClass = self.cardTypes[string.lower(cardName)]
if CardClass then
return CardClass:new(self.ctx, 0, 0)
else
error("Unknown card type: " .. tostring(cardName))
end
end
function CardManager:getAllCardNames()
return self.cardNames
end