| |
|
|
||||
![]() |
||||||
| |
|
|||||
|
Listing
3: // Class Implementation File for the Universe Class // (c) 1999 Guy W. Lecky-Thompson // All Rights Reserved Universe::Universe(unsigned long ulXDimension, unsigned long ulYDimension) { // Set the parameters for this universe this->ulXDimension = ulXDimension; this->ulYDimension = ulYDimension; // Initialise the randomizer this->prRandomizer = new PseudoRandomizer(ulXDimension, ulYDimension, ulXDimension * ulYDimension); } int Universe::StarAt(unsigned long ulXPosition, unsigned long ulYPosition, unsigned long ulSerialNumber) { unsigned long ulRandomValue;
// Set up the serial number for this grid reference ulSerialNumber = ((ulYPosition + 1) * this->ulXDimension) + ulXPosition);
for (unsigned long ulCounter = 0; ulCounter < ulSerialNumber; ulCounter++) { ulRandomValue = this->prRandomizer->PseudoRandom(); } // If ulRandomValue falls in the lower 1%, there is a star here if (ulRandomValue <= ((this->ulXDimension * this->ulYDimension) / 100)) return 1; return 0; } Unigen.h // Class Header File for the Universe Class // (c) 1999 Guy W. Lecky-Thompson // All Rights Reserved #include "prand.h" // The Class Definition for the random number generation class Universe { private: unsigned long ulXDimension, ulYDimension; // The 'size' of the Universe unsigned long ulUniverseSerialNumber; PseudoRandomizer * prRandomizer; public: Universe(unsigned long ulXDimension, unsigned long ulYDimension); int StarAt(unsigned long ulXPosition, unsigned long ulYPosition, unsigned long ulSerialNumber); };
|
|
|