Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class QuestionHandler : MonoBehaviour
- {
- [System.Serializable]
- public class Question
- {
- public string QuestionString;
- public string[] Answers;
- public string correctAnswer;
- public bool IsItPictorial;
- public Texture2D[] AnswersPictorial;
- public Texture2D correctAnswerPictorial;
- }
- public List<Question> Internet_Questions = new List<Question>();
- public List<Question> G_Science_Questions = new List<Question>();
- public List<Question> General_Knowledge_Questions = new List<Question>();
- public List<Question> Chosen_Internet_Question = new List<Question>();
- public List<Question> Chosen_G_science_Question = new List<Question>();
- public List<Question> Chosen_General_knowledge_Question = new List<Question>();
- public Question CurrentQuestion = new Question();
- public bool InternetQuestionFinished, GScienceQuestionFinished, GeneralKnowledgeQuestionFinished, HasGameOver;
- public static QuestionHandler qHandle;
- void Start()
- {
- if (CurrentQuestion.IsItPictorial) { Debug.Log("asdasdasd"); }
- Chosen_Internet_Question = ChooseQuestion(Internet_Questions, 8);
- Chosen_G_science_Question = ChooseQuestion(G_Science_Questions, 4);
- Chosen_General_knowledge_Question = ChooseQuestion(General_Knowledge_Questions, 3);
- qHandle = this;
- InternetQuestionFinished = GScienceQuestionFinished = GeneralKnowledgeQuestionFinished = HasGameOver = false;
- CurrentQuestion = Chosen_Internet_Question[0];
- GameManager.PlayerScore = 0;
- }
- void Update()
- {
- }
- void OnGUI()
- {
- //if (HasGameOver)
- //{
- // if (GUI.Button(new Rect(200, 0, 250, 80), "gameover!"))
- // {
- // }
- //}
- }
- public void QuestionUpdate()//run this when this question animation hide this question ui elements completely
- {
- Debug.Log("i am called.....");
- if (!InternetQuestionFinished && !GScienceQuestionFinished && !GeneralKnowledgeQuestionFinished)
- {
- Chosen_Internet_Question.Remove(Chosen_Internet_Question[0]);
- if (Chosen_Internet_Question.Count < 1)
- { InternetQuestionFinished = true; GScienceQuestionFinished = false; GeneralKnowledgeQuestionFinished = false; CurrentQuestion = Chosen_G_science_Question[0]; }
- else
- {
- CurrentQuestion = Chosen_Internet_Question[0];
- }
- QuestionUIUpdate.questionUIUpdate.UpdateQuestionUIElements();
- }
- else if (InternetQuestionFinished && !GScienceQuestionFinished && !GeneralKnowledgeQuestionFinished)
- {
- Chosen_G_science_Question.Remove(Chosen_G_science_Question[0]);
- if (Chosen_G_science_Question.Count < 1)
- { InternetQuestionFinished = true; GScienceQuestionFinished = true; GeneralKnowledgeQuestionFinished = false; CurrentQuestion = Chosen_General_knowledge_Question[0]; }
- else
- {
- CurrentQuestion = Chosen_G_science_Question[0];
- }
- QuestionUIUpdate.questionUIUpdate.UpdateQuestionUIElements();
- }
- else if (InternetQuestionFinished && GScienceQuestionFinished && !GeneralKnowledgeQuestionFinished)
- {
- Chosen_General_knowledge_Question.Remove(Chosen_General_knowledge_Question[0]);
- if (Chosen_General_knowledge_Question.Count < 1)
- { InternetQuestionFinished = true; GScienceQuestionFinished = true; GeneralKnowledgeQuestionFinished = true; HasGameOver = true; UpdateLeaderBoard(); }
- else
- {
- CurrentQuestion = Chosen_General_knowledge_Question[0];
- }
- if (!HasGameOver)
- {
- QuestionUIUpdate.questionUIUpdate.UpdateQuestionUIElements();
- }
- else
- {
- Application.LoadLevel("LeaderBoardScene");
- }
- }
- }
- List<Question> ChooseQuestion(List<Question> inputQuestion, int countNumber)
- {
- List<Question> tempQuestion = new List<Question>();
- foreach (Question a in inputQuestion) { tempQuestion.Add(a); }
- List<Question> chosenQuestion = new List<Question>();
- if (tempQuestion.Count == 0)
- {
- Debug.Log("List Empty");
- }
- else
- {
- for (int i = 0; i < countNumber; i++)
- {
- int chosenIndex = Random.Range(0, tempQuestion.Count);
- chosenQuestion.Add(tempQuestion[chosenIndex]);
- tempQuestion.Remove(tempQuestion[chosenIndex]);
- }
- }
- return chosenQuestion;
- }
- void UpdateLeaderBoard()
- {
- Debug.Log("update the leaderboard data.....");
- // UpdateInfo(GameManager.PlayerName, GameManager.PlayerScore, GameManager.PlayerID);
- }
- public void UpdateInfo(string name, int score, long id, float timeScore)
- {
- // new player info
- int newScore;
- string newName;
- string newid;
- float newtimeScore;
- // old player info
- int oldScore;
- string oldName;
- string oldid;
- float oldtimeScore;
- newScore = score;
- newName = name;
- newid = id.ToString();
- newtimeScore = timeScore;
- for (int i = 0; i < 10; i++)
- {
- if (PlayerPrefs.HasKey(i + "HScore"))
- {
- if (PlayerPrefs.GetInt(i + "HScore") < newScore)
- {
- if (PlayerPrefs.GetString(i + "HScoreID") == newid)
- {
- oldScore = PlayerPrefs.GetInt(i + "HScore");
- oldName = PlayerPrefs.GetString(i + "HScoreName");
- oldid = PlayerPrefs.GetString(i + "HScoreID");
- oldtimeScore = PlayerPrefs.GetFloat(i + "HTimeScore");
- PlayerPrefs.SetInt(i + "HScore", newScore);
- PlayerPrefs.SetString(i + "HScoreName", newName);
- PlayerPrefs.SetString(i + "HScoreID", newid);
- PlayerPrefs.SetFloat(i + "HTimeScore", newtimeScore);
- newScore = 0;
- newName = "";
- newid = "";
- newtimeScore =0;
- }
- else
- {
- oldScore = PlayerPrefs.GetInt(i + "HScore");
- oldName = PlayerPrefs.GetString(i + "HScoreName");
- oldid = PlayerPrefs.GetString(i + "HScoreID");
- oldtimeScore = PlayerPrefs.GetFloat(i + "HTimeScore");
- PlayerPrefs.SetInt(i + "HScore", newScore);
- PlayerPrefs.SetString(i + "HScoreName", newName);
- PlayerPrefs.SetString(i + "HScoreID", newid);
- PlayerPrefs.SetFloat(i + "HTimeScore", newtimeScore);
- newScore = oldScore;
- newName = oldName;
- newid = oldid;
- newtimeScore = oldtimeScore;
- }
- }
- else if (PlayerPrefs.GetInt(i + "HScore") == newScore && PlayerPrefs.GetFloat(i + "HTimeScore") > newtimeScore)
- {
- if (PlayerPrefs.GetString(i + "HScoreID") == newid)
- {
- oldScore = PlayerPrefs.GetInt(i + "HScore");
- oldName = PlayerPrefs.GetString(i + "HScoreName");
- oldid = PlayerPrefs.GetString(i + "HScoreID");
- oldtimeScore = PlayerPrefs.GetFloat(i + "HTimeScore");
- PlayerPrefs.SetInt(i + "HScore", newScore);
- PlayerPrefs.SetString(i + "HScoreName", newName);
- PlayerPrefs.SetString(i + "HScoreID", newid);
- PlayerPrefs.SetFloat(i + "HTimeScore", newtimeScore);
- newScore = 0;
- newName = "";
- newid = "";
- newtimeScore = 0;
- }
- else
- {
- oldScore = PlayerPrefs.GetInt(i + "HScore");
- oldName = PlayerPrefs.GetString(i + "HScoreName");
- oldid = PlayerPrefs.GetString(i + "HScoreID");
- oldtimeScore = PlayerPrefs.GetFloat(i + "HTimeScore");
- PlayerPrefs.SetInt(i + "HScore", newScore);
- PlayerPrefs.SetString(i + "HScoreName", newName);
- PlayerPrefs.SetString(i + "HScoreID", newid);
- PlayerPrefs.SetFloat(i + "HTimeScore", newtimeScore);
- newScore = oldScore;
- newName = oldName;
- newid = oldid;
- newtimeScore = oldtimeScore;
- }
- }
- }
- else
- {
- PlayerPrefs.SetInt(i + "HScore", newScore);
- PlayerPrefs.SetString(i + "HScoreName", newName);
- PlayerPrefs.SetString(i + "HScoreID", newid);
- PlayerPrefs.SetFloat(i + "HTimeScore", newtimeScore);
- newScore = 0;
- newName = "";
- newid = "";
- newtimeScore = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement