Track feature #21

Merged
fassband merged 9 commits from track-feature into main 2022-03-11 18:41:11 +01:00
1 changed files with 12 additions and 6 deletions
Showing only changes of commit 46e6b838c2 - Show all commits

View File

@ -193,15 +193,21 @@ public class Track implements TrackSpecification {
//Adds Car at new Position
positionVector = cars.get(carIndex).nextPosition();
line = track.get(positionVector.getY());
line = line.substring(0,positionVector.getX()) + cars.get(carIndex).getId() + line.substring(positionVector.getX()+1);
line = line.substring(0,positionVector.getX()) + cars.get(carIndex).getID() + line.substring(positionVector.getX()+1);
track.add(positionVector.getY(),line);
//Change position of car
getCar(carIndex).move();
}
public char getRealCharAtPosition(PositionVector positionVector) {
return track.get(positionVector.getY()).charAt(positionVector.getX());
/**
* This Method will check if the Car could crash at the specific position
* @param positionVector the position to check if the car could crash
* @return true if car would crash. Else false.
*/
public boolean willCrashAtPosition(PositionVector positionVector) {
char charAtPosition = track.get(positionVector.getY()).charAt(positionVector.getX());
return charAtPosition != ConfigSpecification.SpaceType.TRACK.value;
}
/**
@ -255,7 +261,7 @@ public class Track implements TrackSpecification {
*/
@Override
public char getCarId(int carIndex) {
return cars.get(carIndex).getId();
return cars.get(carIndex).getID();
}
/**
@ -267,7 +273,7 @@ public class Track implements TrackSpecification {
*/
@Override
public PositionVector getCarPos(int carIndex) {
return findChar(cars.get(carIndex).getId());
return findChar(cars.get(carIndex).getID());
}
/**
@ -294,7 +300,7 @@ public class Track implements TrackSpecification {
public char getCharAtPosition(int y, int x, Config.SpaceType currentSpace) {
char charAtPos = track.get(y).charAt(x);
for (Car car : cars) {
if(charAtPos == car.getId()) {
if(charAtPos == car.getID()) {
if(car.isCrashed()) {
return CRASH_INDICATOR;
}