Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- */
- package pollos.elementos;
- import java.util.LinkedList;
- import pollos.escenario.Escenario;
- import pollos.geometria.Orientacion;
- //import pollos.geometria.Posicion;
- import pollos.elementos.Elemento;
- /**
- * @author mila
- *
- */
- public class Elemento {
- private int masa;
- private Escenario escenario;
- /**
- * @return the masa
- */
- public int getMasa() {
- return masa;
- }
- /**
- * @return the escenario
- */
- public Escenario getEscenario() {
- return escenario;
- }
- public int getX(){
- return escenario.getPosicionElemento(this).getX();
- }
- public int getY(){
- return escenario.getPosicionElemento(this).getY();
- }
- public Elemento(int masa){
- this.masa = masa;
- }
- public Elemento(){
- this(1);
- }
- public boolean tieneEscenario(){
- return escenario != null;
- }
- /**
- public boolean tieneEscenario(int x, int y){
- if (escenario.getElemento(x, y)){
- return true;
- }
- }
- **/
- public int masaTotal(){
- Elemento vArriba = escenario.getVecino(this, Orientacion.ARRIBA);
- if(vArriba == null)
- return masa;
- return vArriba.masaTotal()+ masa;
- }
- public int x(){
- return escenario.getAncho();
- }
- public int y(){
- return escenario.getAlto();
- }
- public LinkedList<Elemento> getVecinos(){
- LinkedList <Elemento> vecinos = new LinkedList<Elemento>();
- Elemento elemento = escenario.getVecino(this, Orientacion.ARRIBA);
- if(elemento != null )
- vecinos.add(elemento);
- elemento = escenario.getVecino(this, Orientacion.ABAJO);
- if(elemento != null )
- vecinos.add(elemento);
- elemento = escenario.getVecino(this, Orientacion.DERECHA);
- if(elemento != null )
- vecinos.add(elemento);
- elemento = escenario.getVecino(this, Orientacion.IZQUIERDA);
- if(elemento != null )
- vecinos.add(elemento);
- return vecinos;
- }
- /**
- * @param escenario the escenario to set
- */
- public void setEscenario(Escenario escenario){
- if (tieneEscenario())
- escenario.removeElemento(this); // me tengo q borrar a mi mismo
- this.escenario = escenario;
- }
- public Elemento getVecino(Orientacion orientacion){
- return escenario.getVecino(this, orientacion);
- }
- public boolean mover(Orientacion orientacion){
- return escenario.trasladar(this, orientacion);
- }
- public void desaparecer(){
- if(escenario.estaElemento(this))escenario.removeElemento(this);
- escenario = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement