Advertisement
moinularif

lol

May 18th, 2015
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. using UnityEngine;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6.  
  7. public class QuestionHandler : MonoBehaviour
  8. {
  9.  
  10.     [System.Serializable]
  11.     public class Question
  12.     {
  13.         public string QuestionString;
  14.         public string[] Answers;
  15.         public string correctAnswer;
  16.         public bool IsItPictorial;
  17.         public Texture2D[] AnswersPictorial;
  18.         public Texture2D correctAnswerPictorial;
  19.     }
  20.     public List<Question> Internet_Questions = new List<Question>();
  21.     public List<Question> G_Science_Questions = new List<Question>();
  22.     public List<Question> General_Knowledge_Questions = new List<Question>();
  23.  
  24.     public List<Question> Chosen_Internet_Question = new List<Question>();
  25.     public List<Question> Chosen_G_science_Question = new List<Question>();
  26.     public List<Question> Chosen_General_knowledge_Question = new List<Question>();
  27.  
  28.     public Question CurrentQuestion = new Question();
  29.     public bool InternetQuestionFinished, GScienceQuestionFinished, GeneralKnowledgeQuestionFinished, HasGameOver;
  30.     public static QuestionHandler qHandle;
  31.  
  32.     void Start()
  33.     {
  34.  
  35.         if (CurrentQuestion.IsItPictorial) { Debug.Log("asdasdasd"); }
  36.         Chosen_Internet_Question = ChooseQuestion(Internet_Questions, 8);
  37.         Chosen_G_science_Question = ChooseQuestion(G_Science_Questions, 4);
  38.         Chosen_General_knowledge_Question = ChooseQuestion(General_Knowledge_Questions, 3);
  39.         qHandle = this;
  40.         InternetQuestionFinished = GScienceQuestionFinished = GeneralKnowledgeQuestionFinished = HasGameOver = false;
  41.         CurrentQuestion = Chosen_Internet_Question[0];
  42.  
  43.         GameManager.PlayerScore = 0;
  44.     }
  45.  
  46.     void Update()
  47.     {
  48.  
  49.     }
  50.  
  51.     void OnGUI()
  52.     {
  53.         //if (HasGameOver)
  54.         //{
  55.         //    if (GUI.Button(new Rect(200, 0, 250, 80), "gameover!"))
  56.         //    {
  57.  
  58.         //    }
  59.         //}
  60.  
  61.     }
  62.     public void QuestionUpdate()//run this when this question animation hide this question ui elements completely
  63.     {
  64.         Debug.Log("i am called.....");
  65.         if (!InternetQuestionFinished && !GScienceQuestionFinished && !GeneralKnowledgeQuestionFinished)
  66.         {
  67.             Chosen_Internet_Question.Remove(Chosen_Internet_Question[0]);
  68.             if (Chosen_Internet_Question.Count < 1)
  69.             { InternetQuestionFinished = true; GScienceQuestionFinished = false; GeneralKnowledgeQuestionFinished = false; CurrentQuestion = Chosen_G_science_Question[0]; }
  70.             else
  71.             {
  72.                 CurrentQuestion = Chosen_Internet_Question[0];
  73.             }
  74.             QuestionUIUpdate.questionUIUpdate.UpdateQuestionUIElements();
  75.         }
  76.         else if (InternetQuestionFinished && !GScienceQuestionFinished && !GeneralKnowledgeQuestionFinished)
  77.         {
  78.             Chosen_G_science_Question.Remove(Chosen_G_science_Question[0]);
  79.             if (Chosen_G_science_Question.Count < 1)
  80.             { InternetQuestionFinished = true; GScienceQuestionFinished = true; GeneralKnowledgeQuestionFinished = false; CurrentQuestion = Chosen_General_knowledge_Question[0]; }
  81.             else
  82.             {
  83.                 CurrentQuestion = Chosen_G_science_Question[0];
  84.             }
  85.             QuestionUIUpdate.questionUIUpdate.UpdateQuestionUIElements();
  86.         }
  87.         else if (InternetQuestionFinished && GScienceQuestionFinished && !GeneralKnowledgeQuestionFinished)
  88.         {
  89.             Chosen_General_knowledge_Question.Remove(Chosen_General_knowledge_Question[0]);
  90.             if (Chosen_General_knowledge_Question.Count < 1)
  91.             { InternetQuestionFinished = true; GScienceQuestionFinished = true; GeneralKnowledgeQuestionFinished = true; HasGameOver = true; UpdateLeaderBoard(); }
  92.             else
  93.             {
  94.                 CurrentQuestion = Chosen_General_knowledge_Question[0];
  95.             }
  96.             if (!HasGameOver)
  97.             {
  98.                 QuestionUIUpdate.questionUIUpdate.UpdateQuestionUIElements();
  99.             }
  100.             else
  101.             {
  102.                 Application.LoadLevel("LeaderBoardScene");
  103.             }
  104.  
  105.         }
  106.     }
  107.     List<Question> ChooseQuestion(List<Question> inputQuestion, int countNumber)
  108.     {
  109.         List<Question> tempQuestion = new List<Question>();
  110.         foreach (Question a in inputQuestion) { tempQuestion.Add(a); }
  111.         List<Question> chosenQuestion = new List<Question>();
  112.  
  113.         if (tempQuestion.Count == 0)
  114.         {
  115.             Debug.Log("List Empty");
  116.         }
  117.         else
  118.         {
  119.             for (int i = 0; i < countNumber; i++)
  120.             {
  121.                 int chosenIndex = Random.Range(0, tempQuestion.Count);
  122.                 chosenQuestion.Add(tempQuestion[chosenIndex]);
  123.                 tempQuestion.Remove(tempQuestion[chosenIndex]);
  124.  
  125.             }
  126.         }
  127.         return chosenQuestion;
  128.     }
  129.  
  130.     void UpdateLeaderBoard()
  131.     {
  132.         Debug.Log("update the leaderboard data.....");
  133.        // UpdateInfo(GameManager.PlayerName, GameManager.PlayerScore, GameManager.PlayerID);
  134.  
  135.     }
  136.  
  137.     public void UpdateInfo(string name, int score, long id, float timeScore)
  138.     {
  139.         // new player info
  140.         int newScore;
  141.         string newName;
  142.         string newid;
  143.         float newtimeScore;
  144.  
  145.         // old player info
  146.         int oldScore;
  147.         string oldName;
  148.         string oldid;
  149.         float oldtimeScore;
  150.  
  151.         newScore = score;
  152.         newName = name;
  153.         newid = id.ToString();
  154.         newtimeScore = timeScore;
  155.  
  156.         for (int i = 0; i < 10; i++)
  157.         {
  158.             if (PlayerPrefs.HasKey(i + "HScore"))
  159.             {
  160.                 if (PlayerPrefs.GetInt(i + "HScore") < newScore)
  161.                 {
  162.  
  163.                     if (PlayerPrefs.GetString(i + "HScoreID") == newid)
  164.                     {
  165.  
  166.                         oldScore = PlayerPrefs.GetInt(i + "HScore");
  167.                         oldName = PlayerPrefs.GetString(i + "HScoreName");
  168.                         oldid = PlayerPrefs.GetString(i + "HScoreID");
  169.                         oldtimeScore = PlayerPrefs.GetFloat(i + "HTimeScore");
  170.  
  171.  
  172.                         PlayerPrefs.SetInt(i + "HScore", newScore);
  173.                         PlayerPrefs.SetString(i + "HScoreName", newName);
  174.                         PlayerPrefs.SetString(i + "HScoreID", newid);
  175.                         PlayerPrefs.SetFloat(i + "HTimeScore", newtimeScore);
  176.  
  177.  
  178.                         newScore = 0;
  179.                         newName = "";
  180.                         newid = "";
  181.                         newtimeScore =0;
  182.                     }
  183.  
  184.                     else
  185.                     {
  186.                         oldScore = PlayerPrefs.GetInt(i + "HScore");
  187.                         oldName = PlayerPrefs.GetString(i + "HScoreName");
  188.                         oldid = PlayerPrefs.GetString(i + "HScoreID");
  189.                         oldtimeScore = PlayerPrefs.GetFloat(i + "HTimeScore");
  190.  
  191.  
  192.                         PlayerPrefs.SetInt(i + "HScore", newScore);
  193.                         PlayerPrefs.SetString(i + "HScoreName", newName);
  194.                         PlayerPrefs.SetString(i + "HScoreID", newid);
  195.                         PlayerPrefs.SetFloat(i + "HTimeScore", newtimeScore);
  196.  
  197.  
  198.                         newScore = oldScore;
  199.                         newName = oldName;
  200.                         newid = oldid;
  201.                         newtimeScore = oldtimeScore;
  202.                     }
  203.                 }
  204.  
  205.                 else if (PlayerPrefs.GetInt(i + "HScore") == newScore && PlayerPrefs.GetFloat(i + "HTimeScore") > newtimeScore)
  206.                 {
  207.  
  208.                     if (PlayerPrefs.GetString(i + "HScoreID") == newid)
  209.                     {
  210.  
  211.                         oldScore = PlayerPrefs.GetInt(i + "HScore");
  212.                         oldName = PlayerPrefs.GetString(i + "HScoreName");
  213.                         oldid = PlayerPrefs.GetString(i + "HScoreID");
  214.                         oldtimeScore = PlayerPrefs.GetFloat(i + "HTimeScore");
  215.  
  216.  
  217.                         PlayerPrefs.SetInt(i + "HScore", newScore);
  218.                         PlayerPrefs.SetString(i + "HScoreName", newName);
  219.                         PlayerPrefs.SetString(i + "HScoreID", newid);
  220.                         PlayerPrefs.SetFloat(i + "HTimeScore", newtimeScore);
  221.  
  222.  
  223.                         newScore = 0;
  224.                         newName = "";
  225.                         newid = "";
  226.                         newtimeScore = 0;
  227.                     }
  228.                     else
  229.                     {
  230.                         oldScore = PlayerPrefs.GetInt(i + "HScore");
  231.                         oldName = PlayerPrefs.GetString(i + "HScoreName");
  232.                         oldid = PlayerPrefs.GetString(i + "HScoreID");
  233.                         oldtimeScore = PlayerPrefs.GetFloat(i + "HTimeScore");
  234.  
  235.  
  236.                         PlayerPrefs.SetInt(i + "HScore", newScore);
  237.                         PlayerPrefs.SetString(i + "HScoreName", newName);
  238.                         PlayerPrefs.SetString(i + "HScoreID", newid);
  239.                         PlayerPrefs.SetFloat(i + "HTimeScore", newtimeScore);
  240.  
  241.  
  242.                         newScore = oldScore;
  243.                         newName = oldName;
  244.                         newid = oldid;
  245.                         newtimeScore = oldtimeScore;
  246.                     }
  247.                 }
  248.  
  249.             }
  250.             else
  251.             {
  252.                 PlayerPrefs.SetInt(i + "HScore", newScore);
  253.                 PlayerPrefs.SetString(i + "HScoreName", newName);
  254.                 PlayerPrefs.SetString(i + "HScoreID", newid);
  255.                 PlayerPrefs.SetFloat(i + "HTimeScore", newtimeScore);
  256.                 newScore = 0;
  257.                 newName = "";
  258.                 newid = "";
  259.                 newtimeScore = 0;
  260.             }
  261.         }
  262.     }
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement