Exemple #1
0
    //OLD
//	void Start() {
//		levels = new Levels_Data ();      //
//		Levels_Data data = Load2 ();      //
////
//		x = data.x;
//		for (int i = 0; i < buildCount; i++) {
//			levels.levels [i] = new Level_Data ();
//			levels.levels [i].total_Points = data.levels [i].total_Points;      //
//		}
////		print (levels.levels [0].total_Points);
//	}

    public void LoadFunction()
    {
        levels          = new Levels_Data();
        player          = new Player_Data();
        player.settings = new Settings();
        player.skins    = new bool[7];
        questions       = new Questions_Data();
        for (int i = 0; i < buildCount; i++)
        {
            levels.levels [i] = new Level_Data();
        }
        All_Data data = Load2();

        if (data != null)
        {
            player          = data.player;
            player.currency = player.total_points - player.boughtPrice;
            for (int i = 0; i < data.player.skins.Length; i++)
            {
                player.skins [i] = data.player.skins [i];
            }
            for (int i = 0; i < buildCount; i++)
            {
                levels.levels [i] = data.levels.levels [i];                      //
            }
//		print (data.custom_Questions);
            if (data.custom_Questions != null && data.custom_Questions.questions != null)
            {
                if (data.custom_Questions.questions.Count > 0)
                {
                    questions.questions = new List <Question_Data> (data.custom_Questions.questions);
                }
//			print ("Playing with new questions:   ");
            }
            else
            {
                if (CreateCustomQuestions.static_questions != null)
                {
                    List <QuestionObject> x = new List <QuestionObject> (CreateCustomQuestions.static_questions.CustomQuestions);
                    questions.questions = new List <Question_Data> ();
                    for (int i = 0; i < x.Count; i++)
                    {
                        Question_Data temp = x [i].CreateData(x [i]);
                        questions.questions.Add(temp);
                    }
                }
//			print ("Reset back to old questions:   ");
            }
        }
    }
    void ShowQuestion()
    {
        RemoveAnswerButtons();

        // Get the QuestionData for the current question
        Question_Data questionData = questionPool[questionIndex];

        //questionNumber.text = "Question: " + questionPool.Length.ToString();
        questionNumber.text = "Question: " + (questionPool.Length - questionIndex);

        /*
         * Debug.Log("====================" + "\n");
         * for (int i = 0; i < questionData._answers.Length; i++) {
         *  Debug.Log(i + " : " + questionData._answers[i]._answerText + " - " + questionData._answers[i]._isCorrect + "\n");
         * }
         * Debug.Log("====================" + "\n");
         */


        /*
         * Debug.Log(questionData._category + "\n");
         * Debug.Log("====================" + "\n");
         * questionCategory.text = "Category: " + questionData._category;
         *
         * Debug.Log(questionData._type + "\n");
         * Debug.Log("====================" + "\n");
         * questionType.text = "Type: " + questionData._type;
         *
         * Debug.Log(questionData._difficulty + "\n");
         * Debug.Log("====================" + "\n");
         * questionDifficulty.text = "Difficulty: " + questionData._difficulty;
         */

        // Update questionText with the correct text
        questionText.text = questionData._questionText;

        for (int i = 0; i < questionData._answers.Length; i++)                                                  // For every AnswerData in the current QuestionData...
        {
            GameObject answerButtonGameObject = answerButtonObjectPool.GetObject();                             // Spawn an AnswerButton from the object pool
            answerButtonGameObjects.Add(answerButtonGameObject);
            answerButtonGameObject.transform.SetParent(answerButtonParent);
            answerButtonGameObject.transform.localScale = Vector3.one;

            Answer_Button answerButton = answerButtonGameObject.GetComponent <Answer_Button>();
            answerButton.SetUp(questionData._answers[i]);                                                                               // Pass the AnswerData to the AnswerButton so the AnswerButton knows what text to display and whether it is the correct answer
        }
    }
