implemented calculate winner and needed int in in car to hold winpoints.
This commit is contained in:
parent
e94053fee8
commit
b606f20d9f
|
@ -24,6 +24,10 @@ public class Car implements CarSpecification {
|
||||||
* Current position of the car on the track grid using a {@link PositionVector}
|
* Current position of the car on the track grid using a {@link PositionVector}
|
||||||
*/
|
*/
|
||||||
private PositionVector position;
|
private PositionVector position;
|
||||||
|
/**
|
||||||
|
* Points that car is holding for determining winner.
|
||||||
|
*/
|
||||||
|
private int winPoints;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current velocity of the car using a {@link PositionVector}
|
* Current velocity of the car using a {@link PositionVector}
|
||||||
|
@ -59,6 +63,18 @@ public class Car implements CarSpecification {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void increaseWinPoints() {
|
||||||
|
winPoints ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deductWinPoints() {
|
||||||
|
winPoints --;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWinPoints() {
|
||||||
|
return winPoints;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current velocity of the car as a PositionVector.
|
* Returns the current velocity of the car as a PositionVector.
|
||||||
*
|
*
|
||||||
|
|
|
@ -272,36 +272,36 @@ public class Game implements GameSpecification {
|
||||||
switch (track.getSpaceType(point)) {
|
switch (track.getSpaceType(point)) {
|
||||||
case FINISH_UP:
|
case FINISH_UP:
|
||||||
if(start.getY() < finish.getY()) {
|
if(start.getY() < finish.getY()) {
|
||||||
//track.getCar(carIndex).addWinPoint;
|
track.getCar(carIndex).increaseWinPoints();
|
||||||
//TODO: add point
|
|
||||||
}
|
}
|
||||||
else if(start.getY() < finish.getY()) {
|
else if(start.getY() < finish.getY()) {
|
||||||
//TODO: deduct point
|
track.getCar(carIndex).deductWinPoints();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FINISH_DOWN:
|
case FINISH_DOWN:
|
||||||
if(start.getY() > finish.getY()){
|
if(start.getY() > finish.getY()){
|
||||||
//track.getCar(carIndex).addWinPoint;
|
track.getCar(carIndex).increaseWinPoints();
|
||||||
}
|
}
|
||||||
else if (start.getY() < finish.getY()){
|
else if (start.getY() < finish.getY()){
|
||||||
|
track.getCar(carIndex).deductWinPoints();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FINISH_RIGHT:
|
case FINISH_RIGHT:
|
||||||
if(start.getX() < finish.getX()){
|
if(start.getX() < finish.getX()){
|
||||||
//track.getCar(carIndex).addWinPoint;
|
track.getCar(carIndex).increaseWinPoints();
|
||||||
}
|
}
|
||||||
else if (start.getX() < finish.getX()){
|
else if (start.getX() < finish.getX()){
|
||||||
|
track.getCar(carIndex).deductWinPoints();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FINISH_LEFT:
|
case FINISH_LEFT:
|
||||||
if(start.getX() > finish.getX()){
|
if(start.getX() > finish.getX()){
|
||||||
//track.getCar(carIndex).addWinPoint;
|
track.getCar(carIndex).increaseWinPoints();
|
||||||
}
|
}
|
||||||
else if (start.getX() < finish.getX()){
|
else if (start.getX() < finish.getX()){
|
||||||
|
track.getCar(carIndex).increaseWinPoints();
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue