Exemplo n.º 1
0
        public Movment()
        {
            InitializeComponent();
            _timer          = new Timer();
            _timer.Tick    += new EventHandler(_timer_Tick);
            _timer.Interval = 500;
            _player         = new Player();
            mb    = mainShip;
            fs    = folowingShip;
            _game = GameManager.Instance.CreateGame(_player, "TestGame");
            _game.IsNetworkEnabled = false;
            _game.StartGameLoop();
            Group group = new Group();

            GameManager.Instance.GameData.InitAllData();
            Position pos      = new Position(60.25, 10.25);
            BaseUnit unitMain = GameManager.Instance.GameData.CreateUnit(_player, group, "arleighburke", "Arleigh Burke", pos, true);

            unitMain.MovementOrder.AddWaypoint(new Waypoint(new Position(-10.25, 0.25)));

            unitMain.ActualSpeedKph = 700.0;
            unitMain.MoveToNewCoordinate(1.0);

            BaseUnit unitFollow = GameManager.Instance.GameData.CreateUnit(_player, group, "arleighburke", "Hood", pos, true);

            order               = new MovementFormationOrder(unitMain, 326000, -326000, 0);
            waypoint            = order.GetActiveWaypoint();
            unitFollow.Position = waypoint.Position.Clone();

            _timer.Start();
        }
Exemplo n.º 2
0
        public void FormationOrder()
        {
            GameManager.Instance.Log.LogDebug("Running test FormationOrder().");
            Player player = new Player();
            Group  group  = new Group();

            GameManager.Instance.GameData.InitAllData();
            GameManager.Instance.CreateGame(player, "test game");
            Position pos      = new Position(60, 3, 0, 45);
            BaseUnit unitMain = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "", pos, true);

            unitMain.MovementOrder.AddWaypoint(new Waypoint(new Position(61.0, 4.0)));
            unitMain.ActualSpeedKph = 40.0;
            Assert.IsTrue(unitMain.GetActiveWaypoint() != null, "ActiveWaypoint should not be null.");

            unitMain.MoveToNewCoordinate(1.0);

            Assert.IsTrue(unitMain.GetActiveWaypoint() != null, "ActiveWaypoint should not be null after movement.");
            pos = new Position(61, 4, 0, 40);
            BaseUnit unitFollow = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "", pos, true);

            MovementFormationOrder order = new MovementFormationOrder(unitMain, 5000, -1000, 0);
            Waypoint waypoint            = order.GetActiveWaypoint();

            unitFollow.Position = waypoint.Position.Clone();
            double distanceM = MapHelper.CalculateDistanceM(unitMain.Position.Coordinate, unitFollow.Position.Coordinate);

            Assert.IsTrue(distanceM > 5000 && distanceM < 5100, "Distance should be between 5000 and 5100 M.");
            Assert.IsTrue(Math.Abs((double)unitFollow.Position.BearingDeg - 45) < 1, "UnitFollow bearing should be 45 deg");
            GameManager.Instance.Log.LogDebug("*** Offset right:" + order.PositionOffset.RightM + "  Offset forward:" + order.PositionOffset.ForwardM);
            GameManager.Instance.Log.LogDebug("Main unit pos: " + unitMain.Position.ToString());
            GameManager.Instance.Log.LogDebug("Calculated pos: " + waypoint.Position.ToString());
            GameManager.Instance.TerminateGame();
        }
Exemplo n.º 3
0
        public MapVisulizer()
        {
            InitializeComponent();

            _player = new Player();


            CenterMarker.SetValue(Canvas.TopProperty, (backgr.Height - CenterMarker.Height) / 2);
            CenterMarker.SetValue(Canvas.LeftProperty, (backgr.Width - CenterMarker.Width) / 2);

            _game = GameManager.Instance.CreateGame(_player, "TestGame");
            _game.IsNetworkEnabled = false;
            _game.StartGameLoop();
            Group group = new Group();

            GameManager.Instance.GameData.InitAllData();
            Position pos      = new Position(60.25, 5.25);
            BaseUnit unitMain = GameManager.Instance.GameData.CreateUnit(_player, group, "arleighburke", "Arleigh Burke", pos, true);

            unitMain.MovementOrder.AddWaypoint(new Waypoint(new Position(60.5, 5.5)));

            unitMain.ActualSpeedKph = 40.0;
            unitMain.MoveToNewCoordinate(1.0);
            unitMain.Position.BearingDeg = .0;
            //pos = new Position(61.5, 5.5);
            BaseUnit unitFollow  = GameManager.Instance.GameData.CreateUnit(_player, group, "arleighburke", "Hood", pos, true);
            BaseUnit unitFollow2 = GameManager.Instance.GameData.CreateUnit(_player, group, "arleighburke", "Hood", pos, true);

            MovementFormationOrder order  = new MovementFormationOrder(unitMain, 326000, -326000, 0);
            MovementFormationOrder order2 = new MovementFormationOrder(unitMain, -326000, 326000, 0);
            Waypoint waypoint             = order.GetActiveWaypoint();
            Waypoint waypoint2            = order2.GetActiveWaypoint();

            unitFollow.Position  = waypoint.Position.Clone();
            unitFollow2.Position = waypoint2.Position.Clone();
            double distanceM = MapHelper.CalculateDistanceM(unitMain.Position.Coordinate, unitFollow.Position.Coordinate);

            ProjCoordinate min = MapProjection.ToEquiProjectedCoordinate(new Coordinate(61.0, 6.0));
            ProjCoordinate max = MapProjection.ToEquiProjectedCoordinate(new Coordinate(62.0, 5));
            Coordinate     CenterCoordinate = MapHelper.CalculateMidpoint(new Coordinate(62.0, 5.0), new Coordinate(62.0, 6.0));

            RotateTransform rt = new RotateTransform();

            rt.Angle   = (double)unitMain.Position.BearingDeg;
            rt.CenterX = mainShip.Width / 2;
            rt.CenterY = mainShip.Height / 2;

            double testX = MapHelper.LongitudeToXvalue(unitMain.Position.Coordinate.LongitudeDeg, 1);
            double testY = MapHelper.LatitudeToYvalue(unitMain.Position.Coordinate.LatitudeDeg, 1);

            testX = ((512 - 10) / 2) + testX;
            testY = ((512 - 10) / 2) + testY;

            mainShip.SetValue(Canvas.LeftProperty, testX);
            mainShip.SetValue(Canvas.TopProperty, testY);
            mainShip.RenderTransform = rt;

            rt.Angle = (double)waypoint.Position.BearingDeg;
            folowingShip.SetValue(Canvas.LeftProperty, ((512 - 10) / 2) + MapHelper.LongitudeToXvalue(waypoint.Position.Coordinate, 1));
            folowingShip.SetValue(Canvas.TopProperty, ((512 - 10) / 2) + MapHelper.LatitudeToYvalue(waypoint.Position.Coordinate, 1));
            folowingShip.RenderTransform = rt;

            rt.Angle = (double)waypoint2.Position.BearingDeg;
            folowingShip2.SetValue(Canvas.LeftProperty, ((512 - 10) / 2) + MapHelper.LongitudeToXvalue(waypoint2.Position.Coordinate, 1));
            folowingShip2.SetValue(Canvas.TopProperty, ((512 - 10) / 2) + MapHelper.LatitudeToYvalue(waypoint2.Position.Coordinate, 1));
            folowingShip2.RenderTransform = rt;
        }