Exemple #3
0
//	public void Save(){
//		BinaryFormatter bf = new BinaryFormatter ();
//		FileStream file = File.Create (Application.persistentDataPath + "/levelsInfo.dat");
//		Level_Data[] levels_Data = new Level_Data[buildCount];
//		CalculateExperience ();
//		for (int i = 0; i < SceneManager.sceneCountInBuildSettings - 1; i++) {
//			levels_Data [i] = new Level_Data ();
//			levels_Data [i].total_Points = levels [i].total_Points;
//			levels_Data [i].experience = levels [i].experience;
//		}
//		bf.Serialize (file, levels_Data);
//		file.Close ();
//	}
//
//	public void Load(){
//		if (File.Exists (Application.persistentDataPath + "/levelsInfo.dat")) {
//			BinaryFormatter bf = new BinaryFormatter ();
//			FileStream file = File.Open (Application.persistentDataPath + "/levelsInfo.dat", FileMode.Open);
//			Level_Data[] levels_Data = bf.Deserialize (file) as Level_Data[];
//			file.Close ();
//			for (int i = 0; i < SceneManager.sceneCountInBuildSettings - 1; i++) {
//				levels [i] = new Level_Data ();
////			levels_Data [currentSceneIndex] = new Level_Data ();
//				levels [i].total_Points = levels_Data [i].total_Points;
//				levels [i].experience = levels_Data [i].experience;
//			}
//		}
//	}

//	public void Save2(){
//		BinaryFormatter bf = new BinaryFormatter ();
//		FileStream file = File.Create (Application.persistentDataPath + "/test.dat");
//		Levels_Data levels_Data = new Levels_Data();     //
//		CalculateExperience ();
//		levels_Data.x = x + 40;     //
//		levels_Data.levels = new Level_Data[buildCount];     //
//		for (int i = 0; i < buildCount; i++) {     //
//			levels_Data.levels [i] = new Level_Data ();
//			levels_Data.levels [i].total_Points = levels.levels [i].total_Points;     //
//			levels_Data.levels [i].experience = levels.levels [i].experience;     //
//		}
//		bf.Serialize (file, levels_Data);     //
//		file.Close ();
//	}
//
//	public Levels_Data Load2(){
//		if (File.Exists (Application.persistentDataPath + "/test.dat")) {
//			BinaryFormatter bf = new BinaryFormatter ();
//			FileStream file = File.Open (Application.persistentDataPath + "/test.dat", FileMode.Open);
//			Levels_Data levels_Data = bf.Deserialize (file) as Levels_Data;     //
//			file.Close ();
//			return levels_Data;     //
////			levels = new Levels_Data ();
////			levels.levels = new Level_Data[buildCount];
////			levels.levels [0].total_Points = levels_Data.levels [0].total_Points;
////			levels.levels [0].experience = levels_Data.levels [0].experience;
//		} else {
//			Debug.LogError ("Cant find file in " + Application.persistentDataPath + "/test.dat");
//			return null;
//		}
//	}

    public void Save2()
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(Application.persistentDataPath + "/allData1111.dat");
        All_Data        data = new All_Data();

        data.levels          = new Levels_Data();
        data.player          = new Player_Data();
        data.player.settings = new Settings();
        data.player.skins    = new bool[7];
        data.player          = player;
        //Saves current questions by adding them all to a new list
