Пример #1
0
 public override void Initialize()
 {
     base.Initialize();
     this.spriteDatabase   = SpritesheetDatabase.GetInstance;
     this.souvenirDatabase = SouvenirDatabase.GetInstance;
     AssignInstance(this);
     populateDogBreedLookup();
     setDogDataReferences();
     randomizer      = new RandomBuffer <DogDescriptor>(dogs);
     dailyRandomizer = new RandomDailyBuffer <DogDescriptor>(dogs);
 }
Пример #2
0
    public GiftEventData GetRandomGiftEvent()
    {
        RandomBuffer <GiftEventData> randomGiftEventBuffer = new RandomBuffer <GiftEventData>(giftEvents);

        while (randomGiftEventBuffer.HasNext())
        {
            GiftEventData targetGiftEvent = randomGiftEventBuffer.GetRandom();
            if (canUseEvent(targetGiftEvent))
            {
                return(targetGiftEvent);
            }
        }
        return(ArrayUtil.GetRandom(this.giftEvents));
    }
Пример #3
0
    // Excludes already adopted dogs
    protected DogDescriptor[] getDailyRandomDogListFromBuffer(
        RandomBuffer <DogDescriptor> buffer,
        int count,
        int startIndex = 0)
    {
        buffer.Refresh();
        DogDescriptor[] fullSequence = buffer.GetRandom(dogs.Length);
        DogDescriptor[] candidates   = ArrayUtil.GetRange(fullSequence, startIndex, count);
        // Allows for faster lookup versus O(n) to check array
        HashSet <DogDescriptor> currentCandidates = new HashSet <DogDescriptor>(candidates);
        // -1 for zero offset
        int currentIndex  = startIndex + count - ZERO_INDEX_OFFSET;
        int totalDogCount = fullSequence.Length;

        for (int i = 0; i < candidates.Length; i++)
        {
            while (currentIndex < totalDogCount && dataController.CheckIsAdopted(candidates[i]))
            {
                if (!dataController.CheckIsAdopted(fullSequence[currentIndex]))
                {
                    if (!currentCandidates.Contains(fullSequence[currentIndex]))
                    {
                        // Remove the old dog from the Hash (because it's invalid)
                        currentCandidates.Remove(candidates[i]);
                        candidates[i] = fullSequence[currentIndex];
                        // Update the Hash w/ the new dog
                        currentCandidates.Add(candidates[i]);
                    }
                }
                currentIndex++;
            }
            currentIndex++;
            if (currentIndex >= totalDogCount && dataController.CheckIsAdopted(candidates[i]))
            {
                candidates[i] = DogDescriptor.Default();
            }
        }
        return(candidates);
    }