コード例 #1
0
 void spawnNext()
 {
     if (robin.Count == 0)
     {
         //Add 3x the list amounts so that items are distributed nicely
         foreach (GameObject prefa in powerupPrefabs)
         {
             robin.Add(prefa);
         }
         ListUtil.Shuffle(robin);
     }
     if (this.transform.childCount < maxPowerupCount)
     {
         var prefa = robin[0];
         robin.RemoveAt(0);
         var go = Instantiate(prefa, this.transform);
         //Determine where to spawn.
         var deg = UnityEngine.Random.value * Mathf.PI * 2;
         var r   = UnityEngine.Random.value * spawnRadius;
         var xp  = Mathf.Cos(deg) * r;
         var zp  = Mathf.Sin(deg) * r;
         //Skip if hits something.
         if (Physics.OverlapSphere(new Vector3(xp, 60f, zp) + this.transform.position, 2f).Length > 0)
         {
             Debug.Log(Physics.OverlapSphere(go.transform.position, 10f).Length);
             Destroy(go);
         }
         else
         {
             go.transform.position = new Vector3(xp, 60f, zp);
         }
     }
     Invoke("spawnNext", UnityEngine.Random.value * (powerUpSpawnMaxDelay - powerUpSpawnMinDelay) + powerUpSpawnMinDelay);
 }
コード例 #2
0
    void AddElements(bool[,] grid)
    {
        List <Vector2> floors = new List <Vector2>();

        for (int i = 0; i < GetWidth(); i++)
        {
            for (int j = 0; j < GetHeight(); j++)
            {
                if (grid[i, j])
                {
                    floors.Add(new Vector2(i, j));
                }
            }
        }

        foreach (CaveElement ce in elements)
        {
            for (int i = 0; i < ce.limit; i++)
            {
                floors = ListUtil.Shuffle(floors);
                Vector2 f = floors[i];
                CreateElement(GetCell((int)f.x, (int)f.y), ce, (ce.prefab.name + "-" + i));
            }
        }
    }
コード例 #3
0
        /// <summary>
        /// 퀴즈 선택지 목록을 가져옵니다.
        /// </summary>
        /// <param name="quiz">퀴즈 객체</param>
        /// <param name="data">퀴즈 데이터 객체</param>
        /// <returns></returns>
        protected List <string> GetChoiceList(Quiz quiz, Quiz.Data data)
        {
            var  choiceList       = new List <string>();
            var  choiceCandidates = new List <string>();
            bool shouldRecalc;

            if (quiz.ChoiceCount > quiz.DataList.Count)
            {
                throw new ArgumentException($"객관식에서 퀴즈 선택지 수가 문항 수보다 많습니다. ({quiz.Type}-{quiz.MainSubject})");
            }

            choiceList.Add(data.Answer);
            if (quiz.ChoiceExtractMethod == Quiz.ChoiceExtractMethodOption.RICS)
            {
                for (int i = 0; i < quiz.ChoiceCount - 1; i++)
                {
                    string value = quiz.DataList[BotRandom.Next(quiz.DataList.Count)].Answer;
                    shouldRecalc = false;
                    for (int j = 0; j < choiceList.Count; j++)
                    {
                        if (choiceList[j] == value)
                        {
                            shouldRecalc = true; break;
                        }
                    }
                    if (shouldRecalc)
                    {
                        i--; continue;
                    }
                    choiceList.Add(value);
                }
            }
            else if (quiz.ChoiceExtractMethod == Quiz.ChoiceExtractMethodOption.RAPT)
            {
                for (int i = 0; i < quiz.DataList.Count; i++)
                {
                    if (quiz.DataList[i].Type == data.Type)
                    {
                        choiceCandidates.Add(quiz.DataList[i].Answer);
                    }
                }
                if (quiz.ChoiceCount > choiceCandidates.Count)
                {
                    throw new ArgumentException($"RAPT 객관식에서 퀴즈 선택지 수가 가능한 선택지 수보다 많습니다. ({quiz.Type}-{quiz.MainSubject})");
                }

                for (int i = 0; i < quiz.ChoiceCount - 1; i++)
                {
                    string value = choiceCandidates[BotRandom.Next(choiceCandidates.Count)];
                    shouldRecalc = false;
                    for (int j = 0; j < choiceList.Count; j++)
                    {
                        if (choiceList[j] == value)
                        {
                            shouldRecalc = true; break;
                        }
                    }
                    if (shouldRecalc)
                    {
                        i--; continue;
                    }
                    choiceList.Add(value);
                }
            }
            for (int i = 0; i < 3; i++)
            {
                ListUtil.Shuffle(choiceList);
            }

            return(choiceList);
        }
