Game.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. bool Game::laden()
  26. {
  27. return 1;
  28. }
  29. void Game::setMinigameClientZ( KSGClient::MinigameServerClient *client )
  30. {
  31. if( this->client )
  32. this->client->release();
  33. this->client = client;
  34. }
  35. void Game::setMinigameAPI( MinigameAPI *api )
  36. {
  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. this->schrift = schrift;
  78. if( !menü && this->schrift && screen )
  79. menü = new Menü( schrift, screen, client->getThis() );
  80. }
  81. void Game::setBildschirmZ( Bildschirm *zScreen )
  82. {
  83. screen = zScreen;
  84. if( !menü && schrift && screen )
  85. menü = new Menü( schrift, screen, client->getThis() );
  86. }
  87. // constant
  88. bool Game::istEnde() const
  89. {
  90. return menü ? ( menü->istBeendet() && !alpha ) : 0;
  91. }
  92. // Reference Counting
  93. MiniGameV *Game::getThis()
  94. {
  95. ref++;
  96. return this;
  97. }
  98. MiniGameV *Game::release()
  99. {
  100. ref--;
  101. if( !ref )
  102. delete this;
  103. return 0;
  104. }