]> Dogcows Code - chaz/carfire/commitdiff
New map methods Map.SetCell and Map.ClearCell to modify the tiles of the map. These...
authorCharles <Charles@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Fri, 16 Apr 2010 18:42:51 +0000 (18:42 +0000)
committerCharles <Charles@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Fri, 16 Apr 2010 18:42:51 +0000 (18:42 +0000)
git-svn-id: https://bd85.net/svn/cs3505_group@97 92bb83a3-7c8f-8a45-bc97-515c4e399668

CarFire/CarFire/CarFire/Map.cs
CarFire/CarFire/CarFire/MapReader.cs

index f3d59d4a705a6e2e341a0177cf4e87f23fb46f7f..6727133bc79c1ee72471e67d8f30c0fd2fa7349e 100644 (file)
@@ -128,14 +128,27 @@ namespace CarFire
         public string Tileset { get { return mData.Metadata.Tileset; } }\r
 \r
         /// <summary>\r
-        /// Get a list of the raw entity containers loaded with the map.\r
+        /// Get the current grid of open cells.  On the grid, true means\r
+        /// the cell is open (i.e. an entity can occupy that cell), and false\r
+        /// means the cell is closed.  Note that, just like Map.IsCellOpen,\r
+        /// only static scenery is considered; the grid cannot tell you\r
+        /// whether or not an entity is already occupying the cell.\r
+        /// </summary>\r
+        public bool[,] Grid { get { return mData.Grid; } }\r
+\r
+        /// <summary>\r
+        /// Get a list of the raw entity containers loaded with the map.  If you\r
+        /// want to get the actual entity objects, use Map.GetEntities and\r
+        /// Map.GetAllEntities instead.\r
         /// </summary>\r
         public List<RawEntity> RawEntities { get { return mData.Entities; } }\r
 \r
 \r
         /// <summary>\r
         /// Get and set the coordinate of the grid cell that should be in\r
-        /// the center of the screen when the map is drawn.\r
+        /// the center of the screen when the map is drawn.  Setting this\r
+        /// will change the viewport of the map and will effect the return\r
+        /// values of Map.GetPointFromCoordinates and Map.GetRectangleFromCoordinates.\r
         /// </summary>\r
         public Vector2 CenterCell\r
         {\r
@@ -154,9 +167,10 @@ namespace CarFire
         /// <param name="metadata">The metadata.</param>\r
         /// <param name="grid">The grid.</param>\r
         /// <param name="entities">The entities.</param>\r
-        public Map(Metadata metadata, char[,] grid, List<RawEntity> entities, Point[] playerPositions)\r
+        public Map(Metadata metadata, char[,] grid, char defaultTile,\r
+            List<RawEntity> entities, Point[] playerPositions)\r
         {\r
-            mData = new Modal(metadata, grid, entities, playerPositions);\r
+            mData = new Modal(metadata, grid, defaultTile, entities, playerPositions);\r
             mView = new View(mData);\r
         }\r
 \r
@@ -270,6 +284,48 @@ namespace CarFire
             return mData.GetEntities<T>();\r
         }\r
 \r
