Esempio 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);
        }
Esempio n. 2
0
File: Ship.cs Progetto: andy-uq/Echo
        public void Jump(JumpGate gate)
        {
            if (UniversalCoordinates == gate.UniversalCoordinates)
                gate.Jump(this);
            else
            {
                this.destination = null;

                this.target = gate;
                this.targetAction = ((ship, shipTarget) =>
                                     {
                                     	gate.Jump(ship);
                                     	return false;
                                     });
            }
        }
Esempio n. 3
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);
        }