Game.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "Game.h"
  2. #include <Bild.h>
  3. // Inhalt der Game Klasse aus Game.h
  4. // Konstruktor
  5. Game::Game()
  6. : ReferenceCounter()
  7. {
  8. alpha = 0;
  9. menü = 0;
  10. client = 0;
  11. }
  12. // Destruktor
  13. Game::~Game()
  14. {
  15. if( client )
  16. client->release();
  17. if( menü )
  18. menü->release();
  19. }
  20. // nicht constant
  21. bool Game::laden()
  22. {
  23. return 1;
  24. }
  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. void Game::doPublicMausEreignis( MausEreignis &me )
  35. {
  36. if( menü )
  37. menü->doPublicMausEreignis( me );
  38. }
  39. void Game::doTastaturEreignis( TastaturEreignis &te )
  40. {
  41. if( menü )
  42. menü->doTastaturEreignis( te );
  43. }
  44. bool Game::tick( double zeit )
  45. {
  46. int val = (int)( zeit * 150 );
  47. if( menü && !menü->istBeendet() && alpha != 255 )
  48. {
  49. alpha += val;
  50. if( alpha > 255 )
  51. alpha = 255;
  52. return 1;
  53. }
  54. if( menü && menü->istBeendet() && alpha )
  55. {
  56. alpha -= val;
  57. if( alpha < 255 )
  58. alpha = 0;
  59. }
  60. if( menü )
  61. return menü->tick( zeit );
  62. return 0;
  63. }
  64. void Game::render( Bild &zRObj )
  65. {
  66. zRObj.setAlpha( alpha );
  67. if( menü )
  68. menü->render( zRObj );
  69. zRObj.releaseAlpha();
  70. }
  71. void Game::setUIFactory( UIInit &uiFactory )
  72. {
  73. this->uiFactory = uiFactory;
  74. if( !menü )
  75. menü = new Menü( uiFactory, dynamic_cast<KSGClient::MinigameServerClient *>( client->getThis() ) );
  76. }
  77. // constant
  78. bool Game::istEnde() const
  79. {
  80. return menü ? ( menü->istBeendet() && !alpha ) : 0;
  81. }