Untitled

 avatar
user_9243973
plain_text
2 years ago
877 B
2
Indexable
public class Robot {
	
	String nom;
	String direction;
	int x;
	int y;
	
	public Robot(String nom)
	{
		this.nom=nom; x=0; y=0; direction="Est";
	}
	
	public Robot(String nom,int x,int y,String direction)
	{
		this.nom=nom; this.x=x; this.y=y; this.direction=direction;
	}
	
	
	void avance()
	{
		if(direction.equals("Est")) x++;
		else if (direction.equals("Nord")) y++;
		else if (direction.equals("Sud")) y--;
		else if (direction.equals("Ouest")) x--;
	}
	
	
	void droite()
	{
		if(direction.equals("Est")) direction="Sud";
		else if(direction.equals("Nord")) direction="Est";
		else if(direction.equals("Sud")) direction="Ouest";
		else if(direction.equals("Ouest")) direction="Nord";
	}
	
	
	void affiche()
	{
		System.out.println("le robot "+nom+" : " +"[ position : x="+x+" y="+y+" ; direction="
				+ direction+ " ]");
	}

}