Created
October 12, 2014 22:50
-
-
Save andrei512/0800340f0508a8db77dd to your computer and use it in GitHub Desktop.
class properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tank { | |
class var bonusDamage: Double { | |
return Double(Upgrade.level) * 2.5 | |
} | |
let baseDamage = 10.0 | |
var damage: Double { | |
return self.baseDamage + Tank.bonusDamage | |
} | |
class func upgrade() { | |
Upgrade.level += 1 | |
} | |
struct Upgrade { | |
static var level = 0 | |
} | |
} | |
var tank = Tank() | |
println(tank.damage) | |
// 10.0 | |
Tank.upgrade() | |
println(tank.damage) | |
// 12.5 | |
Tank.upgrade() | |
println(tank.damage) | |
// 15.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment