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

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   GameBoard.inl
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Contents: Inline functions implementations.
  11. *                                                                             
  12. *   Authors: Eran Yariv - 28484475                                           
  13. *            Moshe Zur  - 24070856                                           
  14. *                                                                            
  15. *                                                                            
  16. *   Date: 23/09/98                                                           
  17. *                                                                            
  18. ******************************************************************************/
  19. inline CGameBoard::CGameBoard () :
  20.     m_EmptyRect (0,0,0,0),
  21.     m_pMap (new BYTE[MAP_X_CELLS * MAP_Y_CELLS]),
  22.     m_bPrevDir (1)
  23. {
  24.     SetPos (0,0);
  25.     SetSize (MAP_WIDTH, MAP_HEIGHT);
  26. }
  27. inline CGameBoard::~CGameBoard ()
  28. {
  29.     delete [] m_pMap;
  30. }
  31. inline StateType 
  32. CGameBoard::CalcState (DWORD)
  33. {
  34.     return STATE_ALIVE;
  35. }
  36. inline CPoint &
  37. CGameBoard::GetPos()
  38. {
  39.     return m_Pos;
  40. }
  41. inline ObjectHeightType
  42. CGameBoard::GetHeight()
  43. {
  44.     return GROUND_LEVEL;
  45. }
  46. inline HIMAGE 
  47. CGameBoard::GetImage ()
  48. {
  49.     return m_hImage;
  50. }
  51. inline GameObjectType 
  52. CGameBoard::GetType ()
  53. {
  54.     return BOARD;
  55. }
  56. inline CRect &
  57. CGameBoard::GetUpdateRectangle()
  58. {
  59.     return m_EmptyRect;
  60. }
  61. inline CSize &
  62. CGameBoard::GetDimensions ()
  63. {
  64.     return m_Size;
  65. }
  66. inline TerrainType 
  67. CGameBoard::ReadMap (UINT x, UINT y)
  68. {
  69.     if (!InBoard(x, y))
  70.         return TERR_BLOCKED;
  71.     return (TerrainType)m_pMap[x + y * MAP_X_CELLS];
  72. }
  73. inline void 
  74. CGameBoard::WriteMap (UINT x, UINT y, TerrainType ter)
  75. {
  76.     ASSERT (InBoard(x, y) && ter <= TERR_BLOCKED);
  77.     m_pMap[x + y * MAP_X_CELLS] = BYTE(ter);
  78. }
  79. inline UINT 
  80. CGameBoard::Rand (UINT uMax)
  81. {   // Returns random number between 0..uMax-1
  82.     ASSERT (uMax < RAND_MAX);
  83.     return rand() % uMax;
  84. }
  85. inline UINT 
  86. CGameBoard::BlockSize (UINT uPixelSize)
  87. {
  88.     return ((uPixelSize % MAP_BLOCK_SCALE) == 0) ?
  89.            (uPixelSize / MAP_BLOCK_SCALE ) :
  90.            (1 + uPixelSize / MAP_BLOCK_SCALE);
  91. }            
  92. inline BOOL CGameBoard::InBoard (UINT x, UINT y)
  93. {
  94.     return (x < MAP_X_CELLS && y < MAP_Y_CELLS);
  95. }