mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final1.git
synced 2024-11-24 09:24:58 +00:00
Correctly crash touching trains
This commit is contained in:
parent
43ee608975
commit
2e336a9bcb
@ -479,7 +479,7 @@ public class ModelRailwaySimulation {
|
||||
}
|
||||
boolean anyIntersection = occupiedByOtherTrain.stream().anyMatch(occupiedByThisTrain::contains)
|
||||
|| occupiedByOtherTrainPreviously.stream().anyMatch(occupiedByThisTrain::contains);
|
||||
if (anyIntersection) {
|
||||
if (anyIntersection || train.touches(otherTrain)) {
|
||||
train.removeFromRails();
|
||||
otherTrain.removeFromRails();
|
||||
// try to find/merge existing collisions
|
||||
|
@ -357,7 +357,7 @@ public final class Train {
|
||||
* @return whether this train touches the other train
|
||||
*/
|
||||
public boolean touches(final Train other) {
|
||||
return other.isOnAnyPosition(position);
|
||||
return position != null && other.isOnAnyPosition(position);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -373,7 +373,7 @@ public final class Train {
|
||||
* @return whether this train is on any of the specified positions
|
||||
*/
|
||||
public boolean isOnAnyPosition(final List<Vector2D> positions) {
|
||||
return position.stream().anyMatch(positions::contains);
|
||||
return position != null && position.stream().anyMatch(positions::contains);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,3 +170,13 @@ create engine steam T5 Worsch 9 true true
|
||||
add train 8 T5-Worsch
|
||||
put train 8 at (0,0) in direction 0,-1
|
||||
create engine electrical T5 Kühnlein 17 true true
|
||||
add train 9 T5-Kühnlein
|
||||
delete track 1
|
||||
delete track 2
|
||||
delete track 3
|
||||
delete track 4
|
||||
add track (-100,0) -> (0,0)
|
||||
add track (0,0) -> (100,0)
|
||||
put train 8 at (1,0) in direction -1,0
|
||||
put train 9 at (-1,0) in direction 1,0
|
||||
step 1
|
||||
|
@ -194,3 +194,13 @@ T5-Worsch
|
||||
steam engine T5-Worsch added to train 8
|
||||
Error, could not place train
|
||||
T5-Kühnlein
|
||||
electrical engine T5-Kühnlein added to train 9
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
1
|
||||
2
|
||||
OK
|
||||
OK
|
||||
Crash of train 8,9
|
||||
|
Loading…
Reference in New Issue
Block a user