public void testGiveCommand()
        {
            Scenario scenario = new Scenario(20, 20);
            Controller controller = new Controller(scenario);

            Unit unit = new Unit(scenario.getPlayer(), 200);
            controller.addUnit(unit, 10f, 10f);

            // Create a MoveAction
            MoveAction action = new MoveAction(8f, 8f, scenario.getGameWorld(), unit);

            // Test if the ActionController returns true when it gives the command.
            Assert.IsTrue(controller.giveActionCommand(unit, action));

            // Test if the MoveAction is actually on the unit's action queue.
            Assert.IsTrue(unit.getActionQueue()[0] == action);

            // Create a second MoveAction
            MoveAction action2 = new MoveAction(7f, 7f, scenario.getGameWorld(), unit);

            // Test if the ActionController interrupts the current MoveAction and replaces it with the new one.
            Assert.IsTrue(controller.giveActionCommand(unit, action2));
            Assert.IsTrue(unit.getActionQueue()[0] == action2);
            Assert.IsFalse(unit.getActionQueue().Contains(action));
        }
        public void testInsertCommand()
        {
            Scenario scenario = new Scenario(20, 20);
            Controller controller = new Controller(scenario);

            Unit unit = new Unit(scenario.getPlayer(), 200);
            controller.addUnit(unit, 10f, 10f);

            // Create a MoveAction
            MoveAction action = new MoveAction(8f, 8f, scenario.getGameWorld(), unit);

            // Test if the ActionController returns true when it gives the command.
            Assert.IsTrue(controller.giveActionCommand(unit, action));

            // Test if the MoveAction is actually on the unit's action queue.
            Assert.IsTrue(unit.getActionQueue()[0] == action);

            // Create a second MoveAction
            MoveAction action2 = new MoveAction(7f, 7f, scenario.getGameWorld(), unit);

            // Insert the second MoveAction to the beginning of the units action queue.
            ActionController.insertIntoActionQueue(unit, action2);
            Assert.IsTrue(unit.getActionQueue()[0] == action2);
            Assert.IsTrue(unit.getActionQueue()[1] == action);
        }
        public void testMapWithUnitMove()
        {
            Scenario scenario = new Scenario(20, 20);
            Controller controller = new Controller(scenario);
            Unit unit = new Unit(scenario.getPlayer(), new UnitStats());
            controller.addUnit(unit, 6, 6);

            MoveAction move = new MoveAction(10, 10, scenario.getGameWorld(), unit);

            controller.giveActionCommand(unit, move);

            // Update the world so that the unit moves.
            for (int i = 0; i < 1000; i++)
            {
                controller.updateWorld();
            }

            // Test that all of the cells within the units visibility range have been explored.
            for (int i = (int)unit.x - (int)unit.stats.visibilityRange; i < (int)unit.x + (int)unit.stats.visibilityRange; i++)
            {
                for (int j = (int)unit.y - (int)unit.stats.visibilityRange; j < (int)unit.y + (int)unit.stats.visibilityRange; j++)
                {
                    Assert.IsTrue(scenario.getGameWorld().map.getCell(i, j).explored);
                }
            }
        }
        private void initialize()
        {
            // Initialize game world
            testScenario = new ZRTSModel.Scenario.Scenario(20, 20);


            for (int row = 0; row < this.testScenario.getGameWorld().map.height; ++row)
            {
                for (int col = 0; col < this.testScenario.getGameWorld().map.width; ++col)
                {
                    this.testScenario.getGameWorld().map.getCell(col, row).isValid = true;
                }
            }

            this.testScenario.getGameWorld().map.getCell(9, 9).isValid   = false;
            this.testScenario.getGameWorld().map.getCell(9, 10).isValid  = false;
            this.testScenario.getGameWorld().map.getCell(9, 11).isValid  = false;
            this.testScenario.getGameWorld().map.getCell(10, 9).isValid  = false;
            this.testScenario.getGameWorld().map.getCell(10, 10).isValid = false;
            this.testScenario.getGameWorld().map.getCell(10, 11).isValid = false;
            this.testScenario.getGameWorld().map.getCell(11, 9).isValid  = false;
            this.testScenario.getGameWorld().map.getCell(11, 10).isValid = false;


            this.testScenario.getGameWorld().map.getCell(14, 4).isValid = false;
            this.testScenario.getGameWorld().map.getCell(14, 5).isValid = false;
            this.testScenario.getGameWorld().map.getCell(14, 6).isValid = false;
            this.testScenario.getGameWorld().map.getCell(15, 4).isValid = false;
            this.testScenario.getGameWorld().map.getCell(15, 5).isValid = false;
            this.testScenario.getGameWorld().map.getCell(15, 6).isValid = false;
            this.testScenario.getGameWorld().map.getCell(16, 4).isValid = false;
            this.testScenario.getGameWorld().map.getCell(16, 5).isValid = false;

            this.testScenario.getGameWorld().map.getCell(4, 4).isValid = false;
            this.testScenario.getGameWorld().map.getCell(4, 5).isValid = false;
            this.testScenario.getGameWorld().map.getCell(4, 6).isValid = false;
            this.testScenario.getGameWorld().map.getCell(5, 4).isValid = false;
            this.testScenario.getGameWorld().map.getCell(5, 5).isValid = false;
            this.testScenario.getGameWorld().map.getCell(5, 6).isValid = false;
            this.testScenario.getGameWorld().map.getCell(6, 4).isValid = false;
            this.testScenario.getGameWorld().map.getCell(6, 5).isValid = false;

            ///Set controller
            testGameController = new ZRTSLogic.Controller(testScenario);

            ///Add a unit at (17, 17)
            this.testGameController.addUnit(new ZRTSModel.Entities.Unit(testGameController.scenario.getWorldPlayer(), 20), 17, 17);

            ///Initialize Player's resources
            this.testScenario.getPlayer().player_resources[0] = 300;
            this.testScenario.getPlayer().player_resources[1] = 300;
            this.testScenario.getPlayer().player_resources[2] = 300;
            this.testScenario.getPlayer().player_resources[3] = 300;
        }
        public void testEmptyMap()
        {
            Scenario scenario = new Scenario(20, 20);
            Controller controller = new Controller(scenario);

            // Test that all of the cells in a map with no player units in it are unexplored.
            for (int i = 0; i < 20; i++)
            {
                for (int j = 0; j < 20; j++)
                {
                    Assert.IsFalse(scenario.getGameWorld().map.getCell(i, j).explored);
                }
            }
        }
        public void testMapWithUnit()
        {
            Scenario scenario = new Scenario(20, 20);
            Controller controller = new Controller(scenario);
            Unit unit = new Unit(scenario.getPlayer(), new UnitStats());
            controller.addUnit(unit, 0, 0);

            // Test that all of the cells within the units visibility range have been explored.
            for (int i = 0; i < unit.stats.visibilityRange; i++)
            {
                for (int j = 0; j < unit.stats.visibilityRange; j++)
                {
                    Assert.IsTrue(scenario.getGameWorld().map.getCell(i, j).explored);
                }
            }
        }
        /// <summary>
        /// Update Input
        /// </summary>
        /// <param name="input"></param>
        /// <param name="testGameController"></param>
        /// <param name="gameView"></param>
        /// <param name="gamePlayMenu"></param>
        public void updateInput(MouseState input, Controller testGameController, ZRTS.View.ViewGame gameView, ViewGamePlayMenu gamePlayMenu)
        {
            // Right click to give a command
            if (input.RightButton == ButtonState.Pressed && prevInput.RightButton == ButtonState.Released)
            {
                giveCommand(input, gameView, testGameController);
            }

            if(gamePlayMenu.containsPoint(input.X, input.Y))
            {
                if (input.LeftButton == ButtonState.Pressed)
                {
                    /** Handle Menu Input **/
                    int button = gamePlayMenu.onButton(input.X, input.Y);
                    //button corespons with the button pressed 0 to 3 left to right

                    if (button == 0)
                    {
                        currentPlayerCommand = PlayerCommand.CANCEL;
                    }
                    if (button == 1)
                    {
                        currentPlayerCommand = PlayerCommand.BUILD;
                    }
                    if (button == 2)
                    {
                        currentPlayerCommand = PlayerCommand.MOVE;
                    }
                    if (button == 3)
                    {
                        currentPlayerCommand = PlayerCommand.ATTACK;
                    }

                }
            }
            else
            {
                handleSelecting(input, testGameController, gameView, gamePlayMenu);
            }

            prevInput = input;
        }
        public void testMove()
        {
            Scenario scenario = new Scenario(20, 20);
            Controller controller = new Controller(scenario);

            Unit unit = new Unit(scenario.getPlayer(), 200);
            controller.addUnit(unit, 10f, 10f);

            // Create a MoveAction
            MoveAction action = new MoveAction(8f, 8f, scenario.getGameWorld(), unit);

            controller.giveActionCommand(unit, action);

            Assert.AreEqual(scenario.getGameWorld().map.getCell(10, 10), unit.getCell());

            // Run 1000 cycles of the game
            for (int i = 0; i < 1000; i++)
            {
                controller.updateWorld();
            }

            // Test if the unit has ended up in the target cell.
            Assert.AreEqual(scenario.getGameWorld().map.getCell(8, 8), unit.getCell());
        }
        /// <summary>
        /// Handle selecting units and buildings by the user
        /// </summary>
        /// <param name="input"></param>
        /// <param name="testGameController"></param>
        /// <param name="gameView"></param>
        /// <param name="gamePlayMenu"></param>
        private void handleSelecting(MouseState input, Controller testGameController, ZRTS.View.ViewScreenConvert gameView, ViewGamePlayMenu gamePlayMenu)
        {
            /* Left click to select units */

            // Store the first corner of the "drag box"
            if (input.LeftButton == ButtonState.Pressed && prevInput.LeftButton == ButtonState.Released)
            {
                if (testGameController.isWithinGameBound(selectX, selectY))
                {
                    selectX = gameView.convertScreenLocToGameLoc(input.X, input.Y).X;
                    selectY = gameView.convertScreenLocToGameLoc(input.X, input.Y).Y;

                    //gameView.setFirstCornerOfDragBox(input.X, input.Y);
                    //gameView.IsDragging = true;
                }

            }

            // While dragging, update the view to draw the box
            if (input.LeftButton == ButtonState.Pressed)
            {
                //gameView.setDragBox(input.X, input.Y);
            }

            // "Drag box" is created, select all units within box
            if (input.LeftButton == ButtonState.Released && prevInput.LeftButton == ButtonState.Pressed)
            {
                float releaseX = gameView.convertScreenLocToGameLoc(input.X, input.Y).X;     // coords of release location
                float releaseY = gameView.convertScreenLocToGameLoc(input.X, input.Y).Y;
                float pressX = selectX;  // coords of press location
                float pressY = selectY;

                if (testGameController.isWithinGameBound(releaseX, releaseY) && testGameController.isWithinGameBound(pressX, pressY))
                {
                    /*
                     * Retrieve all units within the drag box - Use Min and Max to find the topleft and
                     * bottomright corner
                     */
                    testGameController.scenario.selectUnits(
                        (int)Math.Min(pressX, releaseX),
                        (int)Math.Min(pressY, releaseY),
                        (int)(Math.Max(pressX, releaseX) - Math.Min(pressX, releaseX)),
                        (int)(Math.Max(pressY, releaseY) - Math.Min(pressY, releaseY))
                    );
                }

                //gameView.IsDragging = false;
                //gameView.resetDragBox();

            }
        }
        /// <summary>
        /// Give a command when click at icons
        /// </summary>
        /// <param name="input"></param>
        /// <param name="gameView"></param>
        /// <param name="testGameController"></param>
        private void giveCommand(MouseState input, ZRTS.View.ViewScreenConvert gameView, Controller testGameController)
        {
            commandX = gameView.convertScreenLocToGameLoc(input.X, input.Y).X;
            commandY = gameView.convertScreenLocToGameLoc(input.X, input.Y).Y;

            if (testGameController.isWithinGameBound(commandX, commandY))
            {
                foreach (ZRTSModel.Entities.Entity entity in testGameController.scenario.getPlayer().SelectedEntities)
                {
                    switch (currentPlayerCommand)
                    {
                        // Move command
                        case PlayerCommand.MOVE:
                            testGameController.giveActionCommand(entity,
                        new ZRTSLogic.Action.MoveAction(commandX, commandY, testGameController.gameWorld, entity));
                            break;

                        // Cancel command
                        case PlayerCommand.CANCEL:
                            // TODO: Cancel current action
                            break;

                        // Attack command
                        // TODO: Animation of the attack
                        case PlayerCommand.ATTACK:
                            if (entity.entityType == ZRTSModel.Entities.Entity.EntityType.Unit)
                            {
                                // Select Unit at the clicked Cell.
                                ZRTSModel.Entities.Entity temp = testGameController.scenario.getUnit((int)commandX, (int)commandY);

                                // If there is no Unit, select the StaticEntity on the Cell.
                                if (temp == null)
                                {
                                    temp = testGameController.scenario.getGameWorld().map.getCell((int)commandX, (int)commandY).entity;
                                }

                                // If there is an Entity on the Cell.
                                if (temp != null)
                                {
                                    System.Console.Out.WriteLine("Selected Attack at " + commandX + ":" + commandY);
                                    testGameController.giveActionCommand(entity,
                                             new ZRTSLogic.Action.SimpleAttackAction((ZRTSModel.Entities.Unit)entity, temp));
                                }
                            }
                            break;

                        // Build command
                        case PlayerCommand.BUILD:
                            if (testGameController.makeUnitBuild(entity,
                        new ZRTSModel.Entities.Building(testGameController.scenario.getPlayer(), new ZRTSModel.Entities.BuildingStats()),
                        testGameController.gameWorld.map.getCell((int)commandX, (int)commandY)))
                            {
                                System.Console.Out.WriteLine("Building at " + commandX + ":" + commandY);
                            }
                            else
                            {
                                System.Console.Out.WriteLine("Can't place a building at " + commandX + ":" + commandY);
                            }
                            break;
                    }

                }
            }
        }
        /// <summary>
        /// Give a command when click at icons
        /// </summary>
        /// <param name="input"></param>
        /// <param name="gameView"></param>
        /// <param name="testGameController"></param>
        private void giveCommand(MouseState input, View gameView, Controller testGameController)
        {
            commandX = gameView.convertScreenLocToGameLoc(input.X, input.Y).X;
            commandY = gameView.convertScreenLocToGameLoc(input.X, input.Y).Y;

            if (testGameController.isWithinGameBound(commandX, commandY))
            {
                foreach (ZRTSModel.Entities.Entity entity in testGameController.scenario.getPlayer().SelectedEntities)
                {
                    ZRTSModel.GameWorld.Cell cell = testGameController.gameWorld.map.getCell((int)commandX, (int)commandY);
                    if (currentPlayerCommand == PlayerCommand.BUILD)
                    {
                        ZRTSModel.Entities.Building building = new ZRTSModel.Entities.Building(testGameController.scenario.getPlayer(), new ZRTSModel.Entities.BuildingStats());

                        if (testGameController.makeUnitBuild(entity,building, cell))
                        {
                            System.Console.Out.WriteLine("Building at " + commandX + ":" + commandY);
                        }
                        else
                        {
                            System.Console.Out.WriteLine("Can't place a building at " + commandX + ":" + commandY);
                        }
                    }
                    else
                    {
                        if (cell.entity != null)
                        {
                            // TODO: Check that the Entity belongs to an enemy. If not, Move to the entity instead,
                            // TODO: Check if a Resource was clicked, should be harvested or ignored instead.
                            // TODO: Check if Entity is a frienfly building, if so and the unit can build buildings, have unit repair
                            // the building instead.
                            if (entity.entityType == ZRTSModel.Entities.Entity.EntityType.Unit)
                            {
                                    // Right-Clicked on an Entity, Attack the Entity.
                                    System.Console.Out.WriteLine("Selected Attack Entity at " + commandX + ":" + commandY);
                                    testGameController.giveActionCommand(entity,
                                             new ZRTSLogic.Action.SimpleAttackAction((ZRTSModel.Entities.Unit)entity, cell.entity));
                            }
                        }
                        else if (cell.getUnit() != null)
                        {
                            // Right-Clicked on a Unit, attack the Unit.
                            // TODO: Check that the enemy is an entity.
                            if (entity.entityType == ZRTSModel.Entities.Entity.EntityType.Unit)
                            {
                                    System.Console.Out.WriteLine("Selected Attack Unit at " + commandX + ":" + commandY);
                                    ZRTSLogic.Action.AttackAction attackAction = new ZRTSLogic.Action.AttackAction((ZRTSModel.Entities.Unit)entity, cell.getUnit(), testGameController.gameWorld);
                                    testGameController.giveActionCommand(entity, attackAction);
                                    //testGameController.giveActionCommand(entity,
                                             //new ZRTSLogic.Action.SimpleAttackAction((ZRTSModel.Entities.Unit)entity, cell.getUnit()));
                            }
                        }
                        else
                        {
                            // Clicked Cell is empty, have the Unit move to the location.
                            testGameController.giveActionCommand(entity, new ZRTSLogic.Action.MoveAction(commandX, commandY, testGameController.gameWorld, entity));
                        }
                    }
                }
            }
        }
        private void initialize()
        {
            // Initialize game world
            testScenario = new ZRTSModel.Scenario.Scenario(20,20);

            for (int row = 0; row < this.testScenario.getGameWorld().map.height; ++row)
            {
                for (int col = 0; col < this.testScenario.getGameWorld().map.width; ++col)
                {
                    this.testScenario.getGameWorld().map.getCell(col, row).isValid = true;

                }
            }

            this.testScenario.getGameWorld().map.getCell(9, 9).isValid = false;
            this.testScenario.getGameWorld().map.getCell(9, 10).isValid = false;
            this.testScenario.getGameWorld().map.getCell(9, 11).isValid = false;
            this.testScenario.getGameWorld().map.getCell(10, 9).isValid = false;
            this.testScenario.getGameWorld().map.getCell(10, 10).isValid = false;
            this.testScenario.getGameWorld().map.getCell(10, 11).isValid = false;
            this.testScenario.getGameWorld().map.getCell(11, 9).isValid = false;
            this.testScenario.getGameWorld().map.getCell(11, 10).isValid = false;

            this.testScenario.getGameWorld().map.getCell(14, 4).isValid = false;
            this.testScenario.getGameWorld().map.getCell(14, 5).isValid = false;
            this.testScenario.getGameWorld().map.getCell(14, 6).isValid = false;
            this.testScenario.getGameWorld().map.getCell(15, 4).isValid = false;
            this.testScenario.getGameWorld().map.getCell(15, 5).isValid = false;
            this.testScenario.getGameWorld().map.getCell(15, 6).isValid = false;
            this.testScenario.getGameWorld().map.getCell(16, 4).isValid = false;
            this.testScenario.getGameWorld().map.getCell(16, 5).isValid = false;

            this.testScenario.getGameWorld().map.getCell(4, 4).isValid = false;
            this.testScenario.getGameWorld().map.getCell(4, 5).isValid = false;
            this.testScenario.getGameWorld().map.getCell(4, 6).isValid = false;
            this.testScenario.getGameWorld().map.getCell(5, 4).isValid = false;
            this.testScenario.getGameWorld().map.getCell(5, 5).isValid = false;
            this.testScenario.getGameWorld().map.getCell(5, 6).isValid = false;
            this.testScenario.getGameWorld().map.getCell(6, 4).isValid = false;
            this.testScenario.getGameWorld().map.getCell(6, 5).isValid = false;

            ///Set controller
            testGameController = new ZRTSLogic.Controller(testScenario);

            ///Add a unit at (17, 17)
            this.testGameController.addUnit(new ZRTSModel.Entities.Unit(testGameController.scenario.getWorldPlayer(), 20), 17, 17);

            ///Initialize Player's resources
            this.testScenario.getPlayer().player_resources[0] = 150;
            this.testScenario.getPlayer().player_resources[1] = 150;
            this.testScenario.getPlayer().player_resources[2] = 150;
            this.testScenario.getPlayer().player_resources[3] = 150;
        }