Пример #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     PlayerVehicle veh1 = new PlayerVehicle(gameArea);
     gameArea.AddGameObject(veh1);
 }
Пример #2
0
        public Form1()
        {
            InitializeComponent();
            this.DoubleBuffered = true;

            DrawParams dp = new DrawParams();
            dp.Graphics = this.CreateGraphics();
            dp.Graphics.Clear(Color.White);
            dp.Trans = new Trans { XScale = 1, YScale = 1, Origin = new Point(510, 315) };
            dp.Pen = new Pen(Color.Blue);
            dp.FillBrush = new SolidBrush(Color.GreenYellow);

            gameArea = new GameController();
            gameArea.DrawParam = dp;

            GameServer.GameController = gameArea;
            new Thread(GameServer.Server).Start();

            time = new System.Windows.Forms.Timer();
            time.Enabled = true;
            time.Interval = 30;
            time.Tick += UpdateGameArea;

            PlayerVehicle veh1 = new PlayerVehicle(gameArea);
            veh1.Centre = new MatrixPoint(350, -200);

            FuelCell fuelCell1 = new FuelCell(gameArea);
            fuelCell1.Centre = new MatrixPoint(-20, 40);

            FuelCell fuelCell2 = new FuelCell(gameArea);
            fuelCell2.Centre = new MatrixPoint(20, 40);

            FuelCell fuelCell3 = new FuelCell(gameArea);
            fuelCell3.Centre = new MatrixPoint(20, -40);

            FuelCell fuelCell4 = new FuelCell(gameArea);
            fuelCell4.Centre = new MatrixPoint(-20, -40);

            FuelCell fuelCell5 = new FuelCell(gameArea);
            fuelCell5.Centre = new MatrixPoint(-40, 20);

            FuelCell fuelCell6 = new FuelCell(gameArea);
            fuelCell6.Centre = new MatrixPoint(40, 20);

            FuelCell fuelCell7 = new FuelCell(gameArea);
            fuelCell7.Centre = new MatrixPoint(40, -20);

            FuelCell fuelCell8 = new FuelCell(gameArea);
            fuelCell8.Centre = new MatrixPoint(-40, -20);

            WayPoint p1 = new WayPoint(gameArea);
            p1.Centre = new MatrixPoint(-150, 150);

            WayPoint p2 = new WayPoint(gameArea);
            p2.Centre = new MatrixPoint(250, -150);

            WayPoint p3 = new WayPoint(gameArea);
            p3.Centre = new MatrixPoint(-250, -250);

            WayPoint p4 = new WayPoint(gameArea);
            p4.Centre = new MatrixPoint(35, 85);

            WayPoint p5 = new WayPoint(gameArea);
            p5.Centre = new MatrixPoint(100, 150);

            WayPoint p6 = new WayPoint(gameArea);
            p6.Centre = new MatrixPoint(10, 150);

            IMission miss1 = new Mission();
            miss1.Targets.Add(new MissionTarget(p1, MissionObjective.Visit));
            miss1.Targets.Add(new MissionTarget(veh1, MissionObjective.Attack));
            miss1.Targets.Add(new MissionTarget(fuelCell1, MissionObjective.Collect));
            miss1.Targets.Add(new MissionTarget(p2, MissionObjective.Visit));
            miss1.Targets.Add(new MissionTarget(p4, MissionObjective.Visit));

            IMission miss2 = new Mission();
            miss2.Targets.Add(new MissionTarget(p2, MissionObjective.Visit));
            miss2.Targets.Add(new MissionTarget(fuelCell2, MissionObjective.Collect));
            miss2.Targets.Add(new MissionTarget(p3, MissionObjective.Visit));
            miss2.Targets.Add(new MissionTarget(p4, MissionObjective.Visit));

            IMission miss3 = new Mission();
            miss3.Targets.Add(new MissionTarget(p3, MissionObjective.Visit));
            miss3.Targets.Add(new MissionTarget(veh1, MissionObjective.Attack));
            miss3.Targets.Add(new MissionTarget(fuelCell3, MissionObjective.Collect));
            miss3.Targets.Add(new MissionTarget(p4, MissionObjective.Visit));
            miss3.Targets.Add(new MissionTarget(p5, MissionObjective.Visit));

            IMission miss4 = new Mission();
            miss4.Targets.Add(new MissionTarget(p4, MissionObjective.Visit));
            miss4.Targets.Add(new MissionTarget(veh1, MissionObjective.Attack));
            miss4.Targets.Add(new MissionTarget(fuelCell4, MissionObjective.Collect));
            miss4.Targets.Add(new MissionTarget(p5, MissionObjective.Visit));
            miss4.Targets.Add(new MissionTarget(p6, MissionObjective.Visit));

            IMission miss5 = new Mission();
            miss5.Targets.Add(new MissionTarget(p4, MissionObjective.Visit));
            miss5.Targets.Add(new MissionTarget(veh1, MissionObjective.Attack));
            miss5.Targets.Add(new MissionTarget(fuelCell5, MissionObjective.Collect));
            miss5.Targets.Add(new MissionTarget(p3, MissionObjective.Visit));
            miss5.Targets.Add(new MissionTarget(p2, MissionObjective.Visit));

            IMission miss6 = new Mission();
            miss6.Targets.Add(new MissionTarget(p6, MissionObjective.Visit));
            miss6.Targets.Add(new MissionTarget(veh1, MissionObjective.Attack));
            miss6.Targets.Add(new MissionTarget(fuelCell6, MissionObjective.Collect));
            miss6.Targets.Add(new MissionTarget(p2, MissionObjective.Visit));
            miss6.Targets.Add(new MissionTarget(p1, MissionObjective.Visit));

            IMission miss7 = new Mission();
            miss7.Targets.Add(new MissionTarget(p5, MissionObjective.Visit));
            miss7.Targets.Add(new MissionTarget(fuelCell7, MissionObjective.Collect));
            miss7.Targets.Add(new MissionTarget(p3, MissionObjective.Visit));
            miss7.Targets.Add(new MissionTarget(p4, MissionObjective.Visit));

            IMission miss8 = new Mission();
            miss8.Targets.Add(new MissionTarget(p3, MissionObjective.Visit));
            miss8.Targets.Add(new MissionTarget(veh1, MissionObjective.Attack));
            miss8.Targets.Add(new MissionTarget(fuelCell8, MissionObjective.Collect));
            miss8.Targets.Add(new MissionTarget(p6, MissionObjective.Visit));
            miss8.Targets.Add(new MissionTarget(p1, MissionObjective.Visit));

            gameArea.CollectMission(miss1);
            gameArea.CollectMission(miss2);
            gameArea.CollectMission(miss3);
            gameArea.CollectMission(miss4);
            gameArea.CollectMission(miss5);
            gameArea.CollectMission(miss6);
            gameArea.CollectMission(miss7);
            gameArea.CollectMission(miss8);

            new EnemyTank(gameArea).Centre = new MatrixPoint(-300, 900);
            new EnemyTank(gameArea).Centre = new MatrixPoint(400, 400);
            new EnemyTank(gameArea).Centre = new MatrixPoint(700, 80);
            new EnemyTank(gameArea).Centre = new MatrixPoint(-900, 900);
            new EnemyTank(gameArea).Centre = new MatrixPoint(1500, 1700);
            new EnemyTank(gameArea).Centre = new MatrixPoint(-2500, 3000);
            new EnemyTank(gameArea).Centre = new MatrixPoint(300, 600);
            new EnemyTank(gameArea).Centre = new MatrixPoint(2000, 200);
        }
