Пример #1
0
        /// <summary>
        /// 从当前学习中的所有单词列表中生成备选答案(当前学习的单词+2个混淆单词)
        /// </summary>
        private void RandomAnswersFromLearningWords(LearnWord[] wordsArray)
        {
            answers = new LearnWord[3];

            List <int> indexList = new List <int> {
                0, 1, 2
            };

            int questionWordIndex = Random.Range(0, indexList.Count);

            answers [questionWordIndex] = question;

            indexList.Remove(questionWordIndex);

            LearnWord confuseWord1 = GetConfuseWordFromArray(wordsArray, new LearnWord[] { question });

            int confuseWord1Index = indexList [Random.Range(0, indexList.Count)];

            answers [confuseWord1Index] = confuseWord1;

            indexList.Remove(confuseWord1Index);

            int confuseWord2Index = indexList [Random.Range(0, indexList.Count)];

            LearnWord confuseWord2 = GetConfuseWordFromArray(wordsArray, new LearnWord[] { question, confuseWord1 });

            answers [confuseWord2Index] = confuseWord2;

            this.correctAnswerIndex = questionWordIndex;
        }
        private void UpdateDataBase()
        {
            mySql.GetConnectionWith(CommonData.dataBaseName);

            mySql.BeginTransaction();

            for (int i = 0; i < singleLearnWordsCount; i++)
            {
                LearnWord word           = wordsToLearnArray [i];
                string    condition      = string.Format("wordId={0}", word.wordId);
                string    newLearnedTime = (word.learnedTimes).ToString();
                string    newUngraspTime = (word.ungraspTimes).ToString();

                // 更新数据库中当前背诵单词的背诵次数和背错次数
                mySql.UpdateValues(currentWordsTableName, new string[] { "learnedTimes", "ungraspTimes" }, new string[] {
                    newLearnedTime,
                    newUngraspTime
                }, new string[] {
                    condition
                }, true);
            }

            mySql.EndTransaction();

            mySql.CloseConnection(CommonData.dataBaseName);
        }
Пример #3
0
        /// <summary>
        /// 初始化测试数据
        /// </summary>
        /// <param name="question">Question.</param>
        /// <param name="answers">Answers.</param>
        /// <param name="correctAnswerIndex">Correct answer index.</param>
        /// <param name="examType">Exam type.</param>
        public Examination(LearnWord questionWord, LearnWord[] choiceWordsArray, ExaminationType examType)
        {
            this.question   = questionWord;
            this.wordsArray = choiceWordsArray;

            switch (examType)
            {
            case ExaminationType.EngToChn:
                examTypeList = new List <ExaminationType> {
                    ExaminationType.EngToChn
                };
                break;

            case ExaminationType.ChnToEng:
                examTypeList = new List <ExaminationType> {
                    ExaminationType.ChnToEng
                };
                break;

            case ExaminationType.Both:
                examTypeList = new List <ExaminationType> {
                    ExaminationType.EngToChn, ExaminationType.ChnToEng
                };
                break;
            }

            RandomAnswersFromLearningWords(choiceWordsArray);
        }
Пример #4
0
        /// <summary>
        /// 初始化已学习页
        /// </summary>
        /// <param name="learnInfo">Learn info.</param>
//		public void SetUpAllLearnedWords(){
//
//			wordsPlane.gameObject.SetActive (true);
//
//			List<LearnWord> allLearnedWords = learnInfo.GetAllLearnedWords ();
//
//			for (int i = 0; i < allLearnedWords.Count; i++) {
//
//				LearnWord word = allLearnedWords [i];
//
//				Transform wordItem = wordPool.GetInstance <Transform> (wordModel.gameObject, wordContainer);
//
//				wordItem.GetComponent<WordItemView> ().SetUpCellDetailView (word);
//
//			}
//
//		}

        /// <summary>
        /// 初始化未学习页
        /// </summary>
        /// <param name="learnInfo">Learn info.</param>
        public void SetUpAllUngraspedWords()
        {
            List <LearnWord> allUngraspedWords = learnInfo.GetAllUngraspedWords();

            wordPool.AddChildInstancesToPool(wordContainer);

            for (int i = 0; i < allUngraspedWords.Count; i++)
            {
                LearnWord word = allUngraspedWords [i];

                Transform wordItem = wordPool.GetInstance <Transform> (wordModel.gameObject, wordContainer);

                wordItem.GetComponent <WordItemView> ().SetUpCellDetailView(word);
            }

            generalInfoPlane.gameObject.SetActive(false);
            wordsPlane.gameObject.SetActive(true);

            wrongWordsTitle.GetComponent <Image> ().sprite        = selectedSprite;
            wrongWordsTitle.GetComponentInChildren <Text>().color = new Color(
                CommonData.selectedColor.x,
                CommonData.selectedColor.y,
                CommonData.selectedColor.z);
            recordTitle.GetComponent <Image> ().sprite        = normalSprite;
            recordTitle.GetComponentInChildren <Text>().color = new Color(
                CommonData.deselectedColor.x,
                CommonData.deselectedColor.y,
                CommonData.deselectedColor.z);

            GetComponent <Canvas> ().enabled = true;
        }
