Пример #1
0
        public void GetConnections()
        {
            InfiniteGrid grid = Haswell.Controller.City.Grid;
            Point        loc  = new Point(this.Parent.X, this.Parent.Y);

            if (this.GetType() == grid.ElementAt(loc.X + 1, loc.Y).Building.GetType())
            {//North
                this.connections[0] = (Road)grid.ElementAt(loc.X + 1, loc.Y).Building;
            }
            if (this.GetType() == grid.ElementAt(loc.X, loc.Y + 1).Building.GetType())
            {//East
                this.connections[1] = (Road)grid.ElementAt(loc.X, loc.Y + 1).Building;
            }
            if (this.GetType() == grid.ElementAt(loc.X - 1, loc.Y).Building.GetType())
            {//South
                this.connections[2] = (Road)grid.ElementAt(loc.X - 1, loc.Y).Building;
            }
            if (this.GetType() == grid.ElementAt(loc.X, loc.Y - 1).Building.GetType())
            {//West
                this.connections[3] = (Road)grid.ElementAt(loc.X, loc.Y - 1).Building;
            }
        }
Пример #2
0
        /// <summary>
        /// Called by Snowflake when the user requests the creation of a building
        /// Throws an error if something goes wrong.
        /// </summary>
        /// <typeparam name="T">The Type of Building to create</typeparam>
        /// <param name="x">The plot X of the building</param>
        /// <param name="y">The plot Y of the building</param>
        private void CreateBuilding(int x, int y, Building b)
        {
            if (grid.ElementAt(x, y).AddBuilding(b))
            { //Zone check already happens in AddBuilding
                if (BuildingCreated != null)
                {
                    BuildingCreated.Invoke(this, new BuildingEventArgs(b));
                }
                return;
            }

            if (grid.ElementAt(x, y).Building != null)
            {
                throw new Exceptions.BuildingCreationFailedException("Unable to place building - there's already something there!");
            }
            else if (grid.ElementAt(x, y).Zone != b.Zone)
            {
                throw new Exceptions.BuildingCreationFailedException("Cannot create this type of building in " + grid.ElementAt(x, y).Zone.ToString() + " plot!");
            }
            else
            {
                throw new Exceptions.BuildingCreationFailedException("Building creation failed");
            }
        }