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

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   ManouverSet.cpp                                                            
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Module description: Each tank is assigned a Maneuver Set describing the user
  11. *                       key board input in terms of maneuvers - move forward, 
  12. *                       backward, turn etc. The maneuver set object resolve any 
  13. *                       conflicts that may occur when pressing keys that control
  14. *                       contradicting maneuvers, and is send over the net and
  15. *                       to the tanks or bomber objects.
  16. *                                                                             
  17. *   Authors: Eran Yariv - 28484475                                           
  18. *            Moshe Zur  - 24070856                                           
  19. *                                                                            
  20. *                                                                            
  21. *   Date: 23/09/98                                                           
  22. *                                                                            
  23. ******************************************************************************/
  24. #include "stdafx.h"
  25. #include "ManouverSet.h"
  26. const UINT CManouverSet::MOVE_COLLISION = FORWARD_MASK | BACKWARD_MASK;
  27. const UINT CManouverSet::TURN_COLLISION = TURN_RIGHT_MASK | TURN_LEFT_MASK;
  28. void 
  29. CManouverSet::SetBit (UINT ManouverBit)
  30. {
  31.     UINT uMask = (1 << ManouverBit) & MANOUVER_SET_MASK; // Calc mask, to set new val
  32.         // Check for turn key collisions:
  33.     if ( ((uMask | m_uManouverSet) & // Suppose we set the bit, does it collide ?
  34.             TURN_COLLISION) == TURN_COLLISION ) 
  35.     {
  36.         m_uManouverSet &= ~TURN_COLLISION;  // Clear both bits - conflict is settled
  37.         return;
  38.     } 
  39.         // Check for move key collisions:
  40.     if ( ((uMask | m_uManouverSet) & // Suppose we set the bit, does it collide ?
  41.             MOVE_COLLISION) == MOVE_COLLISION )
  42.     {
  43.         m_uManouverSet &= ~MOVE_COLLISION;  // Clear both bits - conflict is settled
  44.         return;
  45.     } 
  46.         // it's now safe to set bit:
  47.     m_uManouverSet |= uMask;
  48. }