AIBase.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // AIBase.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using Microsoft.Xna.Framework;
  14. using RobotGameData.GameInterface;
  15. #endregion
  16. namespace RobotGameData.AI
  17. {
  18. /// <summary>
  19. /// s is the base class for A.I.
  20. /// It contains the event hander functions regarding Start, Update, and Finish.
  21. /// </summary>
  22. public class AIBase : INamed
  23. {
  24. #region Fields
  25. string name = String.Empty;
  26. float activeTime = 0.0f;
  27. #endregion
  28. #region Events
  29. public class AIUpdateEventArgs : EventArgs
  30. {
  31. private GameTime gameTime;
  32. public GameTime GameTime
  33. {
  34. get { return gameTime; }
  35. }
  36. public AIUpdateEventArgs(GameTime gameTime)
  37. : base()
  38. {
  39. this.gameTime = gameTime;
  40. }
  41. }
  42. public event EventHandler<AIUpdateEventArgs> Updating;
  43. public event EventHandler Starting;
  44. public event EventHandler Finishing;
  45. #endregion
  46. #region Properties
  47. public string Name
  48. {
  49. get { return name; }
  50. set { name = value; }
  51. }
  52. public float ActiveTime
  53. {
  54. get { return activeTime; }
  55. set { activeTime = value; }
  56. }
  57. public bool IsActive
  58. {
  59. get { return (activeTime > 0.0f); }
  60. }
  61. #endregion
  62. /// <summary>
  63. /// Reset the A.I.
  64. /// </summary>
  65. public void Reset()
  66. {
  67. ActiveTime = 0.0f;
  68. }
  69. /// <summary>
  70. /// Updates the A.I.
  71. /// </summary>
  72. public void Update(GameTime gameTime)
  73. {
  74. AIUpdate(gameTime);
  75. }
  76. /// <summary>
  77. /// As the A.I. gets updated, the event function always gets called.
  78. /// </summary>
  79. public void AIUpdate(GameTime gameTime)
  80. {
  81. if (Updating != null)
  82. {
  83. Updating(this, new AIUpdateEventArgs(gameTime));
  84. }
  85. }
  86. /// <summary>
  87. /// As the A.I. starts, the registered event function gets called right away.
  88. /// </summary>
  89. public void AIStart()
  90. {
  91. if (Starting != null)
  92. {
  93. Starting(this, EventArgs.Empty);
  94. }
  95. }
  96. /// <summary>
  97. /// As the A.I. ends, the registered event function gets called right away.
  98. /// </summary>
  99. public void AIFinish()
  100. {
  101. if (Finishing != null)
  102. {
  103. Finishing(this, EventArgs.Empty);
  104. }
  105. }
  106. }
  107. }