Example #1
0
 void Update()
 {
     if (DistanceTracker.PlayerInRange && Input.GetKeyDown(KeyCode.Space))
     {
         ItemDistributor.Distribute();
     }
 }
        public int WriteBytesContinuoslyStartingFromBlock(byte[] bytes, int startingBlockIndex, int arrayOffset, int blockOffset)
        {
            // TODO: check args, revisit
            lock (_diskAccessCriticalSection)
            {
                ThrowIfDisposed();

                int numberOfBytesToWrite = bytes.Length - arrayOffset;
                int availableSpace       = ((this.NumberOfBlocks - startingBlockIndex) * this.BlockSizeInBytes) + (this.BlockSizeInBytes - blockOffset);

                if (numberOfBytesToWrite > availableSpace)
                {
                    // InsufficientSpaceException()
                    throw new ArgumentException();
                }

                var distribution = ItemDistributor.Distribute(numberOfBytesToWrite, this.BlockSizeInBytes - blockOffset, this.BlockSizeInBytes);

                int currentArrayOffset = 0;

                foreach (BucketDistribution bucketDistribution in distribution)
                {
                    this.WriteBytesToBlock(
                        startingBlockIndex + bucketDistribution.BucketIndex,
                        bytes,
                        currentArrayOffset,
                        bucketDistribution.IndexOfFirstItemTheBucketGot,
                        bucketDistribution.NumberOfItemsDistributed);

                    currentArrayOffset += bucketDistribution.NumberOfItemsDistributed;
                }

                return(distribution.Count);
            }
        }
Example #3
0
 public void EnsureDistributorThrowsIfFirstBucketIsSaidToContainMoreThanBucketCapacity()
 {
     ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>(
         delegate
     {
         ItemDistributor.Distribute(100, 100000, 1000);
     });
 }
Example #4
0
        public void TestDataSuite2()
        {
            ReadOnlyCollection <BucketDistribution> distributions = ItemDistributor.Distribute(1000, 0, 1000);

            List <BucketDistribution> expectedList = new List <BucketDistribution> {
                new BucketDistribution(1, 0, 1000)
            };

            CollectionAssert.AreEqual(expectedList, distributions);
        }
Example #5
0
        public void TestDataSuite3()
        {
            ReadOnlyCollection <BucketDistribution> distributions = ItemDistributor.Distribute(50, 5, 10);

            List <BucketDistribution> expectedList = new List <BucketDistribution>
            {
                new BucketDistribution(0, 5, 5),
                new BucketDistribution(1, 0, 10),
                new BucketDistribution(2, 0, 10),
                new BucketDistribution(3, 0, 10),
                new BucketDistribution(4, 0, 10),
                new BucketDistribution(5, 0, 5),
            };

            CollectionAssert.AreEqual(expectedList, distributions);
        }
Example #6
0
        public void EnsureDistributorThrowsIfAnyNumberPassedToItAsDistributionArgumentIsNegative()
        {
            ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentOutOfRangeException>(
                delegate
            {
                ItemDistributor.Distribute(-100, 10, 1000);
            });

            ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentOutOfRangeException>(
                delegate
            {
                ItemDistributor.Distribute(100, -10, 1000);
            });

            ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentOutOfRangeException>(
                delegate
            {
                ItemDistributor.Distribute(100, 10, -1000);
            });
        }
    private void NextItem()
    {
        if (closeObtained)
        {
            BoxItemPresenter.HideObtained();
            return;
        }

        if (currentShowedItemIndex > itemDatas.Length - 1)
        {
            BoxItemPresenter.ShowObtained();
            closeObtained = true;
        }
        else
        {
            ItemDistributor.AddItem(itemDatas[currentShowedItemIndex]);
        }

        currentShowedItemIndex++;
        BoxItemPresenter.SetRemaingValue(itemDatas.Length - currentShowedItemIndex);
    }
