Sfoglia il codice sorgente

Funktionalitet färdig, finns inget mål än (svara x frågor och vin).

Axel Nordh 7 anni fa
parent
commit
a272f24b7b

+ 8 - 3
Assets/Scripts/Draggable.cs

@@ -47,9 +47,15 @@ public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDra
             } else {
                 questionCardBefore = placeholderParent.GetChild(cardBefore).GetComponent<QuestionCard>();
                 if (questionCardBefore == null) {
-                    questionCardBefore = placeholderParent.GetChild(cardBefore - 1).GetComponent<QuestionCard>();
+                    if (cardBefore - 1 >= 0) {
+                        questionCardBefore = placeholderParent.GetChild(cardBefore - 1).GetComponent<QuestionCard>();
+                    }
+                }
+                if (questionCardBefore != null) {
+                    answerTextBefore = questionCardBefore.GetAnswerText().text;
+                } else {
+                    answerTextBefore = "Before";
                 }
-                answerTextBefore = questionCardBefore.GetAnswerText().text;
             }
 
             if (cardAfter >= placeholderParent.childCount) {
@@ -96,6 +102,5 @@ public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDra
         GetComponent<CanvasGroup>().blocksRaycasts = true;
 
         Destroy(placeholder);
-        // Destroy(this); fungerar ej här om man ångrar vart man släpper frågan, då går den ej att dra igen.
     }
 }

+ 0 - 4
Assets/Scripts/NewQuestion.cs

@@ -9,15 +9,11 @@ public class NewQuestion : QuestionCard {
         // Get question from server
         SetQuestionData();
     }
-
     
     public void SetQuestionData()
     {
         GetQuestion(false);
         SetAnswerText("???? - ????");
-
-        // For testing only, remove when done
-        SetQuestionText(GetQuestionText().text + " " + GetAnswerText().text);
     }
 
     private static NewQuestion instance;

+ 31 - 6
Assets/Scripts/ScrollViewScript.cs

@@ -3,6 +3,7 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.EventSystems;
+using UnityEngine.UI;
 
 public class ScrollViewScript : MonoBehaviour, IDropHandler {
     public GameObject prefab;
@@ -53,7 +54,6 @@ 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();
 
@@ -71,10 +71,13 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler {
                 dialog.SetOnAccept("Ja", () => {
                     dialog.Hide();
                     nq.SetQuestionData();
+                    SetQuestionsInAnswerLine();
                 }); // generera ny fråga
                 dialog.SetOnDecline("Nej", () => {
                     dialog.Hide();
                     SetAllQuestionsLocked();
+                    IncreaseRoundValue();
+                    SetQuestionsInAnswerLine();
                 }); // lås frågor som ej är låsta.
             } else {
                 dialog.SetTitle("Tyvärr fel svar, korrekt svar var " + nq.answerString);
@@ -82,6 +85,7 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler {
                 RemoveUnlockedQuestions();
                 dialog.SetOnAccept("Ok", () => dialog.Hide());
                 dialog.SetOnDecline("", () => dialog.Hide());
+                IncreaseRoundValue();
 
                 nq.SetQuestionData();
             }
@@ -93,26 +97,47 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler {
     }
 
     private void RemoveUnlockedQuestions() {
+        int lostQuestions = 0;
         for (int i = 0; i < contentPanel.childCount; i++) {
             QuestionCard q = contentPanel.GetChild(i).GetComponent<QuestionCard>();
             if (!q.IsQuestionSafe()) {
+                lostQuestions++;
                 Destroy(q.gameObject);
             }
         }
+        Text lostQuestionsValueText = GameObject.Find("Stats Value Lost").GetComponent<Text>();
+        lostQuestionsValueText.text = (Int16.Parse(lostQuestionsValueText.text) + lostQuestions).ToString();
+
+        SetQuestionsInAnswerLine(contentPanel.childCount - lostQuestions);
+    }
+
+    private void IncreaseRoundValue() {
+        Text roundTextValue = GameObject.Find("Stats Value Round").GetComponent<Text>();
+        roundTextValue.text = (Int16.Parse(roundTextValue.text) + 1).ToString();
+    }
+
+    private void SetQuestionsInAnswerLine() {
+        Text answerlineTextValue = GameObject.Find("Stats Value Inline").GetComponent<Text>();
+        answerlineTextValue.text = contentPanel.childCount.ToString();
+    }
+
+    private void SetQuestionsInAnswerLine(int answers) {
+        Text answerlineTextValue = GameObject.Find("Stats Value Inline").GetComponent<Text>();
+        answerlineTextValue.text = answers.ToString();
     }
 
-    // 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() {
 
         int correctAnswer = Int32.Parse(nq.answerString);
+        int currentChildCount = contentPanel.childCount;
         Transform questionBefore = null;
         Transform questionAfter = null;
-        try {
+        if (newQuestionSiblingIndex - 1 > 0) {
             questionBefore = contentPanel.GetChild(newQuestionSiblingIndex - 1);
-        } catch (UnityException e) { }
-        try {
+        }
+        if (newQuestionSiblingIndex < currentChildCount) {
             questionAfter = contentPanel.GetChild(newQuestionSiblingIndex);
-        } catch (UnityException e) { }
+        }
 
         QuestionCard test = contentPanel.GetChild(0).GetComponent<QuestionCard>();
         int answerBefore = -1;