Inheritance: MonoBehaviour
コード例 #1
0
        public void ShotTest()
        {
            Invader inv = new Invader(2, 3, 20, 9);

            Assert.IsFalse(inv.Shot(10));
            Assert.IsFalse(!inv.Shot(208));
        }
コード例 #2
0
        public void CollisionInvader_Test1()
        {
            LazerGun gun = new LazerGun(5, 15);

            Invader[,] invaders = new Invader[1, 2];

            invaders[0, 1]       = new Invader(5, 5, 15, 9);
            invaders[0, 1].Speed = 40;

            IDistanceStrategy d = new DistanceStrategy();
            Process           p = new Process(d);

            while (invaders[0, 1].CanShot == 0)
            {
                invaders[0, 1].Update(208);
            }
            while (!p.isCollision(invaders[0, 1].EnemyBullet, gun))
            {
                invaders[0, 1].Update(516);
            }

            p.CollisionInvader(invaders, 0, 1, gun);

            Assert.AreEqual(2, gun.NumberOfLives);
        }
コード例 #3
0
    static void Main(string[] args)
    {
        var invader1 = new Invader(110, 5);
        var invader2 = new Invader(20, 1);
        var invader3 = new Invader(10, 2);
        var invader4 = new Invader(30, 3);
        var invader5 = new Invader(0, 3);

        // var computer = new Computer(100);

        //computer.AddInvader(invader1);
        //computer.AddInvader(invader2);
        //computer.AddInvader(invader3);
        //computer.AddInvader(invader4);
        //computer.AddInvader(invader5);

        //computer.Skip(3);
        //computer.Skip(3);

        Computer computer = new Computer(100);

        //var one = 1;
        for (int i = 0; i < 10; i++)
        {
            // System.Console.WriteLine(one++);
            var invader = new Invader(10, 10 + i);
            computer.AddInvader(invader);
        }
        System.Console.WriteLine();
    }
コード例 #4
0
    public void Performance_DestroyInRadius()
    {
        Computer       computer = new Computer(100);
        List <Invader> expected = new List <Invader>();

        for (int i = 1; i <= 20000; i++)
        {
            var invader = new Invader(1, i);
            computer.AddInvader(invader);

            if (i > 10000)
            {
                expected.Add(invader);
            }
        }

        var sw = new Stopwatch();

        sw.Start();

        computer.DestroyTargetsInRadius(10000);

        var exercutionTime = sw.ElapsedMilliseconds;

        Assert.IsTrue(exercutionTime <= 100, "Timeout");

        var actual = computer.Invaders().ToList();

        CollectionAssert.AreEqual(expected, actual, "Collections not equal");

        Assert.AreEqual(100, computer.Energy, "Wrong energy");
    }
コード例 #5
0
        public void MoveTest()
        {
            Invader inv = new Invader(2, 3, 20, 9);

            inv.Move();
            Assert.AreEqual(4, inv.PosY);
        }
コード例 #6
0
    void OnCollisionEnter(Collision collision)
    {
        Collider   collider = collision.collider;
        PlayerBase pb       = playerBase.gameObject.GetComponent <PlayerBase>();

        if (live)
        {
            if (collider.CompareTag("Invader") || collider.CompareTag("MysteryInvader"))
            {
                Invader invader = collider.gameObject.GetComponent <Invader>();
                if (invader.live)
                {
                    invader.Die();
                }
            }
            else if (collider.CompareTag("InvaderMissile"))
            {
                InvaderMissile i_missile = collider.gameObject.GetComponent <InvaderMissile>();
                // The invader missile's collision function will handle its own death
            }
            else if (collider.CompareTag("BaseShield"))
            {
                Destroy(collider.gameObject);
            }
            if (!isBeam)
            {
                live = false;
                gameObject.GetComponent <Renderer>().material.color = new Color(0.2f, 0, 0);
            }
        }
    }
コード例 #7
0
 public static void RemoveInvader(Invader invdr)
 {
     if (I)
     {
         I.invaders.Remove(invdr);
     }
 }
コード例 #8
0
ファイル: PerformanceSkip.cs プロジェクト: player200/SoftUni
    public void Performance_Skip_AllContact()
    {
        Computer       computer = new Computer(20000);
        List <Invader> expected = new List <Invader>();

        for (int i = 1; i <= 19999; i++)
        {
            var invader = new Invader(1, 20000);
            computer.AddInvader(invader);
        }

        var sw = new Stopwatch();

        sw.Start();

        computer.Skip(20000);

        var exercutionTime = sw.ElapsedMilliseconds;

        Assert.IsTrue(exercutionTime <= 150, "Timeout");

        var actual = computer.Invaders().ToList();

        CollectionAssert.AreEqual(expected, actual, "Collections not equal");

        Assert.AreEqual(1, computer.Energy, "Wrong energy");
    }
コード例 #9
0
    public void Performance_DestroyHighestPriority()
    {
        Computer       computer = new Computer(100);
        List <Invader> expected = new List <Invader>();

        for (int i = 1; i <= 20000; i++)
        {
            var invader = new Invader(1, i);
            computer.AddInvader(invader);
            expected.Add(invader);
        }

        expected = expected.OrderBy(x => x.Distance).ThenBy(x => - x.Damage).Skip(10000).ToList();

        var sw = new Stopwatch();

        sw.Start();

        computer.DestroyHighestPriorityTargets(10000);

        var exercutionTime = sw.ElapsedMilliseconds;

        Assert.IsTrue(exercutionTime <= 100, "Timeout");

        var actual = computer.Invaders().ToList();

        CollectionAssert.AreEqual(expected, actual, "Collections not equal");
    }
コード例 #10
0
        public void canShotTrueTest()
        {
            Invader inv = new Invader(2, 3, 20, 9);

            inv.Speed = 1;

            for (var i = 0; i <= 9; i++)
            {
                if (i == 3)
                {
                    inv.K = 4;
                    inv.Update(416);
                    Assert.IsTrue(inv.CanShot != 0);
                }
                else if (i == 5)
                {
                    inv.K = 7;
                    inv.Update(416);
                    Assert.IsTrue(inv.CanShot != 0);
                }
                else if (i == 8)
                {
                    inv.K = 2;
                    inv.Update(416);
                    Assert.IsTrue(inv.CanShot != 0);
                }
                else
                {
                    inv.Update(208);
                }
            }
        }
コード例 #11
0
    public void AddInvader(Invader invader)
    {
        LinkedListNode <Invader> node = new LinkedListNode <Invader>(invader);

        this.invadersByInsertion.AddLast(node);
        this.invadersByPriority.Add(node);
    }
コード例 #12
0
ファイル: Game1.cs プロジェクト: WayneLuong/Portfolio
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            Alien = new Invader();

            base.Initialize();
        }
コード例 #13
0
    public void Skip_MultipleTurns_MultipleInvaders_ShouldDoDamage()
    {
        Computer computer = new Computer(100);

        for (int i = 0; i < 10; i++)
        {
            var invader = new Invader(10, 10 + i);
            computer.AddInvader(invader);
        }

        Assert.AreEqual(100, computer.Energy, "Wrong energy");
        Assert.AreEqual(10, computer.Invaders().Count(), "Wrong count");

        computer.Skip(5);

        Assert.AreEqual(100, computer.Energy, "Wrong energy");
        Assert.AreEqual(10, computer.Invaders().Count(), "Wrong count");

        computer.Skip(5);

        Assert.AreEqual(90, computer.Energy, "Wrong energy");
        Assert.AreEqual(9, computer.Invaders().Count(), "Wrong count");

        computer.Skip(5);

        Assert.AreEqual(40, computer.Energy, "Wrong energy");
        Assert.AreEqual(4, computer.Invaders().Count(), "Wrong count");

        computer.Skip(5);

        Assert.AreEqual(0, computer.Energy, "Wrong energy");
        Assert.AreEqual(0, computer.Invaders().Count(), "Wrong count");
    }
コード例 #14
0
ファイル: PlayView.cs プロジェクト: lemarcque/SpicyInvader
        public void AnimateInvaderKilling(Invader invader)
        {
            const char CHAR_EMPTY = ' ';

            lock (ConsoleWriterLock)
            {
                // Animation of the destruction
                for (int count = 0; count < 6; count++)
                {
                    // pause the thread
                    Thread.Sleep(50);

                    if (count % 2 == 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Black;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                    }

                    // Rewrite the position
                    Console.SetCursorPosition(invader.X, invader.Y);
                    Console.Write(invader.Drawing);
                }

                // Erasing the ennemy displayed on screen)
                Console.SetCursorPosition(invader.X, invader.Y);
                Console.Write(CHAR_EMPTY);
            }
        }
コード例 #15
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Pass often referenced variables to Global
            Global.GraphicsDevice = GraphicsDevice;
            Global.content        = Content;

            // Create and Initialize game objects
            thePlayer = new Player();
            theBullet = new Bullet();

            for (int iInvader = 0; iInvader < nInvaders; iInvader++)
            {
                Invader newInvader = new Invader();
                newInvader.Init();
                invaders.Add(newInvader);
            }


            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch        = new SpriteBatch(GraphicsDevice);
            Global.spriteBatch = spriteBatch;
            background         = Content.Load <Texture2D>("background");
            scanlines          = Content.Load <Texture2D>("scanlines");
            base.Initialize();
        }
        public void IsInRangeOfShouldReturnTrueWhenInvaderIsClose()
        {
            // Given TestTower on (1,1) TestMap location
            SetUpTowerLocationWithRandomDoubleValue(0.0);
            // Given 8 Invaders that are in range of 1
            // 5
            // 4
            // 3
            // 2 i6 i7 i8
            // 1 i4  t i5
            // 0 i1 i2 i3
            //    0  1  2  3  4  5
            Invader i1 = CreateInvaderWithPathOfOneMapLocation(x: 0, y: 0);
            Invader i2 = CreateInvaderWithPathOfOneMapLocation(x: 1, y: 0);
            Invader i3 = CreateInvaderWithPathOfOneMapLocation(x: 2, y: 0);

            Invader i4 = CreateInvaderWithPathOfOneMapLocation(x: 0, y: 1);
            // at (1,1) stays TestTower
            Invader i5 = CreateInvaderWithPathOfOneMapLocation(x: 2, y: 1);

            Invader i6 = CreateInvaderWithPathOfOneMapLocation(x: 0, y: 2);
            Invader i7 = CreateInvaderWithPathOfOneMapLocation(x: 1, y: 2);
            Invader i8 = CreateInvaderWithPathOfOneMapLocation(x: 2, y: 2);

            // When IsInRangeOf() is called with invaders
            // Then true should be returned
            foreach (var invader in new [] { i1, i2, i3, i4, i5, i6, i7, i8 })
            {
                Assert.IsTrue(
                    TestTower.IsInRangeOf(invader)
                    );
            }
        }
コード例 #17
0
    public void DestroyHighestPriority_MultipleTargets()
    {
        Random random = new Random();
        Computer computer = new Computer(100);
        List<Invader> expected = new List<Invader>();

        for (int i = 1; i <= 100; i++)
        {
            var invader = new Invader(random.Next(50), random.Next(50));
            computer.AddInvader(invader);
            expected.Add(invader);
        }

        computer.DestroyHighestPriorityTargets(50);
        
        var toRemove = expected
            .OrderBy(x => x.Distance)
            .ThenBy(x => -x.Damage)
            .Take(50)
            .ToList();

        expected.RemoveAll(x => toRemove.Contains(x));

        CollectionAssert.AreEqual(expected, computer.Invaders().ToList(), "Collections not equal");
    }