Example #8
0
    private void RoomsObjectCreator()
    {
        for (int i = 0; i < rooms.Count; i++)  //Не включает главную комнату (0)
        //Создаю все объекты, с которыми работаю более 1 раза за цикл
        {
            EnemyDistributor        EnDist   = EnemyDistributor[i].GetComponent <EnemyDistributor>();               //Стоит добавлять в каждую комнтату иначе съезжает порядок и будет ошибка выхода за пределы списка
            DestructibleDistributor DestDist = DestructibleDistributor[i].GetComponent <DestructibleDistributor>(); //Стоит добавлять в каждую комнтату иначе съезжает порядок и будет ошибка выхода за пределы списка
            ItemDistributor         ItemDist = ItemDistributor[i].GetComponent <ItemDistributor>();                 //Стоит добавлять в каждую комнтату иначе съезжает порядок и будет ошибка выхода за пределы списка
            AddRoom ARoom = rooms[i].GetComponent <AddRoom>();
            if (i != rooms.Count - 1 && i != 0)
            {
                //Создаю врагов
                int spawnEnemyAmount = Random.Range(8, 12);
                for (int k = 0; k < spawnEnemyAmount / 2 + 1; k++)  //Goblin Green
                {
                    EnDist.SpawnEnemy(EnemyList[0], ref ARoom);
                }
                for (int k = 0; k < spawnEnemyAmount / 2 - 1; k++)  //Goblin Brown
                {
                    EnDist.SpawnEnemy(EnemyList[1], ref ARoom);
                }

                //Создаю разрушаемые объекты
                DestructibleCreator(1, 5, ref DestructibleList, ref DestDist); // Случайное кол-во разрушаемых объектов от 1 до 4 (при 5 точках)
                ItemCreator(1, 4, ref ItemList, ref ItemDist);                 //Создаю вещи
                if (ARoom.deadEnd == true)                                     //rooms[i].GetComponent<AddRoom>().deadEnd
                {
                    if (spawnedChest != 0)
                    {
                        spawnedChest--;
                        //for (int k = 0; k < 10 ; k++){
                        int rand     = Random.Range(0, 100);
                        int chestNum = -1;
                        if (rand < 80)
                        {
                            keyType.Add(0); //Brown key
                            chestNum = 0;   //Brown chest
                        }
                        else if (rand < 95)
                        {
                            keyType.Add(1); //Green key
                            chestNum = 1;   //Green chest
                        }
                        else if (rand < 100)
                        {
                            keyType.Add(2); //Red key
                            chestNum = 2;   //Red chest
                        }
                        //Создаю Сундук
                        ItemDist.SpawnItem(ChestList[chestNum]);
                        //Меняю цвет комнаты
                        rooms[i].GetComponentInChildren <ItemMapOpen>().ChangeColor(new Vector3(255, 255, 0));
                    }
                    else if (spawnedChestGuardian != 0)
                    {
                        spawnedChestGuardian--;
                        int rand = Random.Range(0, keyType.Count);
                        EnDist.SpawnGuardian(ref EnemyGuardianList, 1, 0, keyType[rand]);
                        keyType.RemoveAt(rand);
                        rooms[i].GetComponentInChildren <ItemMapOpen>().ChangeColor(new Vector3(255, 193, 0));
                    }
                }
                //ARoom.EnvironmentSwitсher(false); // Отключаю окружающую среду
            }
            else if (i == 0)
            {
                ItemCreator(1, 4, ref ItemList, ref ItemDist);                 //Создаю вещи
                DestructibleList[1].chanceBeCreated += 200;                    // Увеличиваю вероятность создания бочки с водой
                DestructibleCreator(3, 6, ref DestructibleList, ref DestDist); //Создаю разрушаемые объекты
                DestructibleList[1].chanceBeCreated -= 200;                    // Возвращаю вероятность создания бочки с водой
            }
            else if (i == rooms.Count - 1)                                     //В последней комнате появится босс
            {
                spawnedBoss = true;                                            //Чтобы не появился 2-й босс
                EnDist.SpawnEnemy(boss, ref ARoom);
                ItemCreator(1, 3, ref ItemList, ref ItemDist);                 //Создаю вещи
                DestructibleCreator(1, 5, ref DestructibleList, ref DestDist); //Создаю разрушаемые объекты
                rooms[i].GetComponentInChildren <ItemMapOpen>().ChangeColor(new Vector3(1, 195, 195));
                //Создаю разрушаемые объекты
                //int destructibleAmount = Random.Range(2, 4); // Случайное кол-во разрушаемых объектов от 2 до 3 (при 5 точках)
                //for (int k = 0; k < destructibleAmount; k++) {
                //    GameObject newObj = CalculateChanceToCreate(DestructibleList);
                //    DestDist.SpawnDestructible(newObj);
                //}
                //ARoom.EnvironmentSwitсher(false); // Отключаю окружающую среду
            }
        }

        //Вызываем AStar после всех расстановок окружающей среды
        AStarScan();
    }
Example #9
0
    private void ItemCreator(int minRand, int maxRand, ref List <ObjectsStore> ItemList, ref ItemDistributor ItemDist)
    {
        int itemAmount = Random.Range(minRand, maxRand); // Случайное кол-во предметов от 1 до 5 (при 10 точках)

        for (int k = 0; k < itemAmount; k++)
        {
            GameObject newObj = CalculateChanceToCreate(ref ItemList);
            ItemDist.SpawnItem(newObj);
        }
    }
Example #10
0
        public byte[] ReadMap(out int bitmapSizeInBits)
        {
            byte[] firstBlockBytes = _disk.ReadAllBytesFromBlock(_freeSpaceMapStartingBlock);

            var stream       = new MemoryStream(firstBlockBytes);
            var binaryReader = new BinaryReader(stream);

            int freeSpaceLengthInBits = binaryReader.ReadInt32();

            int freeSpaceLengthInBytes = SpaceRequirementsCalculator.GetNumberOfChunksNeededToStoreData(
                freeSpaceLengthInBits, Constants.NumberOfBitsInByte);

            ReadOnlyCollection <BucketDistribution> numberOfBytesToReadFromEachBlock = ItemDistributor.Distribute(freeSpaceLengthInBytes,
                                                                                                                  _disk.BlockSizeInBytes - Constants.BlockReferenceSizeInBytes,
                                                                                                                  _disk.BlockSizeInBytes);

            var freeSpaceMap = new byte[freeSpaceLengthInBytes];

            int numberOfCurrentBlock = _freeSpaceMapStartingBlock;
            int initialArrayPosition = 0;

            foreach (BucketDistribution distribution in numberOfBytesToReadFromEachBlock)
            {
                byte[] newArray = _disk.ReadBytesFromBlock(numberOfCurrentBlock + distribution.BucketIndex, distribution.IndexOfFirstItemTheBucketGot,
                                                           distribution.NumberOfItemsDistributed);

                Array.Copy(newArray, 0, freeSpaceMap, initialArrayPosition, distribution.NumberOfItemsDistributed);
                initialArrayPosition += distribution.NumberOfItemsDistributed;
            }

            bitmapSizeInBits = freeSpaceLengthInBits;
            return(freeSpaceMap);
        }