public GameOverException(AbstractTrainCar crashCar) { this.crashCar = crashCar; }
private void moveTrain() { int speed = speeds[curSpeedIndex]; AbstractTrainCar crashCar = null; foreach (var item in trainList) { int sections = item.progress; sections += speed; AbstractTrackBlock curBlock = this[item.x, item.y]; TrackSide entry = item.entry; while (sections > EngineOptions.blockSections) { sections -= EngineOptions.blockSections; TrackSide entrySide = entry; //discover the output edge AbstractTrackBlock subBlock = curBlock.getPieceOnSide( entrySide); TrackEnds endOnSide = subBlock.getEndOnSide(entrySide); //find the side the other end is on TrackEnds otherEnd = endOnSide == TrackEnds.A ? TrackEnds.B : TrackEnds.A; TrackSide exit = (TrackSide)(-1); TrackEnds[] ends = subBlock.getTrackEnds(); for (int i = 0; i < (int)TrackSide.West + 1; i++) { if (ends[i] == otherEnd) { exit = (TrackSide)i; break; } } AbstractTrackBlock nextBlock = getAdjacentBlock( curBlock, exit, true); if (nextBlock == null) { //crash crashCar = item; //so other blocks will travel the right distance... speed -= sections; sections = EngineOptions.blockSections; } else { curBlock = nextBlock; entry = invertSide(exit); } } item.progress = sections; item.x = curBlock.x; item.y = curBlock.y; item.entry = entry; debugLog("Car " + item.trainIndex + " is now at " + item.x + "," + item.y + " and " + item.progress + "sections entering " + "from side " + item.entry + "."); } if (crashCar != null) { gameOverHappened = true; throw new GameOverException(crashCar); } }