Game.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "Game.h"
  2. #include <Bild.h>
  3. // Inhalt der Game Klasse aus Game.h
  4. // Konstruktor
  5. Game::Game()
  6. {
  7. schrift = 0;
  8. screen = 0;
  9. alpha = 0;
  10. menü = 0;
  11. ref = 1;
  12. }
  13. // Destruktor
  14. Game::~Game()
  15. {
  16. if( schrift )
  17. schrift->release();
  18. if( screen )
  19. screen->release();
  20. if( menü )
  21. menü->release();
  22. }
  23. // nicht constant
  24. bool Game::laden()
  25. {
  26. return 1;
  27. }
  28. void Game::doMausEreignis( MausEreignis &me )
  29. {
  30. if( menü )
  31. menü->doMausEreignis( me );
  32. }
  33. void Game::doTastaturEreignis( TastaturEreignis &te )
  34. {
  35. if( menü )
  36. menü->doTastaturEreignis( te );
  37. }
  38. bool Game::tick( double zeit )
  39. {
  40. int val = (int)( zeit * 150 );
  41. if( menü && !menü->istBeendet() && alpha != 255 )
  42. {
  43. alpha += val;
  44. if( alpha > 255 )
  45. alpha = 255;
  46. return 1;
  47. }
  48. if( menü && menü->istBeendet() && alpha )
  49. {
  50. alpha -= val;
  51. if( alpha < 255 )
  52. alpha = 0;
  53. }
  54. if( menü )
  55. return menü->tick( zeit );
  56. return 0;
  57. }
  58. void Game::render( Bild &zRObj )
  59. {
  60. zRObj.setAlpha( alpha );
  61. if( menü )
  62. menü->render( zRObj );
  63. zRObj.releaseAlpha();
  64. }
  65. void Game::setSchriftZ( Schrift *schrift )
  66. {
  67. this->schrift = schrift;
  68. if( !menü && this->schrift && screen )
  69. menü = new Menü( schrift, screen );
  70. }
  71. void Game::setBildschirmZ( Bildschirm *screen )
  72. {
  73. this->screen = screen;
  74. if( !menü && schrift && screen )
  75. menü = new Menü( schrift, screen );
  76. }
  77. // constant
  78. bool Game::istEnde() const
  79. {
  80. return menü ? ( menü->istBeendet() && !alpha ) : 0;
  81. }
  82. // Reference Counting
  83. MiniGameV *Game::getThis()
  84. {
  85. ref++;
  86. return this;
  87. }
  88. MiniGameV *Game::release()
  89. {
  90. ref--;
  91. if( !ref )
  92. delete this;
  93. return 0;
  94. }