public void EnemyPoolTest()
        {
            // Retrieve an enemy and release it back to the pool
            var enemy = EnemyPool.Acquire();

            EnemyPool.Release(enemy);
            Assert.AreEqual(1, EnemyPool.Size);

            // Retrieve more enemies than the pool has to offer will
            // increase the size.
            for (int i = 0; i < 2; i++)
            {
                EnemyPool.Acquire();
            }
            Assert.AreEqual(2, EnemyPool.Size);
        }
Exemplo n.º 2
0
    void GenerateEnemies()
    {
        List <EnemyModel> enemyList = new List <EnemyModel>();

        for (int y = 0; y < _MatrixHeight; y++)
        {
            for (int x = 0; x < _MatrixDepth; x++)
            {
                var enemy = enemyPool.Acquire(new Vector2(startPos.x + x / 2, y + 0.5f));
                allEnemies[x, y] = enemy;
                enemy.gridX      = x;
                enemy.gridY      = y;
                enemyList.Add(enemy);
                enemy.tint = DefineColors((int)UnityEngine.Random.Range(0, 4));
                enemy.SetColor();
                enemy.transform.parent = containerObject.transform;
                enemy.AddObserver(containerObject.GetComponent <FormationHandler>());
                enemy.AddObserver(containerObject.GetComponent <ScoreManager>());
            }
        }

        foreach (var e in enemyList)
        {
            if (e.gridY - 1 >= 0)
            {
                e._enemyBot = allEnemies[e.gridX, e.gridY - 1];
            }
            if (e.gridY + 1 < _MatrixHeight)
            {
                e._enemyTop = allEnemies[e.gridX, e.gridY + 1];
            }
            if (e.gridX - 2 >= 0)
            {
                e._enemyLeft = allEnemies[e.gridX - 2, e.gridY];
            }
            if (e.gridX + 1 < _MatrixDepth)
            {
                e._enemyRight = allEnemies[e.gridX + 1, e.gridY];
            }
        }
    }