+\r
+ public bool IsOnMap(int x, int y)\r
+ {\r
+ return 0 <= x && x < Metadata.GridWidth && 0 <= y && y < Metadata.GridHeight;\r
+ }\r
+\r
+\r
+ public List<IEntity> GetAllEntities()\r
+ {\r
+ List<IEntity> list = new List<IEntity>();\r
+\r
+ foreach (RawEntity raw in mEntities)\r
+ {\r
+ if (raw.Attributes.ContainsKey("type"))\r
+ {\r
+ string typename = raw.Attributes["type"];\r
+\r
+ object[] args = new object[4];\r
+ args[0] = raw.Id;\r
+ args[1] = raw.Position;\r
+ args[2] = raw.Attributes;\r
+ args[3] = Game;\r
+\r
+ try\r
+ {\r
+ IEntity entity = (IEntity)Activator.CreateInstance(System.Type.GetType("CarFire." + typename), args);\r
+ if (entity != null)\r
+ {\r
+ entity.LoadContent(Game.ContentManager);\r
+ list.Add(entity);\r
+ }\r
+ else throw new RuntimeException();\r
+ }\r
+#pragma warning disable 0168\r
+ catch (System.Exception ex)\r
+#pragma warning restore 0168\r
+ {\r
+ throw new RuntimeException("Entity of type " + typename + " not loaded because an entity class can't be found.");\r
+ }\r
+ }\r
+ else\r
+ {\r
+ Console.WriteLine("Ignoring entity with identifier " + raw.Id + " since it has no type key.");\r
+ }\r
+ }\r
+\r
+ return list;\r
+ }\r
+\r
+ public List<T> GetEntities<T>()\r
+ {\r
+ System.Type type = typeof(T);\r
+ List<T> list = new List<T>();\r
+\r
+ string typename = typeof(T).Name;\r
+ foreach (RawEntity raw in mEntities)\r
+ {\r
+ if (raw.Attributes.ContainsKey("type") && typename == raw.Attributes["type"])\r
+ {\r
+ object[] args = new object[4];\r
+ args[0] = raw.Id;\r
+ args[1] = raw.Position;\r
+ args[2] = raw.Attributes;\r
+ args[3] = Game;\r
+\r
+ T entity = (T)Activator.CreateInstance(type, args);\r
+ if (entity != null)\r
+ {\r
+ ((IEntity)entity).LoadContent(Game.ContentManager);\r
+ list.Add(entity);\r
+ }\r
+ else throw new RuntimeException("Entity of type " + typename + " not loaded because an entity class can't be found.");\r
+ }\r
+ }\r
+\r
+ return list;\r
+ }\r
+\r
+\r
+ Metadata mMetadata;\r
+ char[,] mGrid;\r
+ char[,] mCleanGrid;\r
+ bool[,] mBooleanGrid;\r
+ char mDefaultTile;\r
+ List<RawEntity> mEntities;\r
+ Point[] mPlayerPositions;\r