Пример #1
0
        /// <summary>
        /// Places the building being dragged
        /// </summary>
        void placeDraggedBuilding()
        {
            // placement is valid, set the new location
            if (draggedBuilding.IsPlacementValid)
            {
                // node index from the building bounds
                var newLocation = new Point()
                {
                    Y = draggedBuildingBounds.X / gridNodeSize.X,
                    X = draggedBuildingBounds.Y / gridNodeSize.Y
                };

                // move to the building to its new location
                draggedBuilding.MoveTo(newLocation);
                // stop dragging the building
                draggedBuilding.SetDragging(false);
                // remove our reference
                draggedBuilding = null;
            }
            else
            {
                // the placement was invalid, play the error sound
                invalidPlacementSound.Play();
            }
        }
Пример #2
0
        /// <summary>
        /// Adds a building to the world's entities
        /// </summary>
        /// <param name="type"> Building type </param>
        /// <param name="location"> Target node index location </param>
        public void AddBuilding(Building type, Point location)
        {
            var building = new BuildingEntity(this, buildingProperties[type]);

            building.MoveTo(location);

            entities.Add(building);
        }