Game.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "Game.h"
  2. #include <Bild.h>
  3. #include "../../../Include/KSGKlientV.h"
  4. // Inhalt der Game Klasse aus Game.h
  5. // Konstruktor
  6. Game::Game()
  7. {
  8. schrift = 0;
  9. screen = 0;
  10. alpha = 0;
  11. menü = 0;
  12. client = 0;
  13. ref = 1;
  14. }
  15. // Destruktor
  16. Game::~Game()
  17. {
  18. if( client )
  19. client->release();
  20. if( schrift )
  21. schrift->release();
  22. if( screen )
  23. screen->release();
  24. if( menü )
  25. menü->release();
  26. }
  27. // nicht constant
  28. bool Game::laden()
  29. {
  30. return 1;
  31. }
  32. void Game::setMinigameClientZ( MinigameKlientV *client )
  33. {
  34. if( this->client )
  35. this->client->release();
  36. this->client = client;
  37. }
  38. void Game::doMausEreignis( MausEreignis &me )
  39. {
  40. if( menü )
  41. menü->doMausEreignis( 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 *screen )
  82. {
  83. this->screen = screen;
  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. }