Пример #5
0
        /// <summary>
        /// 下载单词发音
        /// </summary>
        /// <returns>The pronunciation with WW.</returns>
        /// <param name="word">Word.</param>
        private WWW GetPronunciationWithWWW(LearnWord word)
        {
            string firstLetter = word.spell.Substring(0, 1);

            string url = string.Format("{0}/{1}/{2}.wav", pronunciationBaseURL, firstLetter, word.spell);

            return(new WWW(url));
        }
Пример #6
0
        /// <summary>
        /// 从缓存中读取单词发音
        /// </summary>
        /// <returns>The pronunciation from cache.</returns>
        /// <param name="word">Word.</param>
        private Pronunciation GetPronunciationFromCache(LearnWord word)
        {
            Pronunciation pro = pronunciationCache.Find(delegate(Pronunciation obj) {
                return(obj.word.wordId == word.wordId);
            });

            return(pro);
        }
        /// <summary>
        /// 直接从本次学习单词生成最终测试列表
        /// </summary>
        private void GenerateFinalExams(Examination.ExaminationType examType)
        {
            for (int i = 0; i < ungraspedWordsList.Count; i++)
            {
                LearnWord word = ungraspedWordsList [i];

                Examination finalExam = new Examination(word, wordsToLearnArray, examType);

                finalExaminationsList.Add(finalExam);
            }
        }
        /// <summary>
        /// 用户点击了不熟悉按钮
        /// </summary>
        public void OnUnfamiliarButtonClick()
        {
            // 将该单词移至未掌握单词列表的尾部
            LearnWord unfamiliarWord = currentLearningWord;

            ungraspedWordsList.RemoveAt(0);

            ungraspedWordsList.Add(unfamiliarWord);

            learnView.SetUpLearnViewWithWord(currentLearningWord);
        }
        /// <summary>
        /// 用户点击了发音按钮
        /// </summary>
        public void OnPronunciationButtonClick()
        {
            LearnWord word = currentLearningWord;

            if (word == null)
            {
                return;
            }

            GameManager.Instance.pronounceManager.PronounceWord(word);
        }
        private LearnWord GetWordFromWordsToLearnArrayWith(int wordId)
        {
            for (int i = 0; i < wordsToLearnArray.Length; i++)
            {
                LearnWord word = wordsToLearnArray [i];
                if (word.wordId == wordId)
                {
                    return(word);
                }
            }

            return(null);
        }
Пример #11
0
        public void SetUpLearnViewWithWord(LearnWord word)
        {
            questionText.text = word.spell;

            phoneticSymbolText.text = word.phoneticSymbol;

            explainationText.text = word.explaination;

            explainationText.enabled = false;

            ShowContainers(true, false, false, false);

            GetComponent <Canvas> ().enabled = true;
        }
Пример #12
0
        public override void SetUpCellDetailView(object data)
        {
            LearnWord word = data as LearnWord;

            spellText.text = word.spell;

            explainationText.text = word.explaination;

            pronounceButton.onClick.RemoveAllListeners();

            pronounceButton.onClick.AddListener(delegate {
                GameManager.Instance.pronounceManager.CancelPronounce();
                GameManager.Instance.pronounceManager.PronounceWord(word);
            });
        }
Пример #13
0
        /// <summary>
        /// 如果缓存中有单词发音,则直接发音,如果没有,则下载完成后发音
        /// </summary>
        /// <param name="word">Word.</param>
        public void PronounceWord(LearnWord word)
        {
            wordToPronounce = word;

            Pronunciation pro = GetPronunciationFromCache(word);

            if (pro == null)
            {
                pronunciationWWW            = GetPronunciationWithWWW(word);
                waitDownloadFinishCoroutine = PlayPronunciationWhenFinishDownloading(pronunciationWWW);
                StartCoroutine(waitDownloadFinishCoroutine);
            }
            else
            {
                SoundManager.Instance.PlayPronuncitaion(pro.pronunciation, false);
            }
        }
Пример #14
0
        private LearnWord GetConfuseWordFromArray(LearnWord[] wordsToLearnArray, LearnWord[] existWords)
        {
            LearnWord learnWord = null;

            int randomWordId = Random.Range(0, wordsToLearnArray.Length);

            learnWord = wordsToLearnArray [randomWordId];

            for (int i = 0; i < existWords.Length; i++)
            {
                if (learnWord.wordId == existWords [i].wordId)
                {
                    return(GetConfuseWordFromArray(wordsToLearnArray, existWords));
                }
            }

            return(learnWord);
        }
Пример #15
0
        public List <LearnWord> GetAllUngraspedWords()
        {
            List <LearnWord> ungraspWords = new List <LearnWord>();

            string tableName = GetCurrentLearningWordsTabelName();

            MySQLiteHelper sql = MySQLiteHelper.Instance;

            // 连接数据库
            sql.GetConnectionWith(CommonData.dataBaseName);

            string[] ungraspedCondition = new string[] { "ungraspTimes>0" };

            // 读取器
            IDataReader reader = sql.ReadSpecificRowsOfTable(tableName, null, ungraspedCondition, true);

            // 从表中读取数据
            while (reader.Read())
            {
                if (reader == null)
                {
                    return(null);
                }

                int    wordId         = reader.GetInt32(0);
                string spell          = reader.GetString(1);
                string explaination   = reader.GetString(2);
                string phoneticSymble = reader.GetString(3);
                string example        = reader.GetString(4);
                int    learnedTimes   = reader.GetInt16(5);
                int    ungraspTimes   = reader.GetInt16(6);

                LearnWord w = new LearnWord(wordId, spell, explaination, phoneticSymble, example, learnedTimes, ungraspTimes);

                ungraspWords.Add(w);
            }

            sql.CloseAllConnections();

            return(ungraspWords);
        }
        /// <summary>
        /// 用户点击了已掌握按钮
        /// </summary>
        public void OnHaveGraspedButtonClick()
        {
            GameManager.Instance.pronounceManager.CancelPronounce();

            // 使用当前学习中的单词(在这时已掌握)生成对应的单词测试
            Examination exam = new Examination(currentLearningWord, wordsToLearnArray, examType);

            // 单词测试加入到最终测试列表中
            finalExaminationsList.Add(exam);

            // 将当前学习中的单词从未掌握单词列表中删除
            LearnWord word = ungraspedWordsList[0];

            ungraspedWordsList.RemoveAt(0);
            graspedWordsList.Add(word);

            if (ungraspedWordsList.Count == 0)
            {
                GenerateFinalExams(examType);
            }

            learnView.SetUpLearnViewWithFinalExam(finalExaminationsList [0], examType);
        }
        /// <summary>
        /// 初始化本次要学习的单词数组
        /// </summary>
        private void InitWordsToLearn()
        {
            ungraspedWordsList.Clear();

            mySql = MySQLiteHelper.Instance;

            mySql.GetConnectionWith(CommonData.dataBaseName);

//			int totalLearnTimeCount = GameManager.Instance.gameDataCenter.learnInfo.totalLearnTimeCount;
//
//			int totalWordsCount = mySql.GetItemCountOfTable (CommonData.CET4Table,null,true);
//
//			// 大循环的次数
//			int bigCycleCount = totalLearnTimeCount * singleLearnWordsCount / (totalWordsCount * recycleLearnTimeBase);
//
//			currentWordsLearnedTime = totalLearnTimeCount % (recycleLearnTimeBase * recycleGroupBase) / recycleGroupBase + recycleLearnTimeBase * bigCycleCount;

            mySql.BeginTransaction();

            // 边界条件
            string[] condition = new string[] { "learnedTimes=0" };


            IDataReader reader = mySql.ReadSpecificRowsOfTable(currentWordsTableName, null, condition, true);


            // 从数据库中读取当前要学习的单词
            for (int i = 0; i < singleLearnWordsCount; i++)
            {
                reader.Read();

                if (reader == null)
                {
                    string[] colFields  = new string[] { "learnedTimes" };
                    string[] values     = new string[] { "0" };
                    string[] conditions = new string[] { "learnedTimes=1" };

                    mySql.UpdateValues(currentWordsTableName, colFields, values, conditions, true);

                    mySql.EndTransaction();

                    mySql.CloseAllConnections();

                    InitWordsToLearn();

                    return;
                }

                int wordId = reader.GetInt32(0);

                string spell = reader.GetString(1);

                string phoneticSymble = reader.GetString(2);

                string explaination = reader.GetString(3);

                string example = reader.GetString(4);

                int learnedTimes = reader.GetInt16(5);

                int ungraspTimes = reader.GetInt16(6);

                LearnWord word = new LearnWord(wordId, spell, phoneticSymble, explaination, example, learnedTimes, ungraspTimes);

                Debug.LogFormat("{0}---{1}次", word, learnedTimes);

                wordsToLearnArray [i] = word;
            }

            mySql.EndTransaction();

            mySql.CloseAllConnections();

            // 当前要学习的单词全部加入到未掌握单词列表中,用户选择掌握或者学习过该单词后从未掌握单词列表中移除
            for (int i = 0; i < wordsToLearnArray.Length; i++)
            {
                ungraspedWordsList.Add(wordsToLearnArray [i]);
            }

//			firstIdOfCurrentLearningWords = wordsToLearnArray [0].wordId;
        }
        /// <summary>
        /// 用户点击了最终测试界面中的答案选项卡
        /// </summary>
        public void OnAnswerChoiceButtonOfFinalExamsClick(LearnWord selectWord)
        {
            learnedWordCount++;

            learnView.UpdateLearningProgress(learnedWordCount, wordsToLearnArray.Length, true);

            // 如果选择正确,则将该单词的测试从测试列表中移除
            if (selectWord.wordId == currentExamination.question.wordId)
            {
                Debug.Log("选择正确");

                SoundManager.Instance.PlayAudioClip("UI/sfx_UI_RightTint");

                correctWordCount++;

                coinGain++;

                learnView.UpdateCrystalHarvest(coinGain);

                currentExamination.RemoveCurrentExamType();

                // 如果当前单词测试的所有测试类型都已经完成(根据设置,测试类型有 英译中,英译中+中译英)都已经完成,则从测试列表中删除该测试
                bool currentExamFinished = currentExamination.CheckCurrentExamFinished();
                if (currentExamFinished)
                {
                    currentExamination.question.learnedTimes++;
                    finalExaminationsList.RemoveAt(0);
                }
                else
                {
                    // 当前单词测试未完成
                    Examination exam = currentExamination;
                    finalExaminationsList.RemoveAt(0);
                    finalExaminationsList.Add(exam);
                }
            }
            else
            {
                // 如果选择错误
                Debug.Log("选择错误");

                SoundManager.Instance.PlayAudioClip("UI/sfx_UI_WrongTint");

                // 单词的背错次数+1
                GetWordFromWordsToLearnArrayWith(currentExamination.question.wordId).ungraspTimes++;

                // 当前测试加入到测试列表尾部
                Examination exam = currentExamination;

                finalExaminationsList.RemoveAt(0);

                if (addToTrailIfWrong)
                {
                    finalExaminationsList.Add(exam);
                    coinGain--;
                }

                learnView.ShowRightAnswerAndEnterNextExam(exam.correctAnswerIndex, currentExamination);
            }

            // 单词测试环节结束
            if (finalExaminationsList.Count <= 0)
            {
                learnView.ShowFinishLearningHUD(coinGain, correctWordCount);
            }
            else
            {
                // 测试环节还没有结束,则初始化下一个单词的测试
                Examination.ExaminationType examType = currentExamination.GetCurrentExamType();
                learnView.SetUpLearnViewWithFinalExam(currentExamination, examType);
            }
        }