+\r
+        /// <summary>\r
+        /// Set the tile of a cell.\r
+        /// </summary>\r
+        /// <param name="x">X-coordinate.</param>\r
+        /// <param name="y">Y-coordinate.</param>\r
+        /// <param name="tile">The character representing the tile.</param>\r
+        public void SetCell(int x, int y, char tile)\r
+        {\r
+            mData.SetCell(x, y, tile);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Set the tile of a cell.\r
+        /// </summary>\r
+        /// <param name="point">X,Y-coordinates.</param>\r
+        /// <param name="tile">The character representing the tile.</param>\r
+        public void SetCell(Point point, char tile)\r
+        {\r
+            mData.SetCell(point.X, point.Y, tile);\r
+        }\r
+\r
+\r
+        /// <summary>\r
+        /// Clear a cell to the default tile.\r
+        /// </summary>\r
+        /// <param name="x">X-coordinate.</param>\r
+        /// <param name="y">Y-coordinate.</param>\r
+        public void ClearCell(int x, int y)\r
+        {\r
+            mData.ClearCell(x, y);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Clear a cell to the default tile.\r
+        /// </summary>\r
+        /// <param name="point">X,Y-coordinates.</param>\r
+        public void ClearCell(Point point)\r
+        {\r
+            mData.ClearCell(point.X, point.Y);\r
+        }\r
+\r
         #endregion\r
 \r
 \r
@@ -279,10 +335,13 @@ namespace CarFire
         {\r
             Metadata mMetadata;\r
             char[,] mGrid;\r
+            char mDefaultTile;\r
             List<RawEntity> mEntities;\r
             Point[] mPlayerPositions;\r
+            bool[,] mBooleanGrid;\r
 \r
-            public Modal(Metadata metadata, char[,] grid, List<RawEntity> entities, Point[] playerPositions)\r
+            public Modal(Metadata metadata, char[,] grid, char defaultTile,\r
+                List<RawEntity> entities, Point[] playerPositions)\r
             {\r
                 Debug.Assert(metadata != null);\r
                 Debug.Assert(grid != null);\r
@@ -291,9 +350,19 @@ namespace CarFire
 \r
                 mMetadata = metadata;\r
                 mGrid = grid;\r
+                mDefaultTile = defaultTile;\r
                 mEntities = entities;\r
                 mPlayerPositions = playerPositions;\r
 \r
+                mBooleanGrid = new bool[mMetadata.GridWidth, mMetadata.GridHeight];\r
+                for (int x = 0; x < mMetadata.GridWidth; x++)\r
+                {\r
+                    for (int y = 0; y < mMetadata.GridHeight; y++)\r
+                    {\r
+                        mBooleanGrid[x, y] = IsCellOpen(x, y);\r
+                    }\r
+                }\r
+\r
 #if DEBUG\r
                 Console.WriteLine("Loaded map {0} of type {1} written by {2}.",\r
                     metadata.Name,\r
@@ -306,6 +375,7 @@ namespace CarFire
             public Metadata Metadata { get { return mMetadata; } }\r
             public List<RawEntity> Entities { get { return mEntities; } }\r
             public Point[] PlayerPositions { get { return mPlayerPositions; } }\r
+            public bool[,] Grid { get { return mBooleanGrid; } }\r
 \r
 \r
             public bool IsCellOpen(int x, int y)\r
@@ -314,6 +384,17 @@ namespace CarFire
                 return mGrid[x, y] == ' ';\r
             }\r
 \r
+            public void SetCell(int x, int y, char tile)\r
+            {\r
+                mGrid[x, y] = tile;\r
+                mBooleanGrid[x, y] = IsCellOpen(x, y);\r
+            }\r
+\r
+            public void ClearCell(int x, int y)\r
+            {\r
+                SetCell(x, y, mDefaultTile);\r
+            }\r
+\r
 \r
             public List<object> GetAllEntities()\r
             {\r
index 8eb7e16f98fd85af5027e5e79cc1e30a479b42ae..ae03ff9ea7b607aa7055cf411c86fa35031d25d5 100644 (file)
@@ -96,7 +96,7 @@ namespace CarFire
 \r
             public Map GetMap()\r
             {\r
-                return new Map(mMetadata, mGrid, mEntities, mPlayerPositions);\r
+                return new Map(mMetadata, mGrid, mDefaultTile, mEntities, mPlayerPositions);\r
             }\r
 \r
 \r
@@ -425,10 +425,9 @@ namespace CarFire
             char[,] mGrid;\r
             List<Map.RawEntity> mEntities;\r
             Point[] mPlayerPositions;\r
-\r
-            Dictionary<char, Dictionary<string, string>> mEntitySections = new Dictionary<char, Dictionary<string, string>>();\r
             char mDefaultTile = ' ';\r
 \r
+            Dictionary<char, Dictionary<string, string>> mEntitySections = new Dictionary<char, Dictionary<string, string>>();\r
             LineReader mInput;\r
         }\r
 \r
This page took 0.030619 seconds and 4 git commands to generate.