Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBenjamin Lim
2,747 PointsType 'Enemy' does not conform to protocol 'Attackable' I'm not sure what's wrong, but i copied and paste from the gist
class Enemy: PlayerType, Destructable , Attackable, Movable { var position: Point var life: Int = 10 var strength: Int = 5 var range: Int = 2
required init(point: Point) {
self.position = point
}
func decreaseLife(factor: Int) {
self.life -= factor
}
func attack(var player: PlayerType) {
player.life = player.life - strength
}
func move(direction: Direction, distance: Int) {
switch direction {
case .Up: position.y += 1
case .Down: position.y -= 1
case .Left: position.x -= 1
case .Right: position.x += 1
}
}
}
2 Answers
Berry Loeffen
4,303 PointsThe struct Point needs its properties set to var in stead of let. Also some of the protocols names are spelled a little differently in the code snippets compared to what we wrote with the instructor, so check if the spelling is the same
Dustin Spengler
5,480 Pointsmaybe try taking out the "var" from the attack function parameters? even if thats not the issue it will be deprecated soon.
Daniel Cohen
5,785 PointsIf I remove 'var' from the attack function parameter then I get an error "cannot assign to property 'player' is a 'let' constant". If I leave it in then i get a warning that var parameters are deprecated and will be removed in Swift 3. What am I supposed to do if I don't use a var parameter?
Steven Deutsch
21,046 PointsSteven Deutsch
21,046 PointsCan I see your Attackable protocol please? Thanks :)