- Method toString done
This commit is contained in:
parent
8ff70ab3ac
commit
571728b6fd
|
@ -6,6 +6,7 @@ import ch.zhaw.pm2.racetrack.given.TrackSpecification;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
@ -61,6 +62,8 @@ public class Track implements TrackSpecification {
|
||||||
|
|
||||||
// TODO: Add necessary variables
|
// TODO: Add necessary variables
|
||||||
private List<String> track;
|
private List<String> track;
|
||||||
|
private List<Car> cars;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a Track from the given track file.
|
* Initialize a Track from the given track file.
|
||||||
*
|
*
|
||||||
|
@ -69,7 +72,9 @@ public class Track implements TrackSpecification {
|
||||||
* @throws InvalidTrackFormatException if the track file contains invalid data (no tracklines, ...)
|
* @throws InvalidTrackFormatException if the track file contains invalid data (no tracklines, ...)
|
||||||
*/
|
*/
|
||||||
public Track(File trackFile) throws FileNotFoundException, InvalidTrackFormatException {
|
public Track(File trackFile) throws FileNotFoundException, InvalidTrackFormatException {
|
||||||
// TODO: implementation
|
// TODO:
|
||||||
|
track = new ArrayList<>();
|
||||||
|
cars = new ArrayList<>();
|
||||||
readFile(trackFile);
|
readFile(trackFile);
|
||||||
|
|
||||||
//TODO: throw error again...
|
//TODO: throw error again...
|
||||||
|
@ -78,20 +83,43 @@ public class Track implements TrackSpecification {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method reads the File and saves it to the track ArrayList Line by Line
|
* This method reads the File and saves it to the track ArrayList Line by Line
|
||||||
|
*
|
||||||
* @param trackFile the File where the track has been documented
|
* @param trackFile the File where the track has been documented
|
||||||
* @throws FileNotFoundException if the FilePath is invalid.
|
* @throws FileNotFoundException if the FilePath is invalid.
|
||||||
*/
|
*/
|
||||||
private void readFile(File trackFile) throws FileNotFoundException {
|
private void readFile(File trackFile) throws FileNotFoundException {
|
||||||
track = new ArrayList<>();
|
|
||||||
Scanner scanner = new Scanner(trackFile);
|
Scanner scanner = new Scanner(trackFile);
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
track.add(scanner.nextLine());
|
track.add(scanner.nextLine());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void findCar() {
|
||||||
|
ConfigSpecification.SpaceType[] spaceTypes = ConfigSpecification.SpaceType.values();
|
||||||
|
ArrayList<Character> allSpaceTypesAsChar = new ArrayList<>();
|
||||||
|
|
||||||
|
for (ConfigSpecification.SpaceType spaceType : spaceTypes) {
|
||||||
|
allSpaceTypesAsChar.add(spaceType.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (String line : track) {
|
||||||
|
for (int i = 0; i < line.length(); i++) {
|
||||||
|
if (!allSpaceTypesAsChar.contains(line.charAt(i))) {
|
||||||
|
//TODO: CREATE CAR - ADD IT TO CARS - BUT CHECK THAT Symbol is not allready used for another car?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void findFinish() {
|
||||||
|
//TODO:
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return the track
|
* @return the track
|
||||||
*/
|
*/
|
||||||
public List<String> getTrack() {
|
public List<String> getTrack() {
|
||||||
|
@ -111,7 +139,6 @@ public class Track implements TrackSpecification {
|
||||||
char charAtPosition = track.get(position.getY()).charAt(position.getX());
|
char charAtPosition = track.get(position.getY()).charAt(position.getX());
|
||||||
|
|
||||||
ConfigSpecification.SpaceType[] spaceTypes = ConfigSpecification.SpaceType.values();
|
ConfigSpecification.SpaceType[] spaceTypes = ConfigSpecification.SpaceType.values();
|
||||||
|
|
||||||
for (ConfigSpecification.SpaceType spaceType : spaceTypes) {
|
for (ConfigSpecification.SpaceType spaceType : spaceTypes) {
|
||||||
if (spaceType.getValue() == charAtPosition) {
|
if (spaceType.getValue() == charAtPosition) {
|
||||||
return spaceType;
|
return spaceType;
|
||||||
|
@ -203,6 +230,11 @@ public class Track implements TrackSpecification {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
// TODO: implementation
|
// TODO: implementation
|
||||||
throw new UnsupportedOperationException();
|
String str = "";
|
||||||
|
for (String line : track) {
|
||||||
|
str += line+"\n";
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
//throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,6 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TrackTest {
|
public class TrackTest {
|
||||||
|
@ -36,20 +33,19 @@ public class TrackTest {
|
||||||
* Dirty test...
|
* Dirty test...
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void compareTrack() {
|
void printOutTrack() {
|
||||||
try {
|
System.out.println(trackObj);
|
||||||
List<String> track = trackObj.getTrack();
|
|
||||||
for (String s: track
|
|
||||||
) {
|
|
||||||
System.out.println(s);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.err.println("Error in Test compareTrack" + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getSpaceTyp() {
|
void getSpaceTyp() {
|
||||||
Assertions.assertEquals(ConfigSpecification.SpaceType.FINISH_RIGHT,trackObj.getSpaceType(new PositionVector(22,24)));
|
Assertions.assertEquals(ConfigSpecification.SpaceType.FINISH_RIGHT,trackObj.getSpaceType(new PositionVector(22,24)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO:
|
||||||
|
@Test
|
||||||
|
void findCarAtInit() {
|
||||||
|
trackObj.findCar();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue