瀏覽代碼

Base fertig

Kolja Strohm 5 年之前
父節點
當前提交
f0c1c6cd6c

+ 6 - 2
StickmanWorldOnline/Bariere.cpp

@@ -17,7 +17,8 @@ Bariere::Bariere( int id, int x, int y, int breite, int height, int style, int v
 
 Bariere::~Bariere()
 {
-    team->release();
+    if( team )
+        team->release();
 }
 
 void Bariere::setStyle( int style, bool add )
@@ -56,7 +57,8 @@ void Bariere::startAutoSchaltung()
 
 void Bariere::setTeam( Team *team )
 {
-    this->team->release();
+    if( this->team )
+        this->team->release();
     this->team = team;
 }
 
@@ -117,6 +119,8 @@ int Bariere::getSchaltungAnzahl() const
 
 Team *Bariere::getTeam() const
 {
+    if( !team )
+        return 0;
     return (Team*)team->getThis();
 }
 

+ 87 - 0
StickmanWorldOnline/Base.cpp

@@ -0,0 +1,87 @@
+#include "Base.h"
+#include "Spiel.h"
+#include "Ereignis.h"
+
+
+Base::Base( int id, int x, int y, int width, int height, int maxTime, Team *team )
+    : GameObject( x, y, width, height )
+{
+    this->id = id;
+    this->maxTime = maxTime;
+    this->team = team;
+    inChange = 0;
+    nextTeam = 0;
+    leftTime = (float)maxTime;
+}
+
+Base::~Base()
+{
+    if( team )
+        team->release();
+    if( nextTeam )
+        nextTeam->release();
+}
+
+void Base::setTeam( Team *team )
+{
+    if( this->team )
+        this->team->release();
+    this->team = team;
+}
+
+void Base::startChange( Team *team )
+{
+    if( team == this->team )
+    {
+        inChange = 0;
+        if( nextTeam )
+            nextTeam = (Team*)nextTeam->release();
+        team->release();
+        return;
+    }
+    else if( this->team )
+    {
+        if( nextTeam )
+            nextTeam = (Team *)nextTeam->release();
+        leftTime = (float)maxTime;
+        inChange = 1;
+        team->release();
+    }
+    else
+    {
+        if( nextTeam )
+            nextTeam = (Team *)nextTeam->release();
+        nextTeam = team;
+        leftTime = (float)maxTime;
+        inChange = 1;
+    }
+}
+
+void Base::tick( double time, Spiel *zSpiel )
+{
+    if( inChange )
+    {
+        leftTime -= (float)time;
+        if( leftTime <= 0 )
+        {
+            Ereignis *e = new Ereignis( BASIS_BESITZERWECHSEL );
+            e->addParameter( "Betroffene Basis", getThis() );
+            e->addParameter( "Vorheriges Team", team ? team->getThis() : new Variable( NICHTS ) );
+            e->addParameter( "Nächstes Team", nextTeam ? nextTeam->getThis() : new Variable( NICHTS ) );
+            zSpiel->throwEvent( e );
+            this->team->release();
+            this->team = nextTeam;
+            inChange = 0;
+        }
+    }
+}
+
+Team *Base::getTeam() const
+{
+    return team ? (Team*)team->getThis() : 0;
+}
+
+Team *Base::zTeam() const
+{
+    return team;
+}

+ 1 - 1
StickmanWorldOnline/Base.h

@@ -19,8 +19,8 @@ public:
     Base( int id, int x, int y, int width, int height, int maxTime = 10, Team *team = 0 );
     ~Base();
     void setTeam( Team *team );
-    void tick( double time, Spiel *zSpiel );
     void startChange( Team *team );
+    void tick( double time, Spiel *zSpiel );
     Team *getTeam() const;
     Team *zTeam() const;
 };

+ 1 - 1
StickmanWorldOnline/Ereignis.h

@@ -10,7 +10,7 @@ enum EreignisTyp
     AUSLOESER_RUNNED, // "Betroffener Auslöser"
     BARIERE_SWITCHED,
     BARIERE_WIRD_VERSCHOBEN,
-    BASIS_BESITZERWECHSEL,
+    BASIS_BESITZERWECHSEL, // "Betroffene Basis", "Vorheriges Team", "Nächstes Team"
     GEGENSTAND_ERSCHEINT,
     INITIALISIERUNG, //
     SCHALTER_AKTIVIERT, // "Betroffener Schalter"

+ 1 - 0
StickmanWorldOnline/StickmanWorldOnline.vcxproj

@@ -78,6 +78,7 @@
   </PropertyGroup>
   <ItemGroup>
     <ClCompile Include="Bariere.cpp" />
+    <ClCompile Include="Base.cpp" />
     <ClCompile Include="DllStart.cpp" />
     <ClCompile Include="Reader.cpp" />
     <ClCompile Include="Spiel.cpp" />

+ 3 - 0
StickmanWorldOnline/StickmanWorldOnline.vcxproj.filters

@@ -54,6 +54,9 @@
     <ClCompile Include="Bariere.cpp">
       <Filter>Spiel\Objekte</Filter>
     </ClCompile>
+    <ClCompile Include="Base.cpp">
+      <Filter>Spiel\Objekte</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="SpielKlasse.h">