Ejemplo n.º 1
0
        public void SidewalkTileCollisionBug()
        {
            var world = new World(_tileTypes, new DateTime());

            world.AddTile("sidewalk", new Int2());
            world.AddTile("redHouse", new Int2(1, 0));

            Assert.AreEqual(2, world.TileCount);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        public void ClickingOnDepotSendsOutTrain()
        {
            var world = new World(TileType.GetTileTypes(), new DateTime());

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

            world.AddTile(depot);
            world.AddTile(world.CreateFromName("railStraight", new Int2(6, 1), 0));

            Assert.IsTrue(world.ClickTile(depot.BaseData));
            var expected = new[]
            {
                depot.With(data: new TileDepot(new[] { new Train(1, World.TrainSpeed, false, 0) }.ToImmutableList(), false))
            };

            Assert.AreEqual(expected, world.RailTiles);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public void AddAndGetTile(int tileX, int tileY, int superGridX, int superGridY, bool tileInRegion)
        {
            var world = new World(_tileTypes, new DateTime());

            world.AddTile("redHouse", new Int2(tileX, tileY), 0);

            var result = world.GetRegion(new Int2(superGridX, superGridY));

            var expected = tileInRegion
                ? new[] { world.CreateFromName("redHouse", new Int2(tileX, tileY), 0) }
                : new Tile[0];

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 9
0
        public void RemoveTest()
        {
            var world = new World(_tileTypes, new DateTime());

            var seed    = 123123;
            var random0 = new Random(seed);

            for (int i = 0; i < 10000; i++)
            {
                var tile = RandomTile(random0, World.MinGridPosition, World.MaxGridPosition);
                world.AddTile(tile);
            }

            var random1 = new Random(seed);

            for (int i = 0; i < 10000; i++)
            {
                var tile = RandomTile(random1, World.MinGridPosition, World.MaxGridPosition);
                world.Remove(tile.BaseData);
            }

            Assert.AreEqual(0, world.TileCount);
        }