public void testTwoTowerswithTwoEnemies()
        {
            Tower t1 = new Tower("basic", 10, 1, 10, 20, new Rectangle(10, 10, 1, 1));
            Tower t2 = new Tower("basic", 10, 10, 10, 20, new Rectangle(20, 20, 1, 1));
            Enemy e1 = new Enemy(20, 1.0, "basic", 1, new Rectangle(11, 11, 1, 1)); // In range of tower and tower 2, closer to tower 1
            Enemy e2 = new Enemy(20, 1.0, "basic", 1, new Rectangle(19, 19, 1, 1)); // In range of tower and tower 2, closer to tower 2

            Map m = new Map("normal", 100, 2);
            m.PlaceTower(t1);
            m.PlaceTower(t2);
            m.SpawnEnemy(e1);
            m.SpawnEnemy(e2);
            m.Update();//adds all the approiate enemies to the towers lists
            //Assert.IsNull(t1.getCurrentTarget());
            t1.updateCounter = 59;
            t2.updateCounter = 59;
            t1.Update();
            Assert.AreEqual(2, t1.Enemies.Count);
            Assert.AreEqual(2, t2.Enemies.Count);
            Assert.AreEqual(1, t1.AttackDamage);
               // e1.Health -= 19;
            t2.Update();

            //Assert.AreEqual(19, e1.Health);
            Assert.AreEqual(e2.Health, 10);
        }
示例#2
0
        public void SlowTowerTest()
        {
            Map map = new Map("normal", 100000, 2);
            Tower t = new Tower("slow", 10, 10, 10, 1, new Rectangle(70, 70, 1, 1));
            Enemy e1 = new Enemy(100, 1, "basic", 100, new Rectangle(65, 65, 1, 1));
            Enemy e2 = new Enemy(100, 1, "basic", 100, new Rectangle(75, 75, 1, 1));
            map.PlaceTower(t);
            map.SpawnEnemy(e1);
            map.SpawnEnemy(e2);
            t.updateCounter = t.UpdateMax - 1;
            //e1.Counter = 1;
            //e2.Counter = 1;

            //map.Update();
            t.Update();
            Assert.AreEqual(new Rectangle(65, 65, 1, 1), e1.Location);

            Assert.AreEqual(new Rectangle(75, 75, 1, 1), e2.Location);

            map.Update();
            Assert.AreEqual(new Rectangle(66, 66, 1, 1), e1.Location);

            Assert.AreEqual(new Rectangle(76, 76, 1, 1), e2.Location);

            Assert.AreEqual(t.Color, Color.Blue);
        }
 public void testTowerUpdatesEnemiesList()
 {
     Tower t1 = new Tower("tower", 10, 1, 10, 10, new Rectangle(0, 0, 10, 10));
     Enemy e1 = new Enemy(20, 1.0, "basic", 1, new Rectangle(150, 150, 155, 155)); //Out of t1's range
     Map m = new Map("normal", 100, 2);
     m.PlaceTower(t1);
     m.SpawnEnemy(e1);
     m.Update();//adds all the approiate enemies to the towers lists
     t1.Update();
     //Assert.AreEqual(e1, t1.getEnemyList.get(0));
     Assert.AreEqual(0, t1.Enemies.Count);
 }
示例#4
0
 public void NormalTowerTest()
 {
     Map map = new Map("normal", 100000, 2);
     Tower t = new Tower("basic", 10, 10, 10, 500, new Rectangle(70, 70, 1, 1));
     Enemy special = new Enemy(20, 1.0f, "basic", 20, new Rectangle(1, 1, 1, 1));
     map.SpawnEnemy(special);
     map.SellTower(t);
     map.PlaceTower(t);
     for (int i = 0; i <= 60; i++)
     {
         map.Update();
         t.Update();
     }
     Assert.AreEqual(special, t.getCurrentTarget());//Special should be the closest to the tower
     Assert.AreEqual(10, t.getCurrentTarget().Health);
     Assert.AreEqual(Color.White, t.Color);
 }
        public void testTowerChangesTarget()
        {
            Tower t1 = new Tower("tower", 10, 1, 10, 100, new Rectangle(0, 0, 1, 11));
            Enemy e1 = new Enemy(20, 1.0, "basic", 1, new Rectangle(30, 30, 1, 1));
            Enemy e2 = new Enemy(20, 1.0, "basic", 1, new Rectangle(110, 110, 1, 1));

            Map m = new Map("normal", 100, 2);
            m.PlaceTower(t1);
            m.SpawnEnemy(e1);
            m.SpawnEnemy(e2);
            m.Update();//adds all the approiate enemies to the towers lists
            t1.Update();
            Assert.AreEqual(e1, t1.getCurrentTarget());

            e2.moveTo(25,25);
            m.Update();
            Assert.AreEqual(e2, t1.getCurrentTarget());
        }
