Exemplo n.º 1
0
        /// <summary>
        /// Creates a new copy of an EnvironmentTile from a particular template.
        /// </summary>
        /// <param name="templateName">The name of the template.</param>
        /// <param name="newPosition">The position of the tile.</param>
        /// <returns>A new EnvironmentTile.</returns>
        public EnvironmentTile GetNewTile(string templateName,
                                          Point newPosition)
        {
            TileTemplate    template = _tileTemplates[templateName];
            EnvironmentTile returnMe = new EnvironmentTile(template.Texture, template.CanAccess, _owner);

            returnMe.Id            = new Guid();
            returnMe.Position      = newPosition;
            returnMe.AdjacentTiles = new List <EnvironmentTile>(4);
            returnMe.ItemsOnGround = new List <Item>();
            if (returnMe.CanAccess)
            {
                returnMe.AreaID = 0;
            }
            else
            {
                returnMe.AreaID = -1;
            }
            for (int i = 0; i < 4; i++)
            {
                returnMe.AdjacentTiles.Add(null);
            }
            returnMe.ActorsOnTile = new List <Actor>();
            return(returnMe);
        }
Exemplo n.º 2
0
        public List <Node <Point> > GetSuccessorsWithDirectionMinusParent(Point point, Point parentPoint)
        {
            List <Node <Point> > returnList = GetAdjacentDirections(point);
            EnvironmentTile      parentTile = _gameWorld[parentPoint.X, parentPoint.Y];

            foreach (Node <Point> n in returnList)
            {
                if (n.Position == parentTile.Position)
                {
                    returnList.Remove(n);
                    break;
                }
            }
            return(returnList);
        }
Exemplo n.º 3
0
        private List <Node <Point> > GetAdjacentDirections(Point point)
        {
            List <Node <Point> > returnList  = new List <Node <Point> >();
            EnvironmentTile      currentTile = _gameWorld[point.X, point.Y];


            if (currentTile.WestTile != null)
            {
                if (currentTile.WestTile.CanAccess)
                {
                    //Note: Those directions are where the node is coming *FROM*
                    Node <Point> newNode = new Node <Point>(currentTile.WestTile.Position, Direction.East);
                    returnList.Add(newNode);
                }
            }
            if (currentTile.EastTile != null)
            {
                if (currentTile.EastTile.CanAccess)
                {
                    Node <Point> newNode = new Node <Point>(currentTile.EastTile.Position, Direction.West);
                    returnList.Add(newNode);
                }
            }
            if (currentTile.NorthTile != null)
            {
                if (currentTile.NorthTile.CanAccess)
                {
                    Node <Point> newNode = new Node <Point>(currentTile.NorthTile.Position, Direction.South);
                    returnList.Add(newNode);
                }
            }
            if (currentTile.SouthTile != null)
            {
                if (currentTile.SouthTile.CanAccess)
                {
                    Node <Point> newNode = new Node <Point>(currentTile.SouthTile.Position, Direction.North);
                    returnList.Add(newNode);
                }
            }

            return(returnList);
        }
Exemplo n.º 4
0
 /// <summary>
 /// If a tile access flag has changed, this could preclude the joining or separation
 /// of areas. This method will handle that logic of joining/separating.
 /// </summary>
 /// <param name="theTile">The tile changing state.</param>
 public void ManageAccessStateChange(EnvironmentTile theTile)
 {
     if (theTile.CanAccess)
     {
         _areaDictionary[-1].Members.Remove(theTile);
         _areaDictionary[-1].MemberCount--;
         // Here we need to check if two areas have merged
         List <Point> accessPoints = theTile.GetAdjacentAccessPoints();
         foreach (Point point in accessPoints)
         {
             foreach (Point pointTwo in accessPoints)
             {
                 if (point != pointTwo)
                 {
                     EnvironmentTile firstTile  = _world[point];
                     EnvironmentTile secondTile = _world[pointTwo];
                     if (firstTile.AreaID != secondTile.AreaID)
                     {
                         // Merge requried
                         Area mergeOne = _areaDictionary[firstTile.AreaID];
                         Area mergeTwo = _areaDictionary[secondTile.AreaID];
                         theTile.AreaID = Area.MergeTwoAreas(mergeOne, mergeTwo);
                     }
                 }
             }
         }
         if (theTile.AreaID == -1)
         {
             theTile.AreaID = _world[accessPoints[0]].AreaID;
         }
     }
     else
     {
         // now here we need to use the edge state to determine splitting up an area
         _areaDictionary[theTile.AreaID].Members.Remove(theTile);
         _areaDictionary[theTile.AreaID].MemberCount--;
         theTile.AreaID = -1;
     }
     _areaDictionary[theTile.AreaID].Members.Add(theTile);
     _areaDictionary[theTile.AreaID].MemberCount++;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Loads a test environment.
        /// </summary>
        public void LoadTestEnvironment()
        {
            Owner.SpatialTreeIndex.Initialise();

            Random someNumber = new Random(0);

            for (int i = 0; i < _worldSize.X; i++)
            {
                for (int j = 0; j < _worldSize.Y; j++)
                {
                    int tileToUse = someNumber.Next(0, 6);
                    if (tileToUse >= 5)
                    {
                        EnvironmentTile tileAdded = SpawnTile("grass", new Point(i, j));
                        tileAdded.InteractableObject = new HarvestableInteractableObject(Owner, tileAdded, "tree1", 10, "wood", "woodchopping");
                    }
                    else if (tileToUse >= 1)
                    {
                        SpawnTile("grass", new Point(i, j));
                    }
                    else
                    {
                        SpawnTile("rock", new Point(i, j));
                    }
                }
            }
            InitialiseHelperClasses();
            for (int i = 0; i < _worldSize.X; i++)
            {
                for (int j = 0; j < _worldSize.Y; j++)
                {
                    if (this[i, j].InteractableObject != null)
                    {
                        this[i, j].CanAccess = false;
                    }
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// If a tile access flag has changed, this could preclude the joining or separation
 /// of areas. This method will handle that logic of joining/separating.
 /// </summary>
 /// <param name="theTile">The tile changing state.</param>
 public void ManageAccessStateChange(EnvironmentTile theTile)
 {
     //_edgeTraversal.CanAccessChanged(theTile);
     _areaDictionary.ManageAccessStateChange(theTile);
 }