Advertisement
Guest User

Untitled

a guest
May 27th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. package server.game.mobile;
  2.  
  3. /**
  4. * The container class that represents a hit.
  5. *
  6. * @author Tim
  7. */
  8. public final class Hit {
  9.  
  10. /**
  11. * The amount of damage within this hit.
  12. */
  13. private final int damage;
  14.  
  15. /**
  16. * The hit type represented by this hit.
  17. */
  18. private final HitType type;
  19.  
  20. /**
  21. * Creates a new {@link Hit}.
  22. *
  23. * @param damage
  24. * the amount of damage within this hit.
  25. * @param type
  26. * the hit type represented by this hit.
  27. */
  28. public Hit(int damage, HitType type) {
  29. if (damage == 0 && type == HitType.NORMAL) {
  30. type = HitType.BLOCKED;
  31. } else if (damage > 0 && type == HitType.BLOCKED) {
  32. damage = 0;
  33. } else if (damage < 0) {
  34. damage = 0;
  35. }
  36. this.damage = damage;
  37. this.type = type;
  38. }
  39.  
  40. /**
  41. * Creates a new {@link Hit} with a {@code type} of {@code NORMAL}.
  42. *
  43. * @param damage
  44. * the amount of damage within this hit.
  45. */
  46. public Hit(int damage) {
  47. this(damage, HitType.NORMAL);
  48. }
  49.  
  50. /**
  51. * A substitute for {@link Object#clone()} that creates another 'copy' of
  52. * this instance. The created copy is <i>safe</i> meaning it does not hold
  53. * <b>any</b> references to the original instance.
  54. *
  55. * @return a reference-free copy of this instance.
  56. */
  57. public Hit copy() {
  58. return new Hit(damage, type);
  59. }
  60.  
  61. /**
  62. * Gets the amount of damage within this hit.
  63. *
  64. * @return the amount of damage within this hit.
  65. */
  66. public int getDamage() {
  67. return damage;
  68. }
  69.  
  70. /**
  71. * Gets the hit type represented by this hit.
  72. *
  73. * @return the hit type represented by this hit.
  74. */
  75. public HitType getType() {
  76. return type;
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement