GameObjectsList.cpp
上传用户:royluo
上传日期:2007-01-05
资源大小:1584k
文件大小:4k
源码类别:

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   GameObjectsList.cpp                                                            
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Module description: Implements the global game object list.
  11. *                       The list consists of 4 sub-lists, one for every game
  12. *                       level (z-order): background, lower, higher and sky.
  13. *                       
  14. *                                                                             
  15. *   Authors: Eran Yariv - 28484475                                           
  16. *            Moshe Zur  - 24070856                                           
  17. *                                                                            
  18. *                                                                            
  19. *   Date: 23/09/98                                                           
  20. *                                                                            
  21. ******************************************************************************/
  22. #include <stdafx.h>
  23. #include <GameObjectsList.h>
  24. /*------------------------------------------------------------------------------
  25.   Function: GetGameReaction
  26.   Purpose:  Collects the reaction of all the game objects to the new position of 
  27.             the object in question.
  28.   Input:    pObj - pointer to object we test the reaction upon.
  29.   Output:   The sum of all game objects reaction to our object.
  30.   Remarks:  This method is called by the game manager for every game object in 
  31.             every iteration.
  32. ------------------------------------------------------------------------------*/
  33. CReaction 
  34. CGameObjectsList::GetGameReaction (CGameObject *pObj)
  35. {
  36.     UINT uMaxExplosionIntensity = 0;
  37.     TerrainType MaxTerrainDifficulty = TERR_EMPTY;
  38.     BonusType bt = BONUS_NONE;
  39.     UINT uMaxTankID = 0;
  40.     LIST_POS lp = GetHeadPosition(); 
  41.     for (CGameObject* pCurObj = GetNext(lp); pCurObj; pCurObj = GetNext(lp))
  42.     {
  43.         if (pCurObj == pObj)    // Skip our self reaction
  44.             continue;
  45.         CReaction reaction = pCurObj->React (pObj);
  46.         uMaxExplosionIntensity = max (uMaxExplosionIntensity, 
  47.                                       reaction.GetExplosionIntensity ());
  48.         MaxTerrainDifficulty  = max (MaxTerrainDifficulty, 
  49.                                      reaction.GetTerrainDifficulty ());
  50.         bt = max (bt, reaction.GetBonusType());  
  51.         uMaxTankID = max (uMaxTankID, reaction.GetTankID());
  52.     }
  53.     return CReaction (uMaxExplosionIntensity,
  54.                       MaxTerrainDifficulty,
  55.                       bt,
  56.                       uMaxTankID);
  57. }
  58. /*------------------------------------------------------------------------------
  59.   Function: IsObjectValid
  60.   Purpose:  Check if the given pointer is still an active game object.
  61.   Input:    pObj - pointer to object in question.
  62.   Output:   Return TRUE if object is still active.
  63.   Remarks:  
  64. ------------------------------------------------------------------------------*/
  65. BOOL 
  66. CGameObjectsList::IsObjectValid (CGameObject *pObj)
  67. {
  68.     LIST_POS lp = GetHeadPosition();
  69.     for (CGameObject *p = GetNext(lp); p; p = GetNext(lp))
  70.         if (p == pObj)
  71.             return TRUE;
  72.     return FALSE;
  73. }