Track feature #21
|
@ -157,6 +157,12 @@ public class Track implements TrackSpecification {
|
||||||
return vector;
|
return vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void drawCharOnTrackIndicator(PositionVector positionVector, char symbol) {
|
||||||
|
String line = track.get(positionVector.getY());
|
||||||
|
line = line.substring(0,positionVector.getX()) + symbol + line.substring(positionVector.getX()+1);
|
||||||
|
track.add(positionVector.getY(),line);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return all Cars
|
* @return all Cars
|
||||||
*/
|
*/
|
||||||
|
@ -184,22 +190,24 @@ public class Track implements TrackSpecification {
|
||||||
* @param carIndex representing the current Car
|
* @param carIndex representing the current Car
|
||||||
*/
|
*/
|
||||||
public void moveCar(int carIndex) {
|
public void moveCar(int carIndex) {
|
||||||
PositionVector positionVector = findChar(getCarId(carIndex));
|
makeCarMoveInTrack(carIndex);
|
||||||
//Removes the Car at Current Pos
|
|
||||||
String line = track.get(positionVector.getY());
|
|
||||||
line = line.substring(0,positionVector.getX()) + ConfigSpecification.SpaceType.TRACK.getValue() + line.substring(positionVector.getX()+1);
|
|
||||||
track.add(positionVector.getY(),line);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
track.add(positionVector.getY(),line);
|
|
||||||
|
|
||||||
//Change position of car
|
//Change position of car
|
||||||
getCar(carIndex).move();
|
getCar(carIndex).move();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class does change the Position of the car only in the track.
|
||||||
|
* @param carIndex
|
||||||
|
*/
|
||||||
|
private void makeCarMoveInTrack(int carIndex) {
|
||||||
|
PositionVector positionVector = findChar(getCarId(carIndex));
|
||||||
|
//Removes the Car at Current Pos
|
||||||
|
drawCharOnTrackIndicator(positionVector,ConfigSpecification.SpaceType.TRACK.getValue());
|
||||||
|
//Adds Car at new Position
|
||||||
|
positionVector = cars.get(carIndex).nextPosition();
|
||||||
|
drawCharOnTrackIndicator(positionVector,cars.get(carIndex).getID());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This Method will check if the Car could crash at the specific position
|
* This Method will check if the Car could crash at the specific position
|
||||||
* @param positionVector the position to check if the car could crash
|
* @param positionVector the position to check if the car could crash
|
||||||
|
@ -210,6 +218,19 @@ public class Track implements TrackSpecification {
|
||||||
return charAtPosition != ConfigSpecification.SpaceType.TRACK.value;
|
return charAtPosition != ConfigSpecification.SpaceType.TRACK.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Method will make the Car Crash. In Track and in the Car Object
|
||||||
|
* @param carIndex representing current Car
|
||||||
|
* @param positionVector where the Crash did happen
|
||||||
|
*/
|
||||||
|
public void carDoesCrash(int carIndex,PositionVector positionVector) {
|
||||||
|
Car car = cars.get(carIndex);
|
||||||
|
car.crash();
|
||||||
|
makeCarMoveInTrack(carIndex);
|
||||||
|
drawCharOnTrackIndicator(new PositionVector(positionVector.getX()+1,positionVector.getY()),CRASH_INDICATOR);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the type of space at the given position.
|
* Return the type of space at the given position.
|
||||||
* If the location is outside the track bounds, it is considered a wall.
|
* If the location is outside the track bounds, it is considered a wall.
|
||||||
|
|
Loading…
Reference in New Issue