Game.cpp 1.8 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( screen )
  22. screen->release();
  23. if( menü )
  24. menü->release();
  25. }
  26. // nicht constant
  27. bool Game::laden()
  28. {
  29. return 1;
  30. }
  31. void Game::setMinigameClientZ( KSGClient::MinigameServerClient *client )
  32. {
  33. if( this->client )
  34. this->client->release();
  35. this->client = client;
  36. }
  37. void Game::setMinigameAPI( MinigameAPI *api )
  38. {
  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. this->schrift = schrift;
  80. if( !menü && this->schrift && screen )
  81. menü = new Menü( schrift, screen, client->getThis() );
  82. }
  83. void Game::setBildschirmZ( Bildschirm *screen )
  84. {
  85. this->screen = screen;
  86. if( !menü && schrift && screen )
  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. }