Game.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. 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. if( this->schrift )
  77. this->schrift->release();
  78. this->schrift = schrift;
  79. if( !menü && this->schrift && screen && client )
  80. menü = new Menü( schrift, screen, client->getThis() );
  81. }
  82. void Game::setBildschirmZ( Bildschirm *screen )
  83. {
  84. if( this->screen )
  85. this->screen->release();
  86. this->screen = screen;
  87. if( !menü && schrift && screen && client )
  88. menü = new Menü( schrift, screen, client->getThis() );
  89. }
  90. // constant
  91. bool Game::istEnde() const
  92. {
  93. return menü ? ( menü->istBeendet() && !alpha ) : 0;
  94. }
  95. // Reference Counting
  96. MiniGameV *Game::getThis()
  97. {
  98. ref++;
  99. return this;
  100. }
  101. MiniGameV *Game::release()
  102. {
  103. ref--;
  104. if( !ref )
  105. delete this;
  106. return 0;
  107. }