Game.cpp 1.8 KB

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