mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final1.git
synced 2024-11-27 18:55:55 +00:00
Correctly handle placing already placed trains and correctly handle small trains on larger rails
This commit is contained in:
parent
9191028934
commit
2746b9e7cf
@ -320,7 +320,7 @@ public class ModelRailwaySimulation {
|
||||
*/
|
||||
public boolean putTrain(final int trainId, final Vector2D position, final Vector2D direction) {
|
||||
Train train = getTrain(trainId);
|
||||
if (train == null || !train.isProperTrain()) {
|
||||
if (train == null || !train.isProperTrain() || train.isPlaced()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -290,7 +290,7 @@ public final class Train {
|
||||
// we are really leaving this rail
|
||||
occupiedRails.remove(leavingRail);
|
||||
} // else: we are still on the rail
|
||||
} else if (getLength() == 1) {
|
||||
} else if (getLength() == 1 && railNetwork.findContainingRail(secondToLastPosition) == null) {
|
||||
// we evidently just moved into another rail
|
||||
occupiedRails.clear();
|
||||
} // else: only touched rail
|
||||
@ -298,7 +298,7 @@ public final class Train {
|
||||
Rail nextRail = railNetwork.findContainingRail(nextPosition);
|
||||
if (nextRail != null) {
|
||||
occupiedRails.add(nextRail);
|
||||
} else if (getLength() == 1) {
|
||||
} else if (getLength() == 1 && railNetwork.findContainingRail(secondToLastPosition) == null) {
|
||||
// we evidently just moved into another rail
|
||||
Rail[] nextTouchingRails = railNetwork.findTouchingRails(nextPosition);
|
||||
Rail[] alreadyTouchingRails = railNetwork.findTouchingRails(secondToLastPosition);
|
||||
|
Loading…
Reference in New Issue
Block a user