void fillGrid() { centerX = _engineOptions.gridWidth / 2; centerY = _engineOptions.gridHeight / 2; for (int x = 0; x < _engineOptions.gridWidth; x++) { for (int y = 0; y < _engineOptions.gridHeight; y++) { AbstractTrackBlock item; if (x == centerX && y == centerY) { item = new DoubleStraightTrackBlock(x, y, 0, this); } else { item = generateTrackPiece(x, y); } grid[x, y] = item; } } Locomotive locomotive = (Locomotive)train.PublicCarList[0]; locomotive.x = centerX; locomotive.y = centerY; locomotive.entry = (TrackSide)(random.Next() % (int)TrackSide.West + 1); locomotive.progress = EngineOptions.blockSections / 2; }
public DoubleStraightChild(DoubleStraightTrackBlock parentBlock, int rotationOffset) : base(parentBlock.x, parentBlock.y, rotationOffset, parentBlock.Parent) { this.parentBlock = parentBlock; }
private AbstractTrackBlock generateTrackPiece(int x, int y) { //give random spin int rotation = random.Next(); AbstractTrackBlock result; if (!_engineOptions.mapWraps) { if (x == 0 || x == _engineOptions.gridWidth - 1 || y == 0 || y == _engineOptions.gridHeight - 1) { // it is on the edge debugLog(String.Format("[{0}, {1}] is on the edge", x, y)); if (random.Next() % 2 == 0) { return(new DoubleCurvedTrackBlock(x, y, rotation, this)); } return(new CurvedTrackBlock(x, y, rotation, this)); } if ((x == 1 || x == _engineOptions.gridWidth - 2) && (y == 1 || y == _engineOptions.gridHeight - 2)) { if (random.Next() % 10 == 0) { return(new DoubleStraightTrackBlock(x, y, rotation, this)); } return(new DoubleCurvedTrackBlock(x, y, rotation, this)); } } TrackType type = (TrackType)(random.Next() % (int)TrackType.Station);//it is assumed that the station is the last one //TODO: add weights switch (type) { case TrackType.Curved: result = new CurvedTrackBlock(x, y, rotation, this); break; case TrackType.Straight: result = new StraightTrackBlock(x, y, rotation, this); break; case TrackType.DoubleCurved: result = new DoubleCurvedTrackBlock(x, y, rotation, this); break; case TrackType.DoubleStraight: result = new DoubleStraightTrackBlock(x, y, rotation, this); break; default: throw new InvalidOperationException( "Unexpected track type " + type + "!"); } return(result); }