From beb1ce501897ce4c00f7e97c6923ba0af2451732 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 23 Apr 2010 15:25:14 +0000 Subject: [PATCH] Map shouldn't keep a reference to the game as if it were a property, but it is needed to construct entities; so just pass a game reference to the entity getters. git-svn-id: https://bd85.net/svn/cs3505_group@138 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Game.cs | 5 ++--- CarFire/CarFire/CarFire/Map.cs | 34 ++++++++++++--------------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/CarFire/CarFire/CarFire/Game.cs b/CarFire/CarFire/CarFire/Game.cs index 937cd4d..3808841 100644 --- a/CarFire/CarFire/CarFire/Game.cs +++ b/CarFire/CarFire/CarFire/Game.cs @@ -260,7 +260,7 @@ namespace CarFire { State.mCharacters[i].Coordinates = State.Map.GetStartingPositionForPlayer(i + 1); } - State.Entities = State.Map.GetAllEntities(); + State.Entities = State.Map.GetAllEntities(this); } public void LoadContent(ContentManager contentManager) { @@ -312,8 +312,7 @@ namespace CarFire State.mDisplay.LoadContent(mContentManager); State.Map = mContentManager.Load("Maps/stable"); - State.Map.Game = this; - State.Entities = State.Map.GetAllEntities(); + State.Entities = State.Map.GetAllEntities(this); Map.DefaultTile = mContentManager.Load("default"); /* diff --git a/CarFire/CarFire/CarFire/Map.cs b/CarFire/CarFire/CarFire/Map.cs index 8c744ba..f4d7ea4 100644 --- a/CarFire/CarFire/CarFire/Map.cs +++ b/CarFire/CarFire/CarFire/Map.cs @@ -166,16 +166,6 @@ namespace CarFire set { mView.Zoom = value; } } - - /// - /// Get and set the associated game object. - /// - public Game Game - { - get { return mData.Game; } - set { mData.Game = value; } - } - #endregion @@ -287,21 +277,23 @@ namespace CarFire /// Get all the entities loaded from the map file. Exceptions could be /// thrown if there are entities without associated classes. /// + /// The game reference to be passed to entities. /// List of entity objects loaded. - public List GetAllEntities() + public List GetAllEntities(Game game) { - return mData.GetAllEntities(); + return mData.GetAllEntities(game); } /// /// Get the entities of a certain type loaded from the map file. Exceptions /// could be thrown if there are entities without associated classes. /// + /// The game reference to be passed to entities. /// Type of the entity you want a list of. /// List of entity objects loaded. - public List GetEntities() + public List GetEntities(Game game) { - return mData.GetEntities(); + return mData.GetEntities(game); } @@ -368,8 +360,6 @@ namespace CarFire public Point[] PlayerPositions { get { return mPlayerPositions; } } public bool[,] Grid { get { return mBooleanGrid; } } - public Game Game; - public Model(Metadata metadata, char[,] grid, char defaultTile, List entities, Point[] playerPositions) @@ -438,7 +428,7 @@ namespace CarFire } - public List GetAllEntities() + public List GetAllEntities(Game game) { List list = new List(); @@ -452,14 +442,14 @@ namespace CarFire args[0] = raw.Id; args[1] = raw.Position; args[2] = raw.Attributes; - args[3] = Game; + args[3] = game; try { IEntity entity = (IEntity)Activator.CreateInstance(System.Type.GetType("CarFire." + typename), args); if (entity != null) { - entity.LoadContent(Game.ContentManager); + entity.LoadContent(game.ContentManager); list.Add(entity); } else throw new RuntimeException(); @@ -480,7 +470,7 @@ namespace CarFire return list; } - public List GetEntities() + public List GetEntities(Game game) { System.Type type = typeof(T); List list = new List(); @@ -494,12 +484,12 @@ namespace CarFire args[0] = raw.Id; args[1] = raw.Position; args[2] = raw.Attributes; - args[3] = Game; + args[3] = game; T entity = (T)Activator.CreateInstance(type, args); if (entity != null) { - ((IEntity)entity).LoadContent(Game.ContentManager); + ((IEntity)entity).LoadContent(game.ContentManager); list.Add(entity); } else throw new RuntimeException("Entity of type " + typename + " not loaded because an entity class can't be found."); -- 2.45.2