Variablen.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #include "Variablen.h"
  2. #include "Gegenstand.h"
  3. bool operator==( VariableTyp a, VariableTyp b )
  4. {
  5. if( a == GAME_OBJEKT || b == GAME_OBJEKT )
  6. {
  7. return ( a == BARIERE || a == BASE || a == DROP || a == GEGENSTAND || a == GESCHOSS ||
  8. a == SCHALTER || a == SCHIENE || a == SPIELER || a == TIMER ||
  9. a == TUNNEL || a == UMLENKUNG || a == GAME_OBJEKT || a == ALLE ) &&
  10. ( b == BARIERE || b == BASE || b == DROP || b == GEGENSTAND || b == GESCHOSS ||
  11. b == SCHALTER || b == SCHIENE || b == SPIELER || b == TIMER || b == TUNNEL ||
  12. b == UMLENKUNG || b == GAME_OBJEKT || b == ALLE );
  13. }
  14. if( a == ALLE || b == ALLE )
  15. return 1;
  16. return (int)a == (int)b;
  17. }
  18. bool operator!=( VariableTyp a, VariableTyp b )
  19. {
  20. return !( a == b );
  21. }
  22. Variable::Variable( VariableTyp typ )
  23. {
  24. this->typ = typ;
  25. ref = 1;
  26. }
  27. Variable::~Variable()
  28. {}
  29. VariableTyp Variable::getVariableTyp() const
  30. {
  31. return typ;
  32. }
  33. Variable *Variable::getThis()
  34. {
  35. ref++;
  36. return this;
  37. }
  38. Variable *Variable::release()
  39. {
  40. if( !--ref )
  41. delete this;
  42. return 0;
  43. }
  44. bool isTrue( Variable *v )
  45. {
  46. if( !v )
  47. return 0;
  48. switch( v->getVariableTyp() )
  49. {
  50. case NICHTS:
  51. return 0;
  52. case INTEGER:
  53. return ( (Integer *)v )->getValue() != 0;
  54. case BOOLEAN:
  55. return ( (Boolean *)v )->getValue();
  56. case STRING:
  57. return ( (String *)v )->getValue().getLength();
  58. case FLOAT:
  59. return ( (Float *)v )->getValue() != 0;
  60. case TASTE:
  61. return ( (Integer *)v )->getValue() != 0;
  62. case GEGENSTAND_TYP:
  63. return ( (GegenstandTypVar *)v )->getValue() != KEIN_GEGENSTAND;
  64. default:
  65. return 1;
  66. }
  67. }
  68. Integer::Integer( int value, bool taste )
  69. : Variable( taste ? TASTE : INTEGER )
  70. {
  71. this->value = value;
  72. }
  73. void Integer::setValue( int value )
  74. {
  75. this->value = value;
  76. }
  77. int Integer::getValue() const
  78. {
  79. return value;
  80. }
  81. Boolean::Boolean( bool value )
  82. : Variable( BOOLEAN )
  83. {
  84. this->value = value;
  85. }
  86. void Boolean::setValue( bool value )
  87. {
  88. this->value = value;
  89. }
  90. bool Boolean::getValue() const
  91. {
  92. return value;
  93. }
  94. String::String( const char *value, bool richtung, bool geschossTyp )
  95. : Variable( richtung ? RICHTUNG : ( geschossTyp ? GESCHOSS_TYP : STRING ) )
  96. {
  97. this->value = value;
  98. }
  99. void String::setValue( Text value )
  100. {
  101. this->value = value;
  102. }
  103. const Text &String::getValue() const
  104. {
  105. return value;
  106. }
  107. Float::Float( float value )
  108. : Variable( FLOAT )
  109. {
  110. this->value = value;
  111. }
  112. void Float::setValue( float value )
  113. {
  114. this->value = value;
  115. }
  116. float Float::getValue() const
  117. {
  118. return value;
  119. }