public class Gate extends Entite{
	
	Entite objet=new Entite();
	
	private String nom=new String();
	//private String nomEquipement=new String();
	
	private String modele=new String();
	
	private boolean ouvert=false;
	private boolean casse=false;
	private boolean transparent=false;
	
	private boolean unlocked=false;
	private int complexiteSerrure=0;
	
	private boolean visible=true;
	
	private String tileStrFerme=new String();
	private String tileStrOuvert=new String();
	private String tileStrCache=new String();
	
	private String sonOuverture=new String();
	private String sonFermeture=new String();
	
	private int poids=0;
	
	private int resistanceMat=0;
	private int structureMat=0;
	
	private boolean verrouillable=true;
	
	private int niveau=0;
	
	private String nomE=new String();
	
	public String getNomE(){
		return nomE;
	}
	
	public Gate(String name,String nameE,boolean unlockedC,int complexiteSerrureC,boolean ouv,boolean brok,String modeleC,boolean visibleC,String tileFerme,String tileOuvert,String tileCache,String sndOuvert,String sndFerm){
		
		//niveau=Math.round((complexiteSerrureC-100)/10);
		niveau=Math.round((complexiteSerrureC-95)/5);
		if(niveau<0){niveau=0;}
		
		
		nom=name;
		nomE=nameE;
		modele=modeleC;
		unlocked=unlockedC;
		complexiteSerrure=complexiteSerrureC;
		ouvert=ouv;
		casse=brok;
		visible=visibleC;
		tileStrFerme=tileFerme;
		tileStrOuvert=tileOuvert;
		tileStrCache=tileCache;
		sonOuverture=sndOuvert;
		sonFermeture=sndFerm;
		//nomEquipement=nom;
		
		
		
		if(modele.compareTo("standarddoor")==0){
			
			structureMat=20;
			resistanceMat=70;
			poids=100;
		}
		
		if(modele.compareTo("standardwindow")==0){
			
			structureMat=10;
			resistanceMat=20;
			poids=50;
			transparent=true;
		}
		
		
		
	}
	
	
	
	//////////////////////////////////////////
	public boolean getTransparent(){
		return transparent;
	}
	
	public void setTransparent(boolean t){
		transparent=t;
	}
	
	
	public boolean getVerrouillable(){
		return verrouillable;
	}
	
	
	/*
	public String getNomDequipement(){
		return nomEquipement;
	}
	
	public void setNomDequipement(String nomEquip){
		nomEquipement=nomEquip;
	}
	*/
	
	public String getNom(){
		return nom;
	}
	
	public int getComplexiteSerrure(){
		return complexiteSerrure;
	}
	
	public void setComplexiteSerrure(int cs){
		complexiteSerrure=cs;
	}
	
	public void setUnlocked(boolean dever){
		unlocked=dever;
	}
	
	public boolean getUnlocked(){
		return unlocked;
	}
	
	
	
	public void setOuvert(boolean ouv){
		ouvert=ouv;
		if(ouvert){setVisible(true);
		}
		
	}
	public boolean getOuvert(){
		return ouvert;
	}
	public void setCasse(boolean broken){
		casse=broken;
		
		if(casse==true){
		
			unlocked=true;
			ouvert=true;
			visible=true;
		}	
		
		
	}
	
	
	public boolean getCasse(){
		return casse;
	}
	
	
	
	public int getResistanceMat(){
		return resistanceMat;
	}
	
	public void setResistanceMat(int res){
		resistanceMat=res;
	}
	
	public int getStructureMat(){
		return structureMat;
	}
	
	public void setStructureMat(int struct){
		structureMat=struct;
	}
	
	public String getModele(){
		return modele;
	}
	
	public int getPoids(){
		return poids;
	}
	
	public void setPoids(int pds){
		poids=pds;
	}
	
	public boolean getVisible(){
		return visible;
	}
	
	public void setVisible(boolean visibility){
		visible=visibility;
	}
	
	
	
	public String getTileStr(){
		
		if(getCasse()==true){
			return "./images/doors/rocks.gif";
		}
			
		if(ouvert==true){
			return tileStrOuvert;
		}
		else{
			return tileStrFerme;
		}
				
	}
	
	public String getTileCache(){
		return tileStrCache;
	}
	
	public int getNiveau(){
		return niveau;
	}
	
	
	
	
	
	
	public void bruit(){
		if(ouvert==true){
			ThreadSon son=new ThreadSon(sonFermeture,0);
			son.start();
		}
		else{
			ThreadSon son=new ThreadSon(sonOuverture,0);
			son.start();
		}
	}
	
	
	
	
	public void bruit(Monde monde,int vx,int vy){ 
	// a quoi servent vx et vy ? = à cause de la methode dans Entite !
	
			
		for(int x=0;x<monde.tailleGrille;x++){
        	for(int y=0;y<monde.tailleGrille;y++){
        		
				if(!monde.grille[x][y].isEmpty()){
					
		 			for(int i=0;i<monde.grille[x][y].size();i++){
					
			 				objet = (Entite)monde.grille[x][y].get(i);		
		 				
							
							if(objet.equals(this)){
								System.out.println("GATE EN "+x+" "+y);
								vx=x;
								vy=y;
							}
						
		 				
		 			}
		 		}
        	}
        }
		
		
		float vol=0;
		int px=monde.perso.getCooX();
		int py=monde.perso.getCooY();
		
		int dx=Math.abs(vx-px);
		int dy=Math.abs(vy-py);
		
		if(dx>dy){vol=(float)dx*(-1);
		}
		else{vol=(float)dy*(-1);
		}
		
		vol=Math.round(vol/2);
		
		if(vol<-20){vol=-20;
		}
		
			if(ouvert==true){
			ThreadSon son=new ThreadSon(sonFermeture,vol);
			son.start();
		}
		else{
			ThreadSon son=new ThreadSon(sonOuverture,vol);
			son.start();
		}
		
	}
	
	
	
	
	
	
}