The code is written in Swift 2.0. I am doing a little tinkering project for clash of clans. My code is below.
enum Resource {
case gold
case elixer
case darkElixer
}
class Avatar {
var cost, health, damage, space: Int
var costType: Resource
init(damage: Int, health: Int, cost: Int, costType: Resource, space: Int){
self.damage = damage
self.health = health
self.cost = cost
self.costType = costType
self.space = space
}
}
class Barbarian: Avatar {
init() {
super.init(damage: 44, health: 110, cost: 200, costType: .elixer, space: 1)
}
}
class Archer: Avatar {
init() {
super.init(damage: 22, health: 44, cost: 400, costType: .elixer, space: 1)
}
}
I am trying this function.
func troopCost(troop: Avatar, quantity: Int) -> (Int, Resource){
let rResource = troop.costType
let rCost = troop.cost * quantity
return (rCost, rResource)
}
When I call the function like this.
troopCost(Barbarian, quantity: 2)
I get this error.
Cannon invoke 'troopCost' with an argument list of type '(Barbarian.Type, quantity: Int)'