import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class DirectionJDialog extends JDialog implements KeyListener{
	
	private Monde monde;
	private Entite outil;

	private Point coordPerso=new Point(0,0);
	
	private JLabel info=new JLabel("Choisissez une direction");

	
	private ParcheminFond pfond=new ParcheminFond();
	
	
	public DirectionJDialog(Monde world,Entite tool){
		
		monde=world;
		outil=tool;
		coordPerso=new Point(monde.perso.getCooX(),monde.perso.getCooY());
	
		
		Container c=getContentPane();
		c.setLayout(null);
		
		
		info.setBounds(40,20,200,20);
		c.add(info);
		
		addKeyListener(this);
		
		
		if(monde.jeuPan.lang){
			info.setText("Choose a direction");
		}
		
		info.setFont(world.getPolice());
		
		
		pfond.setBounds(0,0,240,100);
		add(pfond);
		
		
		setLocation(0,0);
		setSize(240,100);
		show();
		
	}
	
	
	/////////////////////////////////////////////////////
	public void keyPressed(KeyEvent e){
		char l=e.getKeyChar();
		
		//System.out.println("DIRECTION CHAR= "+l);
		
		if(l=='7'){
			System.out.println("Direction choisie= NO");
			double x=coordPerso.getX();
			double y=coordPerso.getY();
			double xCible=x-1;
			double yCible=y-1;
			//monde.perso.targetPoint.setLocation(xCible,yCible);
			monde.perso.actionSurCible(outil,new Point((int)xCible,(int)yCible));
			dispose();
		}
		
		if(l=='8'){
			System.out.println("Direction choisie= N");
			double x=coordPerso.getX();
			double y=coordPerso.getY();
			double xCible=x;
			double yCible=y-1;
			//monde.perso.targetPoint.setLocation(xCible,yCible);
			monde.perso.actionSurCible(outil,new Point((int)xCible,(int)yCible));
			dispose();
		}
		
		if(l=='9'){
			System.out.println("Direction choisie= NE");
			double x=coordPerso.getX();
			double y=coordPerso.getY();
			double xCible=x+1;
			double yCible=y-1;
			//monde.perso.targetPoint.setLocation(xCible,yCible);
			monde.perso.actionSurCible(outil,new Point((int)xCible,(int)yCible));
			dispose();
		}
		
		if(l=='4'){
			System.out.println("Direction choisie= O");
			double x=coordPerso.getX();
			double y=coordPerso.getY();
			double xCible=x-1;
			double yCible=y;
			//monde.perso.targetPoint.setLocation(xCible,yCible);
			//monde.perso.actionSurCible(outil);
			monde.perso.actionSurCible(outil,new Point((int)xCible,(int)yCible));
			dispose();
		}
		
		if(l=='5'){
			System.out.println("Direction choisie= self");
			double x=coordPerso.getX();
			double y=coordPerso.getY();
			double xCible=x;
			double yCible=y;
			//monde.perso.targetPoint.setLocation(xCible,yCible);
			//monde.perso.actionSurCible(outil);
			monde.perso.actionSurCible(outil,new Point((int)xCible,(int)yCible));
			dispose();
		}
		
		if(l=='6'){
			System.out.println("Direction choisie= E");
			double x=coordPerso.getX();
			double y=coordPerso.getY();
			double xCible=x+1;
			double yCible=y;
			//monde.perso.targetPoint.setLocation(xCible,yCible);
			//monde.perso.actionSurCible(outil);
			monde.perso.actionSurCible(outil,new Point((int)xCible,(int)yCible));
			dispose();
		}
		
		if(l=='1'){
			System.out.println("Direction choisie= SO");
			double x=coordPerso.getX();
			double y=coordPerso.getY();
			double xCible=x-1;
			double yCible=y+1;
			//monde.perso.targetPoint.setLocation(xCible,yCible);
			//monde.perso.actionSurCible(outil);
			monde.perso.actionSurCible(outil,new Point((int)xCible,(int)yCible));
			dispose();
		}
		
		if(l=='2'){
			System.out.println("Direction choisie= S");
			double x=coordPerso.getX();
			double y=coordPerso.getY();
			double xCible=x;
			double yCible=y+1;
			//monde.perso.targetPoint.setLocation(xCible,yCible);
			//monde.perso.actionSurCible(outil);
			monde.perso.actionSurCible(outil,new Point((int)xCible,(int)yCible));
			dispose();
		}
		
		if(l=='3'){
			System.out.println("Direction choisie= SE");
			double x=coordPerso.getX();
			double y=coordPerso.getY();
			double xCible=x+1;
			double yCible=y+1;
			//monde.perso.targetPoint.setLocation(xCible,yCible);
			//monde.perso.actionSurCible(outil);
			monde.perso.actionSurCible(outil,new Point((int)xCible,(int)yCible));
			dispose();
		}
		
		
	}
	public void keyReleased(KeyEvent e){}
	
	public void keyTyped(KeyEvent e){}
	
	
}