Пример #1
0
        /// <summary>
        /// Initializes the players onto te map.
        /// </summary>
        /// <param name="map">Map.</param>
        /// <param name="canWalk">Can walk.</param>
        /// <param name="players">Players.</param>
        public void initializePlayers(int[,] map, int[,] canWalk, Player[] players)
        {
            int i = 0;

            foreach (Region region in regions)
            {
                if (region.GetType().Equals(typeof(LandRegion)))
                {
                    LandRegion lr = (LandRegion)region;
                    // Place a castle at every landregion
                    lr.PlaceCastle(map, canWalk);
                    if (i < players.Length)
                    {
                        // Create a player, set the castles owner as that player.
                        // Also place a corresponding hero.
                        players[i] = new Player(i, 0);
                        lr.GetCastle().Player = players[i];
                        lr.GetCastle().Town.Owner = players[i];
                        players[i].Castle.Add(lr.GetCastle());
                        i++;
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Tests the paths between all buildings inside a given land-region.
        /// </summary>
        /// <returns><c>true</c>, if paths between buildings was accessable, <c>false</c> otherwise.</returns>
        /// <param name="region">Region.</param>
        /// <param name="canWalk">Can walk.</param>
        public bool TestPathsBetweenBuildings(LandRegion region, int[,] canWalk)
        {
            AStarAlgo aStar = new AStarAlgo(canWalk, canWalk.GetLength(0), canWalk.GetLength(1), false);

            Point castlePlacement = region.GetCastle().GetPosition();

            foreach (OverworldBuilding building in region.GetBuildings())
            {
                Point buildingPlacement = building.Origo;
                if (aStar.calculate(castlePlacement, buildingPlacement).Count == 0)
                {
                    return(false);
                }
            }

            return(true);
        }