コード例 #18
0
    public void Performance_DestroyHighestPriority_Random()
    {
        Random         rnd      = new Random();
        Computer       computer = new Computer(100);
        List <Invader> expected = new List <Invader>();

        for (int i = 1; i <= 10000; i++)
        {
            var distance = rnd.Next(1000);
            var damage   = rnd.Next(1000);
            var invader  = new Invader(damage, distance);
            computer.AddInvader(invader);
            expected.Add(invader);
        }

        var sw = new Stopwatch();

        sw.Start();

        computer.DestroyHighestPriorityTargets(5000);

        var exercutionTime = sw.ElapsedMilliseconds;

        Assert.IsTrue(exercutionTime <= 100, "Timeout");

        var toRemove = expected.OrderBy(x => x.Distance).ThenBy(x => - x.Damage).Take(5000).ToList();

        expected.RemoveAll(x => toRemove.Contains(x));

        var actual = computer.Invaders().ToList();

        CollectionAssert.AreEqual(expected, actual, "Collections not equal");
    }
コード例 #19
0
 public static void RegisterNewInvader(Invader invdr)
 {
     if (I && !I.invaders.Contains(invdr))
     {
         I.invaders.Add(invdr);
     }
 }
コード例 #20
0
 private void ModelShipChangedEventHandler(object sender, ShipChangedEventArgs e)
 {
     if (!e.Killed)
     {
         if (e.ShipUpdated is Invader)
         {
             Invader invader = e.ShipUpdated as Invader;
             if (!_invaders.ContainsKey(invader))
             {
                 FrameworkElement invaderControl = InvadersHelper.InvaderControlFactory(invader, Scale);
                 _invaders[invader] = invaderControl;
                 _sprites.Add(invaderControl);
             }
             else
             {
                 FrameworkElement invaderControl = _invaders[invader];
                 InvadersHelper.MoveElement(invaderControl, invader.Location.X, Scale, invader.Location.Y * Scale);
                 InvadersHelper.ResizeElement(invaderControl, invader.Size.Width * Scale, invader.Size.Height * Scale);
             }
         }
         else if (e.ShipUpdated is Player)
         {
             if (_playerFlashing)
             {
                 AnimatedImage playerImage = _playControl as AnimatedImage;
                 _playerFlashing = false;
             }
             if (_playControl == null)
             {
                 FrameworkElement playerControl = InvadersHelper.PlayerControlFactory(player, Scale);
                 _sprites.Add(playerControl);
             }
         }
     }
 }
        public void NeutralizedInvadersShouldBeRemovedAfterShot()
        {
            // Given level with one neutralized invader
            Invader neutralizedInvader = new Invader(
                path: new Path(
                    new []
            {
                new MapLocation(x: 1, y: 1, map: TestMap),
            }
                    ),
                pathStep: 1,
                health: 0
                );

            Assert.IsTrue(
                neutralizedInvader.IsNeutralized,
                "neutralizedInvader should be neutralized"
                );
            Level level = new Level(
                new List <Invader> {
                neutralizedInvader
            }
                );

            // When we remove neutralized invaders
            level.RemoveNeutralizedInvaders();

            CollectionAssert.DoesNotContain(
                level.Invaders,
                neutralizedInvader,
                "Then neutralizedInvader should be removed from" +
                "Invaders property"
                );
        }
        public void InvadersThatScoredShouldSetWinnerToInvader()
        {
            // Given one invader that scored
            // in level
            Invader scoredInvader = new Invader(
                path: new Path(
                    new []
            {
                new MapLocation(x: 1, y: 1, map: TestMap),
            }
                    ),
                pathStep: 1,
                health: Invader.DefaultHealth
                );

            Assert.IsTrue(
                scoredInvader.HasScored
                );
            Level level = new Level(
                new List <Invader> {
                scoredInvader
            }
                );

            // When CheckForWinnersAmongInvaders() is called
            level.CheckForWinnersAmongInvaders();

            Assert.AreEqual(
                WinnerType.Invader,
                level.Winner,
                "Then level winner should be invader"
                );
        }
        public void LevelShouldBeWonByInvaderInOneTowerOneInvaderGameWhereInvaderIsOutOfTowerRange()
        {
            // Given the tower and
            // invader that is out range of tower,
            // on TestMap :
            // 5
            // 4
            // 3 i i i i i i
            // 2
            // 1   t
            // 0
            //   0 1 2 3 4 5
            Tower tower = new Tower(
                location: new MapLocation(x: 1, y: 1, map: TestMap),
                range: 1,
                power: 1,
                accuracy: 1.0,
                random: new Random()
                );
            Invader invader = new Invader(
                new Path(
                    new MapLocation[]
            {
                new MapLocation(x: 0, y: 3, map: TestMap),
                new MapLocation(x: 1, y: 3, map: TestMap),
                new MapLocation(x: 2, y: 3, map: TestMap),
                new MapLocation(x: 3, y: 3, map: TestMap),
                new MapLocation(x: 4, y: 3, map: TestMap),
                new MapLocation(x: 5, y: 3, map: TestMap),
            }
                    )
                );
            Level level = new Level(
                new List <Invader> {
                invader
            }
                )
            {
                Towers = new List <Tower> {
                    tower
                }
            };

            Assert.AreEqual(
                WinnerType.Undefined,
                level.Winner,
                "Before play call level.Winner should be Undefined"
                );


            // When Level.Play() is called
            level.Play();

            Assert.AreEqual(
                WinnerType.Invader,
                level.Winner,
                "Level.Winner should be WinnerType.Invader"
                );
        }
