/// <summary>
        ///
        /// </summary>
        /// <param name="previousSelection"></param>
        private void TileMenu()
        {
            MenuIcon moveUnits = new MenuIcon(Language.Instance.GetString("MoveUnits"), null, Color.Black);
            MenuIcon cancel    = new MenuIcon(Language.Instance.GetString("Cancel"), Recellection.textureMap.GetTexture(Globals.TextureTypes.No), Color.Black);

            List <MenuIcon> menuIcons = new List <MenuIcon>();

            if (theWorld.GetMap().GetTile(previousSelection.absPoint).GetUnits(playerInControll).Count > 0)
            {
                // Only show this options if there are units.
                menuIcons.Add(moveUnits);
            }
            menuIcons.Add(cancel);

            Menu buildingMenu = new Menu(Globals.MenuLayout.FourMatrix, menuIcons, Language.Instance.GetString("TileMenu"), Color.Black);

            MenuController.LoadMenu(buildingMenu);
            Recellection.CurrentState = MenuView.Instance;
            MenuIcon choosenMenu = MenuController.GetInput();

            Recellection.CurrentState = WorldView.Instance;
            MenuController.UnloadMenu();

            if (choosenMenu == moveUnits)
            {
                Selection currSel = retrieveSelection();
                if (!(currSel.state == State.TILE || currSel.state == State.BUILDING))
                {
                    return;
                }


                Tile from = theWorld.GetMap().GetTile(previousSelection.absPoint);
                SelectTile(theWorld.GetMap().GetTile(currSel.absPoint));

                UnitController.MoveUnits(playerInControll, from, selectedTile, from.GetUnits().Count);
            }
        }
        public void Run()
        {
            backgroundSound.Play();

            while (!finished)
            {
                logger.Debug("Victor turner is turning the page!");
                foreach (Player player in players)
                {
                    if (player is AIPlayer)
                    {
                        logger.Debug(player.color + " is a AIPlayer!");
                        ((AIPlayer)player).MakeMove();
                    }
                    else if (player is Player)
                    {
                        logger.Debug(player.color + " is human!");
                        //This only makes the grid of GUIRegions and scroll zones, remove later.
                        humanControl.Run();
                    }
                    else
                    {
                        logger.Fatal("Could not identify " + player.color + " player!");
                    }
                    if (CheckIfLostOrWon(players))
                    {
                        finished = true;
                        EndGame(players[0]);
                        break;
                    }
                }
                if (finished)
                {
                    break;
                }
                logger.Info("Weighting graphs!");
                foreach (Player player in players)
                {
                    player.unitAcc.ProduceUnits();
                }

                graphControl.CalculateWeights();

                // This is where we start "animating" all movement
                // FIXME: This ain't okay, hombrey
                // Let the units move!
                logger.Info("Moving units!");

                for (int u = 0; u < 5; u++)
                {
                    foreach (Player p in players)
                    {
                        BuildingController.AggressiveBuildingAct(p);
                    }

                    for (int i = 0; i < 100; i++)
                    {
                        UnitController.Update(world.units, 1, world.GetMap());
                        System.Threading.Thread.Sleep(10);
                    }
                }
            }
        }
예제 #3
0
 /// <param name="numberOfUnits">The number of units to move.</param>
 /// <param name="from">From what fromBuilding to move.</param>
 /// <param name="to">Destination for the units.</param>
 private void MoveUnits(int numberOfUnits, Building from, Building to)
 {
     UnitController.MoveUnits(from.owner, from.controlZone.First.Value, to.controlZone.First.Value, numberOfUnits);
 }
        /// <summary>
        /// Loads the Building menu from a selection.
        /// Must have building on tile.
        /// </summary>
        /// <param name="theSelection"></param>
        private void BuildingMenu()
        {
            World.Map map      = theWorld.GetMap();
            Building  building = selectedTile.GetBuilding();

            if (building == null || building.owner != playerInControll)
            {
                return;
            }
            int toHeal = Math.Min(building.maxHealth - building.currentHealth, building.units.Count());

            MenuIcon setWeight    = new MenuIcon(Language.Instance.GetString("SetWeight"));
            MenuIcon buildCell    = new MenuIcon(Language.Instance.GetString("BuildCell"));
            MenuIcon removeCell   = new MenuIcon(Language.Instance.GetString("RemoveCell"));
            MenuIcon upgradeUnits = new MenuIcon(Language.Instance.GetString("UpgradeUnits") + " (" + playerInControll.unitAcc.GetUpgradeCost() + ")");
            MenuIcon moveUnits    = new MenuIcon(Language.Instance.GetString("MoveUnits"));
            MenuIcon repairCell   = new MenuIcon(Language.Instance.GetString("RepairCell") + " (" + toHeal + ")");
            MenuIcon setAggro     = new MenuIcon(Language.Instance.GetString("SetAggro"));
            MenuIcon Cancel       = new MenuIcon(Language.Instance.GetString("Cancel"), Recellection.textureMap.GetTexture(Globals.TextureTypes.No));

            List <MenuIcon> menuIcons = new List <MenuIcon>();

            menuIcons.Add(setWeight);
            menuIcons.Add(buildCell);
            menuIcons.Add(removeCell);
            menuIcons.Add(upgradeUnits);
            menuIcons.Add(moveUnits);
            menuIcons.Add(repairCell);
            menuIcons.Add(setAggro);
            menuIcons.Add(Cancel);

            Menu buildingMenu = new Menu(Globals.MenuLayout.NineMatrix, menuIcons, Language.Instance.GetString("BuildingMenu"), Color.Black);

            MenuController.LoadMenu(buildingMenu);
            Recellection.CurrentState = MenuView.Instance;
            MenuIcon choosenMenu = MenuController.GetInput();

            Recellection.CurrentState = WorldView.Instance;
            MenuController.UnloadMenu();

            if (choosenMenu.Equals(setWeight))
            {
                GraphController.Instance.SetWeight(building);
            }
            else if (choosenMenu.Equals(buildCell))
            {
                tobii.SetFeedbackColor(Color.DarkGreen);
                Selection destsel;
                do
                {
                    SetConstructionLines(BuildingController.GetValidBuildingInterval(selectedTile.position, theWorld));
                    destsel = retrieveSelection();
                    RemoveconstructionTileLines(BuildingController.GetValidBuildingInterval(selectedTile.position, theWorld));
                }while (destsel.state != State.TILE);

                tobii.SetFeedbackColor(Color.White);

                SelectTile(map.GetTile(destsel.absPoint));

                //TODO Add a check to see if the tile is a correct one. The diffrence between the selected tiles coordinates and the source building shall not exceed 3.
                if (selectedTile.GetBuilding() == null)
                {
                    try
                    {
                        BuildingController.ConstructBuilding(playerInControll, selectedTile, building, theWorld);
                        tobii.SetFeedbackColor(Color.White);
                    }
                    catch (BuildingController.BuildingOutOfRangeException)
                    {
                        logger.Debug("Caught BuildingOutOfRangeExcpetion");
                    }
                }
                else
                {
                    //SoundsController.playSound("Denied");
                    tobii.SetFeedbackColor(Color.White);
                    return;
                }
            }
            else if (choosenMenu.Equals(removeCell))
            {
                BuildingController.RemoveBuilding(building);
            }
            else if (choosenMenu.Equals(upgradeUnits))
            {
                upgradeMenu();
            }
            else if (choosenMenu.Equals(moveUnits))
            {
                tobii.SetFeedbackColor(Color.Red);

                Selection destsel = retrieveSelection();
                if (destsel.state == State.BUILDING || destsel.state == State.TILE)
                {
                    Tile selTile = map.GetTile(destsel.absPoint);
                    UnitController.MoveUnits(playerInControll, selectedTile, selTile, building.GetUnits().Count);
                }

                tobii.SetFeedbackColor(Color.White);
            }
            else if (choosenMenu.Equals(repairCell))
            {
                playerInControll.unitAcc.DestroyUnits(building.units, toHeal);
                building.Repair(toHeal);
            }
            else if (choosenMenu.Equals(setAggro))
            {
                building.IsAggressive = !building.IsAggressive;
                building.UpdateAggressiveness(null, new Event <IEnumerable <Unit> >(building.GetUnits(), EventType.ADD));
            }
            else if (choosenMenu.Equals(Cancel))
            {
                return;
            }
            else
            {
                return;
            }
        }
 public void DestroyUnits(List <Unit> u, int n)
 {
     UnitController.MarkUnitsAsDead(u, n);
     UnitController.RemoveDeadUnits();
 }