예제 #1
0
    // Helper function for AddTowerToTowers()
    private void AddAllEnemiesInRowToTower(Tower tower, int rowNum)
    {
        LinkedList <GameObject>     row    = NavigateToRow(enemiesInRow, rowNum);
        LinkedListNode <GameObject> cursor = row.First;

        // Add every enemy in current cursor's row
        for (int i = 0; i < row.Count; i++)
        {
            tower.AddEnemyInList(cursor.Value);
            cursor = cursor.Next;
        }
    }
예제 #2
0
    // Helper functions for Adding/Removing enemies
    private void AddEnemyToTowers(GameObject e, int rowNum)
    {
        LinkedListNode <LinkedList <GameObject> > rowCursor = towers.First;

        for (int i = 0; i < towers.Count; i++)
        {
            LinkedList <GameObject>     row    = rowCursor.Value;
            LinkedListNode <GameObject> cursor = row.First;
            for (int j = 0; j < row.Count; j++)
            {
                Tower tower = cursor.Value.GetComponent <Tower>();

                // Single Lane Targetting & the enemy is in the right row
                if (tower.targeting == TargetingMode.singleLane && (tower.GetRowNum() == rowNum))
                {
                    tower.AddEnemyInList(e);
                } // Adjacent Lane Targetting & enemy is in above, same, or below row
                else if (tower.targeting == TargetingMode.tripleLanes)
                {
                    bool above = tower.GetRowNum() + 1 == rowNum;
                    bool same  = tower.GetRowNum() == rowNum;
                    bool below = tower.GetRowNum() - 1 == rowNum;
                    if (above || same || below)
                    {
                        tower.AddEnemyInList(e);
                    }
                } // All Lane Targetting
                else if (tower.targeting == TargetingMode.allLanes)
                {
                    tower.AddEnemyInList(e);
                }

                cursor = cursor.Next;
            }

            rowCursor = rowCursor.Next;
        }
    }
예제 #3
0
    private void AddTowerToTowers(GameObject tGO, int rowNum)
    {
        NavigateToRow(towers, rowNum).AddLast(tGO);

        Tower tower = tGO.GetComponent <Tower>();

        // Add enemies to this tower for -single lane targeting-
        if (tower.targeting == TargetingMode.singleLane)
        {
            AddAllEnemiesInRowToTower(tower, tower.GetRowNum());
        } // triple lane targeting
        else if (tower.targeting == TargetingMode.tripleLanes)
        {
            // Add the below row if possible
            if (tower.GetRowNum() - 1 >= 0)
            {
                AddAllEnemiesInRowToTower(tower, tower.GetRowNum() - 1);
            }

            // Add the same row
            AddAllEnemiesInRowToTower(tower, tower.GetRowNum());

            // Add the above row if possible
            if (tower.GetRowNum() + 1 < enemiesInRow.Count)
            {
                AddAllEnemiesInRowToTower(tower, tower.GetRowNum() + 1);
            }
        } // all lane targeting
        else if (tower.targeting == TargetingMode.allLanes)
        {
            LinkedListNode <LinkedList <GameObject> > rowNode = enemiesInRow.First;

            // Add enemies from every row
            for (int i = 0; i < enemiesInRow.Count; i++)
            {
                LinkedListNode <GameObject> cursor = rowNode.Value.First;
                // Add every enemy in current cursorInner's row
                for (int j = 0; j < rowNode.Value.Count; j++)
                {
                    tower.AddEnemyInList(cursor.Value);
                    cursor = cursor.Next;
                }
                rowNode = rowNode.Next;
            }
        }
    }