コード例 #24
0
        public void UpdateTest()
        {
            Invader inv = new Invader(2, 3, 20, 9);

            inv.Speed = 1;
            inv.Update(10000);
            Assert.IsTrue(inv.CanShot == 0);
        }
コード例 #25
0
ファイル: Tower.cs プロジェクト: kirakirakira/csharp
 public void FireOnInvaders(Invader[] invaders)
 {
     for (int i = 0; i < invaders.Length; i++)
     {
         Invader invader = invaders[i];
         // Do stuff with invader
     }
 }
コード例 #26
0
        public void InvaderWineTest()
        {
            Invader  inv = new Invader(5, 5, 2, 5);
            LazerGun l   = new LazerGun(5, 5);
            bool     t   = Collision.InvaderWin(inv, l);

            Assert.IsTrue(t);
        }
コード例 #27
0
 public void AddInvader(Invader invader)
 {
     byInsertion.Add(invader);
     if (!byDistance.ContainsKey(invader.Distance))
     {
         byDistance[invader.Distance] = new List <Invader>();
     }
     byDistance[invader.Distance].Add(invader);
 }
コード例 #28
0
        // SOLVED problem: was not passing the INVADER object Size properties to
        // this method; it takes them from the AnimatedImage control directly!
        internal static FrameworkElement InvaderControlFactory(Invader invader, List <string> imageNames, double scale)
        {
            AnimatedImage invaderControl = new AnimatedImage(imageNames, TimeSpan.FromMilliseconds(200));

            invaderControl.Width  = invader.Size.Width * scale;
            invaderControl.Height = invader.Size.Width * scale;
            SetCanvasLocation(invaderControl, invader.Location.X * scale, invader.Location.Y * scale);
            return(invaderControl);
        }
コード例 #29
0
    public void AddInvader(Invader invader)
    {
        if (invader == null)
        {
            return;
        }

        this.invaders.Add(invader);
    }
