Advertisement
PifyZ

Untitled

Feb 8th, 2015
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 0.64 KB | None | 0 0
  1. use stdio as io
  2.  
  3. const ATTACK = 99
  4.  
  5. struct Warrior {
  6.     String name,
  7.     Int life
  8. }
  9.  
  10. Warrior yannick = Warrior { name = "Yannick", life = 100 }
  11. Warrior guillaume = Warrior { name = "Yannick", life = 0xFFFF }
  12.  
  13. Bool attack(Warrior attacker, ref attacked) {
  14.     for i = 0 to ATTACK by 1 {
  15.         attacked.life -= 1
  16.     }
  17.  
  18.     if attacked.life < 0 {
  19.         attacked.life = 0
  20.     }
  21.  
  22.     return attacked.life == 0
  23. }
  24.  
  25. Bool died = false
  26.  
  27. while not died {
  28.     Bool died = attack(attacked = yannick, attacker = guillaume)
  29.  
  30.     if not died {
  31.         io.println("Il reste ${yannick.life} points de vie à ${yannick.name}")
  32.     }
  33. }
  34.  
  35. io.println("${yannick.name} est mort au combat")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement