Merge pull request #19 from PM2-IT21bWIN-ruiz-mach-krea/car
created Branch car
This commit is contained in:
commit
d6a46f3cae
|
@ -3,6 +3,8 @@ package ch.zhaw.pm2.racetrack;
|
||||||
import ch.zhaw.pm2.racetrack.given.CarSpecification;
|
import ch.zhaw.pm2.racetrack.given.CarSpecification;
|
||||||
import ch.zhaw.pm2.racetrack.strategy.MoveStrategy;
|
import ch.zhaw.pm2.racetrack.strategy.MoveStrategy;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing a car on the racetrack.
|
* Class representing a car on the racetrack.
|
||||||
* Uses {@link PositionVector} to store current position on the track grid and current velocity vector.
|
* Uses {@link PositionVector} to store current position on the track grid and current velocity vector.
|
||||||
|
@ -48,17 +50,39 @@ public class Car implements CarSpecification {
|
||||||
setPosition(position);
|
setPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the id of the car.
|
||||||
|
*
|
||||||
|
* @return id of the car.
|
||||||
|
*/
|
||||||
|
public char getID(){
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current velocity of the car as a PositionVector.
|
||||||
|
*
|
||||||
|
* @return velocity current velocity of the car.
|
||||||
|
*/
|
||||||
|
public PositionVector getVelocity(){
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Set this Car position directly, regardless of current position and velocity.
|
* Set this Car position directly, regardless of current position and velocity.
|
||||||
* This should only be used by the game controller in rare cases to set the crash or winning position.
|
* This should only be used by the game controller in rare cases to set the crash or winning position.
|
||||||
* The next position is normaly automatically calculated and set in the {@link #move()} method.
|
* The next position is normaly automatically calculated and set in the {@link #move()} method.
|
||||||
*
|
*
|
||||||
* @param position The new position to set the car directly to.
|
* @param position The new position to set the car directly to.
|
||||||
|
* @throws IllegalArgumentException if invalid PositionVector is given.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setPosition(final PositionVector position) {
|
public void setPosition(final PositionVector position) {
|
||||||
// TODO: implementation
|
if (position.getX() < 0 || position.getY() < 0) {
|
||||||
throw new UnsupportedOperationException();
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,8 +93,7 @@ public class Car implements CarSpecification {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PositionVector nextPosition() {
|
public PositionVector nextPosition() {
|
||||||
// TODO: implementation
|
return new PositionVector(position.getX() + velocity.getX(),position.getY() + velocity.getY());
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,11 +103,18 @@ public class Car implements CarSpecification {
|
||||||
* Changes only velocity, not position.
|
* Changes only velocity, not position.
|
||||||
*
|
*
|
||||||
* @param acceleration A Direction vector containing the amounts to add to the velocity in x and y dimension
|
* @param acceleration A Direction vector containing the amounts to add to the velocity in x and y dimension
|
||||||
|
* @throws IllegalArgumentException if PositionVector is not in allowed area.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void accelerate(PositionVector.Direction acceleration) {
|
public void accelerate(PositionVector.Direction acceleration) {
|
||||||
// TODO: implementation
|
if(acceleration.vector.getX() < -1 || acceleration.vector.getX() > 1||
|
||||||
throw new UnsupportedOperationException();
|
acceleration.vector.getY() < -1 || acceleration.vector.getY() > 1) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
velocity = new PositionVector(velocity.getX() + acceleration.vector.getX(),
|
||||||
|
velocity.getY() + acceleration.vector.getY());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,8 +122,7 @@ public class Car implements CarSpecification {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void move() {
|
public void move() {
|
||||||
// TODO: implementation
|
position = new PositionVector(position.getX() + velocity.getX(), position.getY() + velocity.getY());
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,8 +130,7 @@ public class Car implements CarSpecification {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void crash() {
|
public void crash() {
|
||||||
// TODO: implementation
|
crashed = true;
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,13 +140,12 @@ public class Car implements CarSpecification {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isCrashed() {
|
public boolean isCrashed() {
|
||||||
// TODO: implementation
|
return crashed;
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set move strategy
|
* Set move strategy
|
||||||
* @param moveStrategy
|
* @param moveStrategy Strategy to be implemented
|
||||||
*/
|
*/
|
||||||
public void setMoveStrategy(MoveStrategy moveStrategy) {
|
public void setMoveStrategy(MoveStrategy moveStrategy) {
|
||||||
this.moveStrategy = moveStrategy;
|
this.moveStrategy = moveStrategy;
|
||||||
|
|
Loading…
Reference in New Issue