Exemplo n.º 1
0
        public void JumpGates()
        {
            var universe = new Universe();

            var sol = new SolarSystem { Name = "Sol", Location = universe };
            var outOfSol = new JumpGate(sol);
            sol.OrbitSun(outOfSol, 45d);

            var alphaCentauri = new SolarSystem {Name = "Alpha Centauri", UniversalCoordinates = new Vector(1000d, 0, 0), Location = universe };

            var intoAlphaCentauri = new JumpGate(alphaCentauri);
            alphaCentauri.OrbitSun(intoAlphaCentauri, 45d);

            outOfSol.ConnectsTo = intoAlphaCentauri;

            var ship = new Ship(new Agent(new Corporation())) {Speed = 2d };
            sol.EnterSystem(ship, outOfSol.LocalCoordinates);

            Assert.AreEqual(sol, ship.SolarSystem);
            Assert.AreEqual(outOfSol.UniversalCoordinates, ship.UniversalCoordinates);

            CollectionAssert.Contains(sol.Objects, ship);
            CollectionAssert.DoesNotContain(alphaCentauri.Objects, ship);

            outOfSol.Jump(ship);

            Assert.AreEqual(alphaCentauri, ship.SolarSystem);
            CollectionAssert.DoesNotContain(sol.Objects, ship);
            CollectionAssert.Contains(alphaCentauri.Objects, ship);

            Assert.AreEqual(intoAlphaCentauri.UniversalCoordinates, ship.UniversalCoordinates);
        }
Exemplo n.º 2
0
        public void IntraSolarSystem()
        {
            var universe = new Universe();
            var sol = new SolarSystem { Location = universe };

            var ship = new Ship(new Agent(new Corporation())) {Speed = 2d, Name = "S1" };
            sol.EnterSystem(ship, new Vector(10, 0, 0));

            ship.Destination = Vector.Zero;

            for (int i=10; i >= 0; i-=2)
            {
                Assert.AreEqual(i, ship.DistanceToDestination, "Ship is heading in the wrong direction!");
                ship.Tick((uint )i);
            }
        }
Exemplo n.º 3
0
            public TestCase()
            {
                Universe = new Universe();

                Seller = new Corporation {Name = "Seller", Location = Universe };
                Buyer = new Corporation {Name = "Buyer", Location = Universe };

                var starCluster = new StarCluster();
                Universe.AddStarCluster(starCluster);

                var sol = new SolarSystem();
                starCluster.AddSolarSystem(sol);

                Refinery = new Refinery(sol, Seller);
                sol.OrbitSun(Refinery, 100d);

                var m1 = new Ship(Seller.Recruit()) {Name = "M1"};
                sol.EnterSystem(m1, Refinery.LocalCoordinates);
                Refinery.Dock(m1);

                var m2 = new Ship(Buyer.Recruit()) {Name = "M2"};
                sol.EnterSystem(m2, Refinery.LocalCoordinates);
                Refinery.Dock(m2);

                this.item = new Ore {Quantity = 1000, Location = Refinery, Owner = Seller};
            }
Exemplo n.º 4
0
        public void MoveToJumpGate()
        {
            var universe = new Universe();
            var starCluster = new StarCluster();
            universe.AddStarCluster(starCluster);

            var sol = new SolarSystem { Name = "Sol" };
            starCluster.AddSolarSystem(sol);

            var alphaCentauri = new SolarSystem { Name = "Alpha Centauri", UniversalCoordinates = new Vector(1.6E9d, 0, 0)};
            starCluster.AddSolarSystem(alphaCentauri);

            var outOfSol = new JumpGate(sol);
            sol.OrbitSun(outOfSol, 45d);

            var intoAlphaCentauri = new JumpGate(alphaCentauri);
            alphaCentauri.OrbitSun(intoAlphaCentauri, 45d);

            outOfSol.ConnectsTo = intoAlphaCentauri;

            var ship = new Ship(new Agent(new Corporation())) { Speed = 20d };
            sol.EnterSystem(ship, new Vector(100d, 0, 0));

            ship.SetTask(new ShipTask(outOfSol, delegate { outOfSol.Jump(ship); return true; }));

            ulong tick = 0L;
            while (ship.SolarSystem == sol)
            {
                Assert.Less(tick, 1000L, "Ship took more than 1000 days to reach the jump gate.");

                starCluster.Tick(tick);
                tick++;
            }

            Console.WriteLine("Ship took {0} days to reach its destination which was a distance of {1:n0}km", tick, (intoAlphaCentauri.UniversalCoordinates - sol.UniversalCoordinates).Magnitude);
        }