예제 #1
0
        public void MoveTrainHorizontally(double trainSpeed)
        {
            var random = new Random(123123);

            for (var i = 0; i < 100; i++)
            {
                var world = new World(TileType.GetTileTypes(), new DateTime());

                var train = new Train(0, trainSpeed, true, 0);

                var gridX = random.Next(World.MinGridPosition.X, World.MaxGridPosition.X);
                var gridY = random.Next(World.MinGridPosition.Y, World.MaxGridPosition.Y);

                var trackLength = 5;
                for (var j = 0; j < trackLength; j++)
                {
                    var tile = world.CreateFromName("railStraight", new Int2(j + gridX, gridY), 0);
                    if (j == 0)
                    {
                        tile = tile.With(data: new TileRail(new[] { train }.ToImmutableList()));
                    }
                    world.AddTile(tile);
                }

                var startPos = world.GetTrainPosition(train.Id) ?? new Double2();

                world.MoveTrains(new DateTime() + TimeSpan.FromSeconds(1));

                var endPos = world.GetTrainPosition(train.Id) ?? new Double2();

                Assert.AreEqual(startPos.X + Math.Min(trainSpeed, trackLength), endPos.X, 0.0001);
                Assert.AreEqual(gridY + 0.5, endPos.Y, 0.0001);
            }
        }
예제 #2
0
        public void StackOverflowTest2()
        {
            var world = new World(TileType.GetTileTypes(), new DateTime());

            world.AddTile(
                new Tile(
                    new TileBaseData(5, new Int2(40, 13), 2),
                    new TileRail(new[] { new Train(0.98829291305018363, 4, true, 3) }.ToImmutableList())));

            world.AddTile(new Tile(new TileBaseData(6, new Int2(40, 16), 3), new TileRailFork(ImmutableList <Train> .Empty, true)));

            world.MoveTrains(new DateTime() + TimeSpan.FromMilliseconds(100));
        }
예제 #3
0
        public void StackOverflowTest()
        {
            var world = new World(TileType.GetTileTypes(), new DateTime());

            world.AddTile(
                new Tile(
                    new TileBaseData(world.TileTypes.FindIndex(item => item.CodeName == "railTurn"), new Int2(40, 25), 3),
                    new TileRail(new[] { new Train(0.99785386021710187, 4, true, 3) }.ToImmutableList())));

            world.AddTile("railSplitRight", new Int2(43, 22), 1);

            world.AddTile(new Tile(new TileBaseData(6, new Int2(43, 25), 1), new TileRailFork(ImmutableList <Train> .Empty, true)));

            world.MoveTrains(new DateTime() + TimeSpan.FromMilliseconds(100));
        }
예제 #4
0
        public void TrainFlipsTurnFork()
        {
            var world = new World(TileType.GetTileTypes(), new DateTime());

            var depot = world.CreateFromName("depot", new Int2(), 2);

            world.AddTile(depot);
            var rail = world.CreateFromName("railSplitLeft", new Int2(5, 1), 1);

            world.AddTile(rail);

            world.ClickTile(depot.BaseData);

            world.MoveTrains(new DateTime() + TimeSpan.FromSeconds(3));

            var expected = new[]
            {
                rail.With(data: new TileRailFork(new[] { new Train(0, World.TrainSpeed, false, 0) }.ToImmutableList(), true))
            };

            Assert.AreEqual(expected, world.RailTiles);
        }
예제 #5
0
        public void TrainTurn(bool turnUp)
        {
            var world = new World(TileType.GetTileTypes(), new DateTime());

            var depot = world.CreateFromName("depot", new Int2(), 2);

            world.AddTile(depot);
            var rail = world.CreateFromName("railTurn", new Int2(5, turnUp ? -1 : 1), turnUp ? 0 : 1);

            world.AddTile(rail);

            world.ClickTile(depot.BaseData);

            world.MoveTrains(new DateTime() + TimeSpan.FromSeconds(3));

            var expected = new[]
            {
                rail.With(data: new TileRail(new[] { new Train(turnUp ? 1 : 0, World.TrainSpeed, turnUp, 0) }.ToImmutableList()))
            };

            Assert.AreEqual(expected, world.RailTiles);
        }