Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

Unit.java 2.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package structures.basic;
  2. import com.fasterxml.jackson.annotation.JsonIgnore;
  3. import com.fasterxml.jackson.databind.ObjectMapper;
  4. /**
  5. * This is a representation of a Unit on the game board.
  6. * A unit has a unique id (this is used by the front-end.
  7. * Each unit has a current UnitAnimationType, e.g. move,
  8. * or attack. The position is the physical position on the
  9. * board. UnitAnimationSet contains the underlying information
  10. * about the animation frames, while ImageCorrection has
  11. * information for centering the unit on the tile.
  12. *
  13. * @author Dr. Richard McCreadie
  14. *
  15. */
  16. public class Unit {
  17. @JsonIgnore
  18. protected static ObjectMapper mapper = new ObjectMapper(); // Jackson Java Object Serializer, is used to read java objects from a file
  19. int id;
  20. UnitAnimationType animation;
  21. Position position;
  22. UnitAnimationSet animations;
  23. ImageCorrection correction;
  24. public Unit() {}
  25. public Unit(int id, UnitAnimationSet animations, ImageCorrection correction) {
  26. super();
  27. this.id = id;
  28. this.animation = UnitAnimationType.idle;
  29. position = new Position(0,0,0,0);
  30. this.correction = correction;
  31. this.animations = animations;
  32. }
  33. public Unit(int id, UnitAnimationSet animations, ImageCorrection correction, Tile currentTile) {
  34. super();
  35. this.id = id;
  36. this.animation = UnitAnimationType.idle;
  37. position = new Position(currentTile.getXpos(),currentTile.getYpos(),currentTile.getTilex(),currentTile.getTiley());
  38. this.correction = correction;
  39. this.animations = animations;
  40. }
  41. public Unit(int id, UnitAnimationType animation, Position position, UnitAnimationSet animations,
  42. ImageCorrection correction) {
  43. super();
  44. this.id = id;
  45. this.animation = animation;
  46. this.position = position;
  47. this.animations = animations;
  48. this.correction = correction;
  49. }
  50. public int getId() {
  51. return id;
  52. }
  53. public void setId(int id) {
  54. this.id = id;
  55. }
  56. public UnitAnimationType getAnimation() {
  57. return animation;
  58. }
  59. public void setAnimation(UnitAnimationType animation) {
  60. this.animation = animation;
  61. }
  62. public ImageCorrection getCorrection() {
  63. return correction;
  64. }
  65. public void setCorrection(ImageCorrection correction) {
  66. this.correction = correction;
  67. }
  68. public Position getPosition() {
  69. return position;
  70. }
  71. public void setPosition(Position position) {
  72. this.position = position;
  73. }
  74. public UnitAnimationSet getAnimations() {
  75. return animations;
  76. }
  77. public void setAnimations(UnitAnimationSet animations) {
  78. this.animations = animations;
  79. }
  80. /**
  81. * This command sets the position of the Unit to a specified
  82. * tile.
  83. * @param tile
  84. */
  85. @JsonIgnore
  86. public void setPositionByTile(Tile tile) {
  87. position = new Position(tile.getXpos(),tile.getYpos(),tile.getTilex(),tile.getTiley());
  88. }
  89. }