Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. /**
  2. *
  3. */
  4. package pollos.elementos;
  5.  
  6. import java.util.LinkedList;
  7. import pollos.escenario.Escenario;
  8. import pollos.geometria.Orientacion;
  9. //import pollos.geometria.Posicion;
  10. import pollos.elementos.Elemento;
  11.  
  12. /**
  13. * @author mila
  14. *
  15. */
  16. public class Elemento {
  17. private int masa;
  18. private Escenario escenario;
  19.  
  20. /**
  21. * @return the masa
  22. */
  23. public int getMasa() {
  24. return masa;
  25. }
  26.  
  27. /**
  28. * @return the escenario
  29. */
  30. public Escenario getEscenario() {
  31. return escenario;
  32. }
  33.  
  34. public int getX(){
  35. return escenario.getPosicionElemento(this).getX();
  36. }
  37.  
  38. public int getY(){
  39. return escenario.getPosicionElemento(this).getY();
  40. }
  41.  
  42. public Elemento(int masa){
  43. this.masa = masa;
  44. }
  45.  
  46. public Elemento(){
  47. this(1);
  48. }
  49.  
  50. public boolean tieneEscenario(){
  51. return escenario != null;
  52. }
  53.  
  54. /**
  55. public boolean tieneEscenario(int x, int y){
  56. if (escenario.getElemento(x, y)){
  57. return true;
  58. }
  59. }
  60. **/
  61.  
  62.  
  63. public int masaTotal(){
  64. Elemento vArriba = escenario.getVecino(this, Orientacion.ARRIBA);
  65. if(vArriba == null)
  66. return masa;
  67. return vArriba.masaTotal()+ masa;
  68. }
  69.  
  70. public int x(){
  71. return escenario.getAncho();
  72. }
  73.  
  74. public int y(){
  75. return escenario.getAlto();
  76. }
  77.  
  78. public LinkedList<Elemento> getVecinos(){
  79. LinkedList <Elemento> vecinos = new LinkedList<Elemento>();
  80. Elemento elemento = escenario.getVecino(this, Orientacion.ARRIBA);
  81.  
  82. if(elemento != null )
  83. vecinos.add(elemento);
  84. elemento = escenario.getVecino(this, Orientacion.ABAJO);
  85. if(elemento != null )
  86. vecinos.add(elemento);
  87. elemento = escenario.getVecino(this, Orientacion.DERECHA);
  88. if(elemento != null )
  89. vecinos.add(elemento);
  90. elemento = escenario.getVecino(this, Orientacion.IZQUIERDA);
  91. if(elemento != null )
  92. vecinos.add(elemento);
  93. return vecinos;
  94. }
  95.  
  96. /**
  97. * @param escenario the escenario to set
  98. */
  99. public void setEscenario(Escenario escenario){
  100. if (tieneEscenario())
  101. escenario.removeElemento(this); // me tengo q borrar a mi mismo
  102. this.escenario = escenario;
  103. }
  104.  
  105. public Elemento getVecino(Orientacion orientacion){
  106. return escenario.getVecino(this, orientacion);
  107. }
  108.  
  109. public boolean mover(Orientacion orientacion){
  110. return escenario.trasladar(this, orientacion);
  111. }
  112.  
  113. public void desaparecer(){
  114. if(escenario.estaElemento(this))escenario.removeElemento(this);
  115. escenario = null;
  116. }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement