PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Engine/Game/World.cs

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