Example #1
0
    public Clickable GetRandomFreeCellToMove(Clickable clickable, List <Clickable> listClickable, int attempt)
    {
        Clickable cell = null;

        //   int maxCell = Mathf.Clamp(clickable.num + Alien.ClampDistance[attempt], 0, cells.Length - 1);
        //      int minCell = Mathf.Clamp(clickable.num - Alien.ClampDistance[attempt], 0, cells.Length - 1);



        //     List<int> tempArr = new List<int>();

        /*
         *      if (listClickable != null)
         *      {
         *          foreach (Clickable inListClickable in listClickable)
         *          {
         *              if (clickable.num != inListClickable.num && inListClickable.num >= minCell && inListClickable.num <= maxCell)
         *              {
         *                  tempArr.Add(inListClickable.num);
         *              }
         *          }
         *      }
         *
         *      else
         *      {*/

        List <Clickable> tempArrCl = GetClickableInArea(clickable, GameplayConstants.AlienMinDistance, GameplayConstants.AlienClampDistance[attempt]);

        // Debug.Log(tempArrCl.Count);

        /* for (int i = minCell; i <= maxCell; i++)
         * {
         *   if (clickable.num != i)
         *       tempArr.Add(i);
         * }*/
        //  }/*
        do
        {
            //   if (tempArr.Count == 0)
            //        break;

            if (tempArrCl.Count == 0)
            {
                break;
            }

            cell = tempArrCl[Random.Range(0, tempArrCl.Count)];

            tempArrCl.Remove(cell);

            /* int randomNum = Random.Range(0, tempArr.Count);
             * int num = tempArr[randomNum];
             *
             * cell = cells[num];
             *
             * tempArr.RemoveAt(randomNum);
             */
        } while (!cell.IsFreeForMove());

        if (cell == null && attempt < GameplayConstants.AlienClampDistance.Length - 1)
        {
            GetRandomFreeCellToMove(clickable, listClickable, ++attempt);
        }

        return(cell);
    }