Пример #19
0
 public Pronunciation(LearnWord word, AudioClip pronunciation)
 {
     this.word          = word;
     this.pronunciation = pronunciation;
 }
Пример #20
0
        private void MySetUpLearnViewWithFinalExam(Examination exam, Examination.ExaminationType examType)
        {
            totalTurnCount++;

            switch (examType)
            {
            case Examination.ExaminationType.EngToChn:

                questionText.text = exam.question.spell;

                phoneticSymbolText.text = exam.question.phoneticSymbol;

                phoneticSymbolText.enabled = true;

                for (int i = 0; i < choices.Length; i++)
                {
                    Button choiceButton = choices [i];

                    choiceButton.GetComponentInChildren <Text> ().color = Color.white;

                    LearnWord answer = exam.answers [i];

                    choiceButton.GetComponentInChildren <Text>().text = answer.explaination;

                    choiceButton.onClick.RemoveAllListeners();

//					int currentSelectChoiceIndex = i;

                    choiceButton.onClick.AddListener(delegate {
//						currentSelectChoice = choices[currentSelectChoiceIndex];
                        GetComponent <LearnViewController>().OnAnswerChoiceButtonOfFinalExamsClick(answer);
                    });
                }
                break;

            case Examination.ExaminationType.ChnToEng:

                questionText.text = exam.question.explaination;

                phoneticSymbolText.enabled = false;

                for (int i = 0; i < choices.Length; i++)
                {
                    Button choiceButton = choices [i];

                    LearnWord answer = exam.answers [i];

                    choiceButton.GetComponentInChildren <Text>().text = answer.spell;

                    choiceButton.onClick.RemoveAllListeners();

//					int currentSelectChoiceIndex = i;

                    choiceButton.onClick.AddListener(delegate {
//						currentSelectChoice = choices[currentSelectChoiceIndex];
                        GetComponent <LearnViewController>().OnAnswerChoiceButtonOfFinalExamsClick(answer);
                    });
                }
                break;
            }

            correctExplaination.text = exam.question.explaination;

            correctExplaination.enabled = false;

            ShowContainers(false, false, true, true);
        }