Axel Nordh 7 лет назад
Родитель
Сommit
195581b0ae
1 измененных файлов с 35 добавлено и 14 удалено
  1. 35 14
      Assets/Scripts/ScrollViewScript.cs

+ 35 - 14
Assets/Scripts/ScrollViewScript.cs

@@ -33,11 +33,7 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler {
         if (d == null || !d.gameObject.name.Contains("NewQuestion")) {
             return;
         }
-
-
         // Popup modal asking are you sure here or at onDragEnd?
-
-
         nq = d.GetComponent<NewQuestion>();
         newQuestionSiblingIndex = d.placeholder.transform.GetSiblingIndex();
 
@@ -48,19 +44,44 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler {
         modalPanel.NewChoice(modalDetails);
     }
 
+    // kontrollera om man svarat korrekt, om det är korrekt, visa ny modal med vill du ha ny fråga? om fel, meddela det och avsluta omgång.
     void YesFunction() {
-        GameObject question = Instantiate(prefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
-        QuestionCard questionCard = question.GetComponent<QuestionCard>();
+        int correctAnswer = Int32.Parse(nq.answerString);
+        Transform questionBefore = null;
+        Transform questionAfter = null;
+        try {
+            questionBefore = contentPanel.GetChild(newQuestionSiblingIndex -1 );
+        } catch (UnityException e) { }
+        try {
+            questionAfter = contentPanel.GetChild(newQuestionSiblingIndex );
+        } catch (UnityException e) { }
 
-        questionCard.SetAnswerText(nq.answerString);
-        questionCard.SetQuestionText(nq.questionString);
-        questionCard.questionString = nq.questionString;
-        questionCard.answerString = nq.answerString;
-        questionCard.categoryString = nq.categoryString;
-        questionCard.idString = nq.idString;
+        QuestionCard test = contentPanel.GetChild(0).GetComponent<QuestionCard>();
+        int answerBefore = -1;
+        int answerAfter = 999999;
+        if (questionBefore != null) {
+            answerBefore = Int16.Parse(questionBefore.GetComponent<QuestionCard>().GetAnswerText().text);
+        }
+        if (questionAfter != null) {
+            answerAfter = Int16.Parse(questionAfter.GetComponent<QuestionCard>().GetAnswerText().text);
+        }
+        if (answerBefore <= correctAnswer && answerAfter >= correctAnswer) { // korrect svar, spara frågan i tidslinjen och prompta ny modal för "Vill du ha en fråga till?" med meddelande om vad som står på spel (olåsta frågor)
 
-        questionCard.transform.SetParent(contentPanel);
-        questionCard.transform.SetSiblingIndex(newQuestionSiblingIndex);
+            GameObject question = Instantiate(prefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
+            QuestionCard questionCard = question.GetComponent<QuestionCard>();
+
+            questionCard.SetAnswerText(nq.answerString);
+            questionCard.SetQuestionText(nq.questionString);
+            questionCard.questionString = nq.questionString;
+            questionCard.answerString = nq.answerString;
+            questionCard.categoryString = nq.categoryString;
+            questionCard.idString = nq.idString;
+
+            questionCard.transform.SetParent(contentPanel);
+            questionCard.transform.SetSiblingIndex(newQuestionSiblingIndex);
+        } else { // Visa modal för fel svar och meddela att man svarat fel och förlorat x olåsta frågor.
+
+        }
     }
 
     void NoFunction() {