示例#6
0
        public void RedTowerTest()
        {
            Map map = new Map("normal", 100000, 2);
            Tower t = new Tower("dot", 10, 10, 10, 30, new Rectangle(70, 70, 1, 1));
            Enemy e1 = new Enemy(30000, 1, "basic", 100, new Rectangle(65, 65, 1, 1));
            map.PlaceTower(t);
            map.SpawnEnemy(e1);
            t.updateCounter = t.UpdateMax - 1;
            map.Update();
            t.Update();
            Assert.True(e1.BurnStop > e1.Counter);
            Assert.AreEqual(30000f, e1.Health);
            map.Update();
            e1.Update();
            Assert.AreEqual(29999f, e1.Health);
            for (int i = 0; i < 200; i++)
                e1.Update();

            Assert.False(e1.BurnStop > e1.Counter);

            Assert.AreEqual(t.Color, Color.Red);
        }
        public void SetUp()
        {
            map = new Map("normal", 100000, 1);
            rec = new Rectangle(0, 0, 5, 5);
            tower = new Tower("basic", 10, 20, 30, 40, new Rectangle(1, 0, 1, 1));
            enemy = new Enemy(10, 1.0f, "basic", 20, new Rectangle(rec.X + 5, rec.Y + 5, rec.Width, rec.Height));

            wave = new Wave(new Enemy(10, 1.0f, "basic", 20, new Rectangle(rec.X + 5, rec.Y + 5, rec.Width, rec.Height)), 5);
            map.newWave(wave);
            map.PlaceTower(tower);
        }
 public void SetUp()
 {
     towerRange = 5;
     towerPosition = new Rectangle(0, 1, 1, 1);
     enemyPosition = new Rectangle(1, 1, 1, 1);
     enemy = new Enemy(10, 1.0f, "basic", 10, enemyPosition);
     tower = new Tower("Tower", 1, 1, 1, 100, towerPosition);
     map = new Map("normal", 100, 1);
     map.PlaceTower(tower);
     map.SpawnEnemy(enemy);
 }
示例#9
0
 public void InsufficientFundsRejectTowerPlacement()
 {
     map = new Map("normal", 0, 1);
     map.PlaceTower(tower);
     Assert.AreEqual(map.Towers, new List<Tower>());
 }
示例#10
0
 public void TowersGetRemovedFromListWhenSold()
 {
     Tower tower = new Tower("tower", 10, 20, 30, 40, rec);
     Map map = new Map("normal", 0, 1);
     map.PlaceTower(tower);
     map.SellTower(tower);
     Assert.AreEqual(map.Towers, new List<Tower>());
 }
示例#11
0
        public void UpdateInput()
        {
            mouseState = Mouse.GetState();
            boardState = Keyboard.GetState();

            if (placingTower != null)
            {
                placingTower.Location = new Rectangle(mouseState.X - (mouseState.X % gridSize), mouseState.Y - (mouseState.Y % gridSize), placingTower.Location.Width, placingTower.Location.Height);

                if (mouseState.LeftButton == ButtonState.Pressed && previousMouseState.LeftButton == ButtonState.Released)
                {
                    for (int i = 0; i < map.Towers.Count; i++)
                    {
                    }
                    map.PlaceTower(new Tower(placingTower.Name, placingTower.Health, placingTower.AttackDamage, placingTower.Cost, placingTower.Range, placingTower.Location));

                    placingTower = null;
                }
            }
            else
            {
                if (mouseState.LeftButton == ButtonState.Pressed && previousMouseState.LeftButton == ButtonState.Released)
                {
                    foreach (Tower tower in menu.Towers)
                    {
                        if (tower.Location.Contains(mouseState.X, mouseState.Y))
                        {
                            placingTower = tower.Clone();
                        }
                    }
                }
            }

            if (mouseState.RightButton == ButtonState.Pressed && previousMouseState.RightButton == ButtonState.Released)
            {
                for (int i = 0; i < map.Towers.Count; i++)
                {
                    if (map.Towers[i].Location.Contains(mouseState.X, mouseState.Y))
                    {
                        map.SellTower(map.Towers[i]);
                    }
                }
            }

            #region Selecting towers with Keyboard Input

            if (boardState.IsKeyDown(Keys.D1) && previousKeyboardState.IsKeyUp(Keys.D1))
            {
                Tower temp = menu.Towers[0];
                placingTower = new Tower(temp.Name, temp.Health, temp.AttackDamage, temp.Cost, temp.Range, new Rectangle(mouseState.X - (mouseState.X % gridSize), mouseState.Y - (mouseState.Y % gridSize), 50, 50));
            }

            if (boardState.IsKeyDown(Keys.D2) && previousKeyboardState.IsKeyUp(Keys.D2))
            {
                Tower temp = menu.Towers[1];
                placingTower = new Tower(temp.Name, temp.Health, temp.AttackDamage, temp.Cost, temp.Range, new Rectangle(mouseState.X - (mouseState.X % gridSize), mouseState.Y - (mouseState.Y % gridSize), 50, 50));
            }

            #endregion

            if (boardState.IsKeyUp(Keys.LeftAlt))
            {
                rewindingTime = false;
                map.Rewinding = false;
                map.SaveNextState();
            }
            if (boardState.IsKeyDown(Keys.LeftAlt))
            {
                map.Rewinding = true;
                rewindingTime = true;
                map.LoadPreviousState();
            }


            #region Menu interaction

            if (boardState.IsKeyDown(Keys.Escape) && previousKeyboardState.IsKeyUp(Keys.Escape))
            {
                main.Visible = !main.Visible;
            }

            if (mouseState.LeftButton == ButtonState.Pressed && previousMouseState.LeftButton == ButtonState.Released)
            {
                foreach (Menu item in menus)
                {
                    if (item.Visible)
                    {
                        item.RegisterClick(new Point(mouseState.X, mouseState.Y));
                    }
                }
            }


            #endregion



            previousMouseState    = mouseState;
            previousKeyboardState = boardState;
        }
示例#12
0
文件: MainGame.cs 项目: mellinja/TD2
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            this.IsMouseVisible = true;
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            font = Content.Load<SpriteFont>("font");
            toolTipFont = Content.Load<SpriteFont>("tooltipfont");
            bigFont = Content.Load<SpriteFont>("bigFont");
            gridSize = 50;
            gameTimer = 0;
            placingTower = null;
            map = new Map("normal", 100, 2);

            towerTex = Content.Load<Texture2D>("Sprites\\Eiffel");
            backTex = Content.Load<Texture2D>("Sprites\\Blank");
            Enemy e = new Enemy(100, 10f, "basic", 10, new Rectangle(50, 900, 50, 50));
            e.Map = map;
            map.setStandardEnemy(e.Clone());
            map.Enemies.Add(e);
            Castle c = new Castle(1000000000, new Rectangle(1500, 200, 40, 40));
            map.PlaceCastle(c);
            this.menu = new Interface(this.graphics, this.spriteBatch, this.font);
            this.menu.Background = backTex;
            this.menu.TowerTex = towerTex;
            this.menu.ToolTipFont = toolTipFont;

            menus = new List<Menu>();
            this.main = new Menu("Main Menu", new Point(0, 0), backTex, font, spriteBatch);
            this.main.Interface = menu;
            main.AddSubOption("Resume");
            main.AddSubOption("Exit Game");

            main.Game = this;
            this.options = new Menu("Options", new Point(0, 250), backTex, font, spriteBatch);
            this.options.Interface = menu;
            this.difficulty = new Menu("Difficulty", new Point(0, 500), backTex, font, spriteBatch);
            this.difficulty.Interface = menu;
            this.difficulty.AddSubOption("Raise Difficulty");
            this.difficulty.AddSubOption("Lower Difficulty");
            this.difficulty.AddSubOption("Back");

            difficulty.Map = this.map;

            this.language = new Menu("Languages", new Point(0, 750), backTex, font, spriteBatch);
            this.language.Interface = menu;
            this.language.AddSubOption("Spanish");
            this.language.AddSubOption("English");
            this.language.AddSubOption("Back");

            options.AddSubMenu(difficulty);
            options.AddSubMenu(language);

            this.options.AddSubOption("Back");

            main.AddSubMenu(options);

            menus.Add(main);
            menus.Add(options);
            menus.Add(language);
            menus.Add(difficulty);
            Enemy e2 = e.Clone();
            //Path creation using towers
            for (int i = 0; i <= Math.Abs(e2.Location.Y - c.Location.Y) / 50; i++)
            {
                Tower t = new Tower("path",10,0,0,1,new Rectangle(50, 900 - Math.Sign(e2.Location.Y - c.Location.Y) * i * 50, 50, 50));
                map.PlaceTower(t);
            }
            for (int i = 0; i < Math.Abs(e2.Location.X - c.Location.X) / 50; i++)
            {
                Tower t = new Tower("path", 10, 0, 0, 1, new Rectangle(50 - Math.Sign(e2.Location.X - c.Location.X) * i * 50,c.Location.Y, 50, 50));
                map.PlaceTower(t);
            }

            // TODO: use this.Content to load your game content here
        }