Guest User

Untitled

a guest
Dec 15th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. class Weapon {
  2. // W konstruktorze mozesz ustawiac property
  3. public Weapon(string name, short power) {
  4. this.Name = name;
  5. this.Power = power;
  6. }
  7.  
  8. public string Name { get; }
  9. public short Power { get; }
  10. }
  11.  
  12. class Player {
  13. // Kazdy moze zmienic bron
  14. public Weapon { get; set; }
  15.  
  16. // Kazdy moze zobaczyc ile zycia ma player,
  17. // ale tylko player moze zmienic swoj stan
  18. public short Life { get; private set; }
  19.  
  20. // Kazdy moze sprawdzic czy player jest jeszcze zywy
  21. // Ale nikt nie moze tego ustawic, sprawdzane jest
  22. // dynamicznie na podstawie stany zycia gracza
  23. public bool IsAlive {
  24. get {
  25. return this.Life > 0;
  26. }
  27. }
  28.  
  29. // Player zostal trafiony przez jakas bron
  30. // i otrzymal od niej obrazenia
  31. public void HitBy(Weapon weapon) {
  32. this.Life -= weapon.Power;
  33. }
  34.  
  35. // Player zaatakowal innego gracza
  36. public void Attack(Player player) {
  37. player.HitBy(this.Weapon);
  38. }
  39. }
Add Comment
Please, Sign In to add comment