//		print(CustomQuiz.custom_controller);
        if (CustomQuiz.custom_controller != null)
        {
            data.custom_Questions           = new Questions_Data();
            data.custom_Questions.questions = new List <Question_Data> ();
            List <QuestionObject> x = new List <QuestionObject> (CustomQuiz.custom_controller.CustomQuestions);
//		    List<QuestionObject> x = CustomQuiz.custom_controller.CustomQuestions;
            for (int i = 0; i < x.Count; i++)
            {
                Question_Data temp = x [i].CreateData(x [i]);
                data.custom_Questions.questions.Add(temp);
            }
        }
        else
        {
            data.custom_Questions = questions;
        }

        data.levels.levels = new Level_Data[buildCount];   //
        for (int i = 0; i < buildCount; i++)               //
        {
            data.levels.levels [i] = new Level_Data();
            data.levels.levels [i] = levels.levels [i];             //
        }
        CalculateExperience();
        bf.Serialize(file, data);              //
        file.Close();

        LoadFunction();
    }
 public void Restore(Question_Data data)
 {
     this.question     = data.question;
     this.correctAns   = data.correctAns;
     this.incorrectAns = data.incorrectAns;
 }
    private void HandleOnResponseReceived_Random(string response)
    {
        var fetchedData = new Opentdbcom_Class();

        JsonUtility.FromJsonOverwrite(response, fetchedData);

        /*
         * var i = 0;
         * foreach (var result in randomData.results) {
         *  Debug.Log("================" + i + "=============");
         *
         *  Debug.Log("CATEGORY: " + result.category + "\n"
         + "type: " + result.type + "\n"
         + "difficulty: " + result.difficulty + "\n"
         + "question: " + result.question + "\n"
         + "correct_answer: " + result.correct_answer + "\n");
         +
         +  Debug.Log("INCORRECT_ANSWERS: \n");
         +
         +  foreach (var item in result.incorrect_answers) {
         +      Debug.Log(item + "\n");
         +  }
         +
         +  Debug.Log("======================================");
         +
         +  i++;
         + }
         */

        var roundData = new Round_Data();

        roundData._name = Menu_Controller.instance.urlCategory;
        roundData._pointsAddedForCorrectAnswer = 10;
        roundData._timeLimitInSeconds          = Menu_Controller.instance.timeLimit;
        roundData._questions = new Question_Data[Menu_Controller.instance.urlNumberOfQuestions];
        int k = 0;

        foreach (var result in fetchedData.results)
        {
            // (m+1) - number of answers
            int m = 0;
            foreach (var ans in result.incorrect_answers)
            {
                m++;
            }

            // questionText and answers[] initialization
            var question = new Question_Data(result.category, result.type, result.difficulty, result.question, m + 1);

            // answers[] filling
            int j = 0;
            foreach (var ans in result.incorrect_answers)
            {
                var qaj = question._answers[j];
                qaj._answerText      = ans;
                qaj._isCorrect       = false;
                question._answers[j] = qaj;
                j++;
            }
            var qajPlus1 = question._answers[j];
            qajPlus1._answerText = result.correct_answer;
            qajPlus1._isCorrect  = true;
            question._answers[j] = qajPlus1;

            /*
             * //Debug.Log("QUESTION № " + roundData._questions.Length+1);
             * Debug.Log("BEFORE ORDER BY");
             * Debug.Log("====================" + "\n");
             * for (int i = 0; i < question._answers.Length; i++) {
             *  Debug.Log(i + " : " + question._answers[i]._answerText + " - " + question._answers[i]._isCorrect + "\n");
             * }
             * Debug.Log("====================" + "\n");
             */


            // Answer_Data[] answersWithRandomPos
            question._answers = question._answers.OrderBy(x => rnd.Next()).ToArray();

            /*
             * Debug.Log("AFTER ORDER BY");
             * Debug.Log("====================" + "\n");
             * for (int i = 0; i < question._answers.Length; i++) {
             *  Debug.Log(i + " : " + question._answers[i]._answerText + " - " + question._answers[i]._isCorrect + "\n");
             * }
             * Debug.Log("====================" + "\n");
             */


            // QuestionData = questionText + answers[]
            roundData._questions[k] = question;
            k++;
        }


        /*
         * var i = 0;
         * foreach (var question in roundData._questions) {
         *  Debug.Log("================" + i + "=============");
         *
         *  Debug.Log("CATEGORY: " + question._category + "\n"
         + "type: " + question._type + "\n"
         + "difficulty: " + question._difficulty + "\n"
         + "question: " + question._questionText + "\n");
         +
         +  Debug.Log("ANSWERS: \n");
         +
         +  foreach (var item in question._answers) {
         +      Debug.Log(item + "\n");
         +  }
         +
         +  Debug.Log("======================================");
         +
         +  i++;
         + }
         */



        allRoundData[0] = roundData;

        UnityEngine.SceneManagement.SceneManager.LoadScene("GameScene");
    }