コード例 #30
0
    public void OnTriggerEnter2D(Collider2D other)
    {
        Invader invader = other.GetComponent <Invader>();

        if (other.tag == "Invader" && invader != null)
        {
            invader.nextWaypoint = nextwaypoint;
        }
    }
コード例 #31
0
        private void Invader_Outside(object sender, EventArgs e)
        {
            Invader invader = (Invader)sender;

            if (invader.Location.X <= 0)
            {
                invader.Location = new Point(form1.Width, invader.Location.Y + 50);
            }
        }
コード例 #32
0
        private IEnumerable<Invader> CreateNewAttackWave()
        {
            IList<Invader> attackers = new List<Invader>();

            var currentX = Invader.Height*1.4;
            var currentY = Invader.Width*1.4;
            for (var i = 0; i < 16; i++)
            {
                var invader = new Invader(new Point(currentX, currentY), GetInvaderType(), new BitmapImage());
                ShipChangedEventHandler += invader.OnShipChanged;
                attackers.Add(invader);
                currentX += Invader.Width*2.4;
                if (IsOutOfBounds(new Point(currentX*2.4, currentY)))
                {
                    currentX = Invader.Height*1.4;
                    currentY += Invader.Height + Invader.Height*1.4;
                }
            }

            return attackers;
        }
コード例 #33
0
ファイル: SpaceInvaders.cs プロジェクト: WayneLuong/Portfolio
        //Initialise Ingame Variables
        public void InitialiseGameVariables()
        {
            RocketXPos = 650;         //Set Rocket X value
            AlienDirection = -1;      //Set default direction
            AlienSpeed = 25;          //Sets a default speed (These can be changed in-game to increase difficulty)

            BossAlienDirection = -1;
            BossAlienSpeed = 100;

            //Declaring the Alien arrays:
            Invaders = new Invader[11];     //11 columns across
            InvadersOne = new Invader[11];
            InvadersTwo = new Invader[11];
            InvadersThree = new Invader[11];
            InvadersFour = new Invader[11];

            int XPos = 512;                 // Sets the default X coordinate for Aliens
            for (int Count = 0; Count < 11; Count++)    //Checks the count for amount of aliens
            {
                //First Array
                Invaders[Count] = new Invader();
                Invaders[Count].SetXPos(XPos);
                Invaders[Count].SetYPos(100);   //Each line of alien has a different Y coordinate
                //Second Array
                InvadersOne[Count] = new Invader();
                InvadersOne[Count].SetXPos(XPos);
                InvadersOne[Count].SetYPos(135);
                //Third Array
                InvadersTwo[Count] = new Invader();
                InvadersTwo[Count].SetXPos(XPos);
                InvadersTwo[Count].SetYPos(155);
                //Fourth Array
                InvadersThree[Count] = new Invader();
                InvadersThree[Count].SetXPos(XPos);
                InvadersThree[Count].SetYPos(180);
                //Fifth Array
                InvadersFour[Count] = new Invader();
                InvadersFour[Count].SetXPos(XPos);
                InvadersFour[Count].SetYPos(205);

                XPos = XPos + 32;
            }

            int BossXPos = 512;     //Sets defualt X position for Boss Alien
            BossAlien= new BossAlien();
            BossAlien.SetXPos(BossXPos);
            BossAlien.SetYPos(0);

            Ticks = 0; //Shows the amount of time passed
            Timer = 0; //Timer for each variable e.g. Alien & Boss
            Timer2 = 0;
            Timer3 = 0;
            Timer4 = 0;
            MissileFired = null;    //Missile values are set to null at start
            AlienMissileFired = null;
            AlienMissileFired2 = null;
            BossMissileFired = null;
            PlayerScore = 0;    //Player score set to 0 at start
            AmountofLives = 3; //Amount of lives the player at start of game
            BossLife = 3;     //Amount of lives Boss has at start of game
            WeaponsCount = 1; //Checks what weapon the player is using & allows switching between them
        }