コード例 #1
0
//---------------------------------------------------------------------------
// Description: This method update the preview panel drawing the road with
//              the heigher intensity of pheromone in red
bool __fastcall Civilization::DrawPreviewBoard()
{
 // Scale factor
 const float Scale  = 0.25;
 const int   Radius = 5;
 City *mCity = NULL;

 for(int i=0; i<Roads->Count; i++)
  {
   ((Route*)Roads->Items[i])->DrawRoad(Preview,clBlue,Scale);
  }

 FindMainRoads(25,Preview,3,Scale);

 for(int i=0; i<Cities->Count; i++)
  {
   mCity = (City*)Cities->Items[i];

   int X = Scale*mCity->GetCityPositionX();
   int Y = Scale*mCity->GetCityPositionY() + 2;

   Preview->Canvas->Pen->Color =   clGreen;
   Preview->Canvas->Brush->Color =   clGreen;
   Preview->Canvas->Ellipse(X-Radius, Y-Radius, X+Radius, Y+Radius);//, X+Radius, Y+Radius, X+Radius, Y+Radius);
   Preview->Canvas->Brush->Color =   clWhite;
  }

 return true;
}
コード例 #2
0
//---------------------------------------------------------------------------
void Civilization::SaveToFile(FILE *stream)
{
 int n = Nest->GetCityName();
 fwrite(&n,sizeof(int),1,stream);
 n = FoodSourceCity->GetCityName();
 fwrite(&n,sizeof(int),1,stream);
 n = Cities->Count;
 fwrite(&n,sizeof(int),1,stream);
 City *nCity;
 for(int i=0; i<Cities->Count; i++)
  {
   nCity = (City*)Cities->Items[i];
   n = nCity->GetCityPositionX();
   fwrite(&n,sizeof(int),1,stream);
   n = nCity->GetCityPositionY();
   fwrite(&n,sizeof(int),1,stream);
  }
 n = Roads->Count;
 fwrite(&n,sizeof(int),1,stream);
 Route *nRoad;
 for(int i=0; i<Roads->Count; i++)
  {
   nRoad = (Route*)Roads->Items[i];

   n = nRoad->GetCityName(1);
   fwrite(&n,sizeof(int),1,stream);
   n = nRoad->GetCityName(2);
   fwrite(&n,sizeof(int),1,stream);
  }
}