Projekty z kursu Systemy operacyjne 2 na PWr
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "Brick.h"
  2. bool Brick::initialized = false;
  3. int Brick::xMax;
  4. int Brick::yMax;
  5. Brick::Brick(int xPosition, int descentRate)
  6. {
  7. //ctor
  8. this->xPosition = xPosition;
  9. this->yPosition = 0;
  10. this->descentRate = descentRate;
  11. this->falling = false;
  12. }
  13. Brick::~Brick()
  14. {
  15. //dtor
  16. }
  17. void Brick::initScene(int xRes, int yRes)
  18. {
  19. xMax = xRes;
  20. yMax = yRes;
  21. initialized = true;
  22. }
  23. int Brick::getxPosition()
  24. {
  25. return xPosition;
  26. }
  27. int Brick::getyPosition()
  28. {
  29. return yPosition;
  30. }
  31. bool Brick::isFalling()
  32. {
  33. return falling;
  34. }
  35. void Brick::fall()
  36. {
  37. if(initialized)
  38. {
  39. falling = true;
  40. while(yPosition < yMax - 2)
  41. {
  42. yPosition++;
  43. usleep(250000 - 10000 * descentRate);
  44. }
  45. }
  46. else
  47. {
  48. std::cout << "Scene size not initialized!" << std::endl;
  49. }
  50. }
  51. std::thread Brick::fallThread()
  52. {
  53. return std::thread(&Brick::fall, this);
  54. }