- Methoden überarbeitet

Teils provisorisch da genaue Umsetzung noch unklar
Siehe TODO
This commit is contained in:
Andrin Fassbind 2022-03-07 17:49:55 +01:00
parent 571728b6fd
commit 007d8ee393
2 changed files with 37 additions and 14 deletions

View File

@ -94,7 +94,7 @@ public class Track implements TrackSpecification {
} }
} }
public void findCar() { public void addCar() {
ConfigSpecification.SpaceType[] spaceTypes = ConfigSpecification.SpaceType.values(); ConfigSpecification.SpaceType[] spaceTypes = ConfigSpecification.SpaceType.values();
ArrayList<Character> allSpaceTypesAsChar = new ArrayList<>(); ArrayList<Character> allSpaceTypesAsChar = new ArrayList<>();
@ -113,6 +113,19 @@ public class Track implements TrackSpecification {
} }
private PositionVector findChar(char symbol) {
PositionVector vector = null;
for (int i = 0; i < track.size(); i++) {
String line = track.get(i);
for (int j = 0; j < line.length(); j++) {
if (line.charAt(j) == symbol) {
vector = new PositionVector(j,i);
}
}
}
return vector;
}
private void findFinish() { private void findFinish() {
//TODO: //TODO:
@ -155,8 +168,9 @@ public class Track implements TrackSpecification {
*/ */
@Override @Override
public int getCarCount() { public int getCarCount() {
// TODO: implementation // TODO: error???
throw new UnsupportedOperationException(); return cars.size();
//throw new UnsupportedOperationException();
} }
/** /**
@ -167,8 +181,9 @@ public class Track implements TrackSpecification {
*/ */
@Override @Override
public Car getCar(int carIndex) { public Car getCar(int carIndex) {
// TODO: implementation // TODO: error???
throw new UnsupportedOperationException(); return cars.get(carIndex);
//throw new UnsupportedOperationException();
} }
/** /**
@ -179,8 +194,9 @@ public class Track implements TrackSpecification {
*/ */
@Override @Override
public char getCarId(int carIndex) { public char getCarId(int carIndex) {
// TODO: implementation // TODO: error???
throw new UnsupportedOperationException(); return cars.get(carIndex).getID();
//throw new UnsupportedOperationException();
} }
/** /**
@ -191,8 +207,14 @@ public class Track implements TrackSpecification {
*/ */
@Override @Override
public PositionVector getCarPos(int carIndex) { public PositionVector getCarPos(int carIndex) {
// TODO: implementation // TODO: nextPosition or Position of Trackfile?
throw new UnsupportedOperationException(); //Alternative 1
return cars.get(carIndex).nextPosition();
//Alternative 2 //NULL aussschliessen falls umgesetzt.
return findChar(cars.get(carIndex).getID());
//throw new UnsupportedOperationException();
} }
/** /**
@ -203,8 +225,9 @@ public class Track implements TrackSpecification {
*/ */
@Override @Override
public PositionVector getCarVelocity(int carIndex) { public PositionVector getCarVelocity(int carIndex) {
// TODO: implementation // TODO: error???
throw new UnsupportedOperationException(); return cars.get(carIndex).getVelocity();
//throw new UnsupportedOperationException();
} }
/** /**
@ -229,7 +252,7 @@ public class Track implements TrackSpecification {
*/ */
@Override @Override
public String toString() { public String toString() {
// TODO: implementation // TODO: error???
String str = ""; String str = "";
for (String line : track) { for (String line : track) {
str += line+"\n"; str += line+"\n";

View File

@ -44,8 +44,8 @@ public class TrackTest {
//TODO: //TODO:
@Test @Test
void findCarAtInit() { void addCarAtInit() {
trackObj.findCar(); trackObj.addCar();
} }
} }