Game.cpp 1.9 KB

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