Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package br.uefs.ecomp.Game.model;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.LinkedList;
- import java.util.Scanner;
- /**
- * Classe responsável por ler o arquivo de configuração e tratar seus dados.
- *
- * @author Daniel Andrade
- * @author Cássio Santos
- */
- public class ReadSettingsFile {
- File file;
- private final Scanner read;
- private final int numberOfSpots;
- private final LinkedList<Spot> spots;
- private final LinkedList<Road> roads;
- public ReadSettingsFile(String path) throws FileNotFoundException {
- file = new File(path);
- read = new Scanner(file);
- this.numberOfSpots = read.nextInt();
- this.spots = new LinkedList<>();
- this.roads = new LinkedList<>();
- this.generateData();
- }
- public int getNumberOfSpots() {
- return this.numberOfSpots;
- }
- /**
- * Faz a leitura fo arquivo e trata os dados.
- *
- * @throws FileNotFoundException
- */
- private void generateData() throws FileNotFoundException {
- Scanner dRead = new Scanner(this.file);
- dRead.useDelimiter("\\n|;|[)]|[(]|,");
- dRead.next();//Tira primeiro número
- Spot s;
- //Leitura dos lugares e das coordenadas.
- for (int i = 0; i < this.numberOfSpots; i++) {
- s = new Spot(dRead.next());
- dRead.next();//vazio
- s.setX(Integer.parseInt(dRead.next()));
- s.setY(Integer.parseInt(dRead.next()));
- spots.add(s);
- dRead.next();//vazio
- }
- //Lendo e adicionando origem e destino das ligações na lista
- while (dRead.hasNext()) {
- String a = dRead.next();
- String b = dRead.next();
- this.getRoads().add(new Road(a, b));
- }
- this.read.close();
- dRead.close();
- }
- public LinkedList<Spot> getSpots() {
- return spots;
- }
- public LinkedList<Road> getRoads() {
- return roads;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement