Game.cpp 2.0 KB

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