AreaMovement.java 2.54 KiB
package pikelake.environment;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;
public class AreaMovement {
	static List<String> area = new ArrayList<String>();
	String saison = null, phaseJour = null;
	int distMin = 0, distMoy = 0, distMax = 0, std = 0;
	StringTokenizer sLigne;
	public AreaMovement(String saisonRef, String phaseJourRef) {
		// Lecture fichier contenant les distances Horaires Cartesienne
		String filePath = "data/input/DistanceHoraireCartesienne_Bro.txt";    	
		Scanner scanner;
		try {
			scanner = new Scanner(new File(filePath));
			// On boucle sur chaque ligne detecte
			String line = scanner.nextLine();
			while (scanner.hasNextLine()) {
				line = scanner.nextLine();		
				// Decoupage ligne : saison ; phase du jour ; distance : minimun, moyenne, maximum et std
				sLigne = new StringTokenizer (line);
				if (sLigne.hasMoreTokens())
					saison = sLigne.nextToken();
				if (sLigne.hasMoreTokens())
					phaseJour = sLigne.nextToken();
				if (sLigne.hasMoreTokens())
					distMin = Integer.parseInt(sLigne.nextToken());
				if (sLigne.hasMoreTokens())
					distMoy = Integer.parseInt(sLigne.nextToken());
				if (sLigne.hasMoreTokens())
					distMax = Integer.parseInt(sLigne.nextToken());
				if (sLigne.hasMoreTokens())
					std = Integer.parseInt(sLigne.nextToken());
				if (saison.equals(saisonRef) & phaseJour.equals(phaseJourRef)) {
					calculationArea (distMax);
					break;
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
	public List<String> calculationArea (int distance) {
		int xi = 0, yi = 0;
		// Conversion distance en nombre de cellule
		int distCell = (int) Math.round(distance/10.);
		// Calcul des coordonnees (x,y) des cellules pour une distance donnee		
		for (xi = -distCell; xi <= distCell; xi++) {			
			yi = (int) Math.round(Math.sqrt(distCell*distCell - xi*xi));
			for (int j = -yi; j <= yi; j++) {
				area.add(xi + " " + j);
		return area;
7172737475767778798081828384858687888990919293949596979899
public int getDistMin () { return distMin; } public int getDistMoy () { return distMoy; } public int getDistMax () { return distMax; } public int getDistStd () { return std; } public String getSaison () { return saison; } public String getPhaseJour () { return phaseJour; } public List<String> getArea () { return area; } }