public void AddWorldObjectTest() { Planet planet1 = new Planet(); WorldObject[] worldObjects = {planet1}; World target = new World(worldObjects); WorldObject spaceship1 = new Spaceship(); WorldObject spaceship2 = new Spaceship(); WorldObject projectile = new Projectile(); WorldObject explosion = new Explosion(); WorldObject planet2 = new Planet(); target.AddWorldObject(spaceship1); target.AddWorldObject(spaceship2); target.AddWorldObject(projectile); target.AddWorldObject(explosion); target.AddWorldObject(planet2); Assert.IsTrue((new List<WorldObject>(target.WorldObjects)).Contains(planet1)); Assert.IsTrue((new List<WorldObject>(target.WorldObjects)).Contains(spaceship1)); Assert.IsTrue((new List<WorldObject>(target.WorldObjects)).Contains(spaceship2)); Assert.IsTrue((new List<WorldObject>(target.WorldObjects)).Contains(projectile)); Assert.IsTrue((new List<WorldObject>(target.WorldObjects)).Contains(explosion)); Assert.IsTrue((new List<WorldObject>(target.WorldObjects)).Contains(planet2)); }
public void Initialize() { ConfigurationReader configurationReader = new ConfigurationReader(new BinaryFormatter(), null); configuration = configurationReader.Read("config.cfg"); mockCollisionHandler = new Mock<CollisionHandler>(); planet = new Planet(); planet.Mass = 100000; // asume 40.0 * 40.0 world, planet is in the center planet.Position = new Vector2(20.0f, 20.0f); planet.Velocity = new Vector2(0.0f, 0.0f); world = new World(new WorldObject[0]); }
/// <summary> /// Creates a new GameModel and its subcomponents. /// </summary> /// <returns>The created GameModel.</returns> public GameModel BuildModel() { // build game objects Planet planet = new Planet(); planet.Radius = 300; // build planet in orbit int distance = 700; Planet planet2 = new Planet(); planet2.Radius = 82; planet2.IsFlexible = true; planet2.Position = new Vector2(distance, 0); // calculate velocity needed to circuit in orbit float planet2Velocity = (float) Math.Sqrt(planet.Mass * GameAssets.G / distance / (GameAssets.N * 1000)); planet2.Velocity = new Vector2(0, planet2Velocity); Spaceship spaceship1 = new Spaceship(); Spaceship spaceship2 = new Spaceship(); Player player1 = new HumanPlayer(1, this.playerHandler, Color.Green, this.configuration.GetKeyboardConfiguration(1)); Player player2 = new HumanPlayer(2, this.playerHandler, Color.Orange, this.configuration.GetKeyboardConfiguration(2)); player1.Spaceship = spaceship1; player2.Spaceship = spaceship2; player1.Spaceship.Position = new Vector2(-1900, 0); player2.Spaceship.Position = new Vector2(1900, 0); List<Player> players = new List<Player>(); players.Add(player1); players.Add(player2); WorldObject[] worldObjects = {planet, planet2, spaceship1, spaceship2}; // build ShortLifespanObjectFactory ShortLifespanObjectFactory shortLifespanObjectFactory = new SimpleShortLifespanObjectFactory(); // build game model World world = new World(worldObjects); Physics physics = new SimplePhysicsAlgorithm(this.collisionHandler, world, configuration); GameModel gameModel = new GameModel(shortLifespanObjectFactory, physics, players, world); return gameModel; }
public void RemoveWorldObjectTest() { Projectile projectile1 = new Projectile(); Projectile projectile2 = new Projectile(); Spaceship spaceship = new Spaceship(); Planet planet = new Planet(); Explosion explosion = new Explosion(); WorldObject[] worldObjects = { projectile1, projectile2, spaceship, planet, explosion }; World target = new World(worldObjects); target.RemoveWorldObject(projectile1); target.RemoveWorldObject(projectile2); target.RemoveWorldObject(spaceship); target.RemoveWorldObject(explosion); Assert.IsFalse((new List<WorldObject>(target.WorldObjects)).Contains(projectile1)); Assert.IsFalse((new List<WorldObject>(target.WorldObjects)).Contains(projectile2)); Assert.IsFalse((new List<WorldObject>(target.WorldObjects)).Contains(spaceship)); Assert.IsFalse((new List<WorldObject>(target.WorldObjects)).Contains(explosion)); Assert.IsTrue((new List<WorldObject>(target.WorldObjects)).Contains(planet)); }
public void UpdateDifficultyTest() { Mock<ConfigurationRetriever> mockConfRet = new Mock<ConfigurationRetriever>(); mockConfRet.SetupGet(m => m.Difficulty).Returns(1); // set up a big planet Planet bigPlanet = new Planet(); bigPlanet.IsFlexible = false; bigPlanet.Position = new Vector2(0, 0); bigPlanet.Radius = 300; world.AddWorldObject(bigPlanet); // set up a small planet float desiredDistance = 700; Planet smallPlanet = new Planet(); smallPlanet.IsFlexible = true; smallPlanet.Position = new Vector2(desiredDistance, 0); // calculate velocity needed to circuit in orbit float smallPlanetVelocity = (float)Math.Sqrt(bigPlanet.Mass * G / desiredDistance / (N * 1000)); smallPlanet.Velocity = new Vector2(0, smallPlanetVelocity); smallPlanet.Radius = 150; world.AddWorldObject(smallPlanet); target = new SimplePhysicsAlgorithm(mockCollisionHandler.Object, world, mockConfRet.Object); target.Update(new GameTime(new TimeSpan(0, 0, 10, 3, 0), new TimeSpan(0, 0, 0, 5, 10))); // check whether the distance between the planets is still about the same float distance = Vector2.Distance(bigPlanet.Position, smallPlanet.Position); Assert.IsTrue(distance <= desiredDistance + 30); }