PageRenderTime 182ms CodeModel.GetById 80ms app.highlight 2ms RepoModel.GetById 99ms app.codeStats 0ms

/Engine/Game/World.cs

#
C# | 75 lines | 41 code | 9 blank | 25 comment | 0 complexity | 59b0e14c0055e7239698079a1037e544 MD5 | raw file
 1using System.Collections.Generic;
 2
 3namespace Delta.Engine.Game
 4{
 5	/// <summary>
 6	/// Basic world class containing a list of actors which can be spawned and
 7	/// despawned into the world.
 8	/// </summary>
 9	public class World
10	{
11		#region AllActors (Public)
12		/// <summary>
13		/// Array of all actors in this world.
14		/// </summary>
15		public Actor[] AllActors
16		{
17			get
18			{
19				return actors.ToArray();
20			}
21		}
22		#endregion
23
24		#region Private
25
26		#region actors (Private)
27		/// <summary>
28		/// List of all actors in this world.
29		/// </summary>
30		private readonly List<Actor> actors;
31		#endregion
32
33		#endregion
34
35		#region Constructors
36		/// <summary>
37		/// Create a new world.
38		/// </summary>
39		public World()
40		{
41			actors = new List<Actor>();
42		}
43		#endregion
44
45		#region SpawnActor (Public)
46		/// <summary>
47		/// Spawn an actor in the world.
48		/// </summary>
49		/// <param name="newActor">The new actor to spawn.</param>
50		public void SpawnActor(Actor newActor)
51		{
52			// Call the "Spawned" function to let the actor do logic after being
53			// spawned.
54			newActor.Spawned();
55
56			// Add actor to our list of actors
57			actors.Add(newActor);
58		}
59		#endregion
60
61		#region DespawnActor (Public)
62		/// <summary>
63		/// Calls the despawned method of the actor and then removes the actor
64		/// from the list of known actors.
65		/// </summary>
66		/// <param name="actor">The actor to despawn.</param>
67		public void DespawnActor(Actor actor)
68		{
69			actor.Despawned();
70
71			actors.Remove(actor);
72		}
73		#endregion
74	}
75}