Skip to content

Instantly share code, notes, and snippets.

@Getmrahul
Created April 7, 2019 17:35
Show Gist options
  • Save Getmrahul/4cbfdfb9aceba81c95fe76c2fee42e60 to your computer and use it in GitHub Desktop.
Save Getmrahul/4cbfdfb9aceba81c95fe76c2fee42e60 to your computer and use it in GitHub Desktop.
Fun Swift
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