コード例 #4
0
        /// <summary>
        /// 퀴즈 데이터 목록을 얻어옵니다.
        /// </summary>
        /// <param name="requestedQuizType">요청된 퀴즈 유형</param>
        /// <param name="subjects">주제 목록</param>
        /// <param name="quizCount">퀴즈 개수</param>
        /// <returns>퀴즈 데이터 목록</returns>
        protected List <Quiz.Data> GetQuizDataList(Quiz.TypeOption requestedQuizType, string[] subjects, int quizCount)
        {
            var data2dList = new List <List <Quiz.Data> >();
            List <Quiz.Data> tempList;
            bool             matchesChildSubject;

            /* resultDataList 초기화 */
            for (int i = 0; i < subjects.Length; i++)
            {
                foreach (Quiz quiz in QuizList)
                {
                    if (quiz.Type == requestedQuizType)
                    {
                        string mainSubject = quiz.MainSubject;
                        if (mainSubject == subjects[i])
                        {
                            tempList = new List <Quiz.Data>();
                            for (int j = 0; j < quiz.DataList.Count; j++)
                            {
                                var data = quiz.DataList[j];
                                if (quiz.UseMultiChoice == true)
                                {
                                    data.Choices = GetChoiceList(quiz, data);
                                }
                                tempList.Add(data);
                            }
                            data2dList.Add(tempList);
                            break;
                        }
                        else
                        {
                            matchesChildSubject = false;
                            foreach (string childSubject in quiz.ChildSubjects)
                            {
                                if ($"{mainSubject}-{childSubject}" == subjects[i])
                                {
                                    tempList = new List <Quiz.Data>();
                                    for (int j = 0; j < quiz.DataList.Count; j++)
                                    {
                                        var data = quiz.DataList[j];
                                        if (data.ChildSubject == childSubject)
                                        {
                                            if (quiz.UseMultiChoice == true)
                                            {
                                                data.Choices = GetChoiceList(quiz, data);
                                            }
                                            tempList.Add(data);
                                        }
                                    }
                                    data2dList.Add(tempList);
                                    matchesChildSubject = true;
                                }
                            }
                            if (matchesChildSubject)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            /* data2dList Shuffle */
            int shuffleCount = 3;

            for (int i = 0; i < data2dList.Count; i++)
            {
                for (int j = 0; j < shuffleCount; j++)
                {
                    ListUtil.Shuffle(data2dList[i]);
                }
            }

            /* 배열 리스트, 문항 수 초기화 */
            List <Quiz.Data[]> dataArrList = new List <Quiz.Data[]>();
            int totalCount = 0;

            for (int i = 0; i < data2dList.Count; i++)
            {
                dataArrList.Add(new Quiz.Data[data2dList[i].Count]);
                totalCount += data2dList[i].Count;
            }
            if (totalCount > quizCount)
            {
                totalCount = quizCount;
            }

            /* 문제 선택 및 결과 리스트로 이동 */
            var resultDataList = new List <Quiz.Data>();

            for (int i = 0; i < totalCount; i++)
            {
                int randomValue = BotRandom.Next(dataArrList.Count);
                for (int j = 0; j < dataArrList[randomValue].Length; j++)
                {
                    if (dataArrList[randomValue][j] == null)
                    {
                        dataArrList[randomValue][j] = data2dList[randomValue][j];
                        resultDataList.Add(dataArrList[randomValue][j]);
                        break;
                    }
                    else if (j == dataArrList[randomValue].Length - 1)
                    {
                        i--;
                    }
                }
            }

            /* 결과 리스트 shuffle (리스트 내에서 다시 셔플) */
            for (int i = 0; i < shuffleCount; i++)
            {
                ListUtil.Shuffle(resultDataList);
            }

            return(resultDataList);
        }
コード例 #5
0
ファイル: SongList.cs プロジェクト: ZimCodes/MonoGameLibrary
 /// <summary>
 /// Shuffles the list of Songs
 /// </summary>
 public void shuffleSongs()
 {
     ListUtil.Shuffle(this.songs);
 }