Пример #3
0
        public void TestMovingEntities()
        {
            GameController ga = new GameController();

            MovingEntity mover = new MovingEntity(ga);

            mover.Rotate(-Math.PI / 4);
            mover.Move(10);
            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(mover.Centre.Xd, 7), "Test move x");
            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(mover.Centre.Yd, 7), "Test move y");

            Missile m = new Missile(ga, mover.Orientation, new MatrixPoint(0, 0), 1000);
            m.Move(5);

            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(m.Centre.Xd, 7), "Missile move x");
            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(m.Centre.Yd, 7), "Missile move y");

            Line trace = m.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(0.0, 7), Math.Round(trace.Point1.Xd, 7), "Trace move x");
            Assert.AreEqual(Math.Round(0.0, 7), Math.Round(trace.Point1.Yd, 7), "Trace move y");
            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(trace.Point2.Xd, 7), "Trace move x");
            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(trace.Point2.Yd, 7), "Trace move y");

            m.Move(10);
            trace = m.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(trace.Point1.Xd, 7), "Trace move x");
            Assert.AreEqual(Math.Round(Math.Sqrt(50), 7), Math.Round(trace.Point1.Yd, 7), "Trace move y");
            Assert.AreEqual(Math.Round(2 * Math.Sqrt(50), 7), Math.Round(trace.Point2.Xd, 7), "Trace move x");
            Assert.AreEqual(Math.Round(2 * Math.Sqrt(50), 7), Math.Round(trace.Point2.Yd, 7), "Trace move y");

            m.Move(10);
            trace = m.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(2 * Math.Sqrt(50), 7), Math.Round(trace.Point1.Xd, 7), "Trace move x");
            Assert.AreEqual(Math.Round(2 * Math.Sqrt(50), 7), Math.Round(trace.Point1.Yd, 7), "Trace move y");
            Assert.AreEqual(Math.Round(3 * Math.Sqrt(50), 7), Math.Round(trace.Point2.Xd, 7), "Trace move x");
            Assert.AreEqual(Math.Round(3 * Math.Sqrt(50), 7), Math.Round(trace.Point2.Yd, 7), "Trace move y");

            PlayerVehicle veh1 = new PlayerVehicle(ga);
            Missile miss = new Missile(ga, new Angle(-3.0499999999999972), new MatrixPoint(-7.2369182872595275, 99.435069414788984), 1000);

            trace = miss.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(-7.2369182872595275, 7), Math.Round(trace.Point1.Xd, 7), "Trace2 move x");
            Assert.AreEqual(Math.Round(99.435069414788984, 7), Math.Round(trace.Point1.Yd, 7), "Trace2 move y");
            Assert.AreEqual(Math.Round(-7.2369182872595275, 7), Math.Round(trace.Point2.Xd, 7), "Trace2 move x");
            Assert.AreEqual(Math.Round(99.435069414788984, 7), Math.Round(trace.Point2.Yd, 7), "Trace2 move y");
            Assert.False(miss.DetectProximity(veh1).Collision, "Collison check 1");

            miss.Move(10);
            trace = miss.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(-7.2369182872595275, 7), Math.Round(trace.Point1.Xd, 7), "Trace2 move x");
            Assert.AreEqual(Math.Round(99.435069414788984, 7), Math.Round(trace.Point1.Yd, 7), "Trace2 move y");
            Assert.AreEqual(Math.Round(-6.3222718999999996, 7), Math.Round(trace.Point2.Xd, 7), "Trace2 move x");
            Assert.AreEqual(Math.Round(89.476986199999999, 7), Math.Round(trace.Point2.Yd, 7), "Trace2 move y");
            Assert.False(miss.DetectProximity(veh1).Collision, "Collison check 2");

            miss.Move(10);
            trace = miss.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(-6.3222718999999996, 7), Math.Round(trace.Point1.Xd, 7), "Trace2 move x1");
            Assert.AreEqual(Math.Round(89.476986199999999, 7), Math.Round(trace.Point1.Yd, 7), "Trace2 move y1");
            Assert.AreEqual(Math.Round(-5.4076253999999997, 7), Math.Round(trace.Point2.Xd, 7), "Trace2 move x2");
            Assert.AreEqual(Math.Round(79.5189029, 7), Math.Round(trace.Point2.Yd, 7), "Trace2 move y2");
            Assert.False(miss.DetectProximity(veh1).Collision, "Collison check 3");

            miss.Move(10);
            trace = miss.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(-5.4076253999999997, 7), Math.Round(trace.Point1.Xd, 7), "Trace2 move x1");
            Assert.AreEqual(Math.Round(79.5189029, 7), Math.Round(trace.Point1.Yd, 7), "Trace2 move y1");
            Assert.AreEqual(Math.Round(-4.4929790000000001, 7), Math.Round(trace.Point2.Xd, 7), "Trace2 move x2");
            Assert.AreEqual(Math.Round(69.560819699999996, 7), Math.Round(trace.Point2.Yd, 7), "Trace2 move y2");
            Assert.False(miss.DetectProximity(veh1).Collision, "Collison check 4");

            miss.Move(10);
            miss.Move(10);
            miss.Move(10);
            miss.Move(10);
            miss.Move(10);

            miss.Move(10);
            trace = miss.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(0.080253099999999994, 7), Math.Round(trace.Point1.Xd, 7), "Trace2 move x1");
            Assert.AreEqual(Math.Round(19.7704035, 7), Math.Round(trace.Point1.Yd, 7), "Trace2 move y1");
            Assert.AreEqual(Math.Round(0.99489950000000005, 7), Math.Round(trace.Point2.Xd, 7), "Trace2 move x2");
            Assert.AreEqual(Math.Round(9.8123202000000003, 7), Math.Round(trace.Point2.Yd, 7), "Trace2 move y2");
            Assert.True(miss.DetectProximity(veh1).Collision, "Collison check 5");

            miss.Move(10);
            trace = miss.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(0.99489950000000005, 7), Math.Round(trace.Point1.Xd, 7), "Trace2 move x1");
            Assert.AreEqual(Math.Round(9.8123202000000003, 7), Math.Round(trace.Point1.Yd, 7), "Trace2 move y1");
            Assert.AreEqual(Math.Round(1.9095458999999999, 7), Math.Round(trace.Point2.Xd, 7), "Trace2 move x2");
            Assert.AreEqual(Math.Round(-0.145763, 7), Math.Round(trace.Point2.Yd, 7), "Trace2 move y2");
            Assert.False(miss.DetectProximity(veh1).Collision, "Collison check 6");

            miss.Move(10);
            trace = miss.GetPerimeter()[0];
            Assert.AreEqual(Math.Round(1.9095458999999999, 7), Math.Round(trace.Point1.Xd, 7), "Trace2 move x1");
            Assert.AreEqual(Math.Round(-0.145763, 7), Math.Round(trace.Point1.Yd, 7), "Trace2 move y1");
            Assert.AreEqual(Math.Round(2.8241923999999998, 7), Math.Round(trace.Point2.Xd, 7), "Trace2 move x2");
            Assert.AreEqual(Math.Round(-10.103846300000001, 7), Math.Round(trace.Point2.Yd, 7), "Trace2 move y2");
            Assert.True(miss.DetectProximity(veh1).Collision, "Collison check 7");
        }