Created
April 7, 2019 17:35
-
-
Save Getmrahul/4cbfdfb9aceba81c95fe76c2fee42e60 to your computer and use it in GitHub Desktop.
Fun Swift
This file contains hidden or 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 King { | |
var power = 100 | |
var health = 100 | |
let maxHealth = 100 | |
let maxPower = 100 | |
func attack() { | |
if self.isDead() { | |
print("🤴 is dead!") | |
return | |
} | |
print("Attacking with \((power * maxPower) / 100)% power!") | |
self.damage() | |
} | |
private func damage() { | |
health -= 10 | |
power -= 10 | |
} | |
private func isDead() -> Bool { | |
return power == 0 || health == 0 | |
} | |
} | |
let 🤴 = King.init() | |
for _ in (0...10) { | |
🤴.attack() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment