finished method currentCarIndex, switchToNextActiveCar, willCarCrash

This commit is contained in:
Leonardo Brandenberger 2022-03-11 10:37:54 +01:00
parent dd987a5a14
commit e159274085
1 changed files with 15 additions and 6 deletions

View File

@ -82,8 +82,7 @@ public class Game implements GameSpecification {
*/
@Override
public int getCurrentCarIndex() {
// TODO: implementation
throw new UnsupportedOperationException();
return currentCarIndex;
}
/**
@ -163,8 +162,12 @@ public class Game implements GameSpecification {
*/
@Override
public void switchToNextActiveCar() {
// TODO: implementation
throw new UnsupportedOperationException();
do {
if (currentCarIndex++ > track.getCarCount()) {
currentCarIndex = 0;
}
} while (track.getCar(currentCarIndex).isCrashed());
// TODO: evtl andere Kapselung
}
/**
@ -181,7 +184,7 @@ public class Game implements GameSpecification {
*/
@Override
public List<PositionVector> calculatePath(PositionVector startPosition, PositionVector endPosition) {
ArrayList pathList = new ArrayList<PositionVector>();
ArrayList<PositionVector> pathList = new ArrayList<>();
// Use Bresenham's algorithm to determine positions.
int x = startPosition.getX();
int y = startPosition.getY();
@ -246,7 +249,13 @@ public class Game implements GameSpecification {
@Override
public boolean willCarCrash(int carIndex, PositionVector position) {
List<PositionVector> positionList = calculatePath(track.getCarPos(carIndex),position);
for(PositionVector location : positionList) {
if(track.willCrashAtPosition(location)) {
return true;
}
}
return false;
}
}