Пример #1
0
    /// <summary>
    /// Gets distractors.
    /// These are wrong answers which can be presented as options to the player.
    /// </summary>
    /// <returns>The distractors.</returns>
    /// <param name="howManyDistractors">How many random distractors to return.</param>
    public ProblemPart[] GetDistractors(int howManyDistractors)
    {
        int availableDistractors = protobufsProblemData.distractor.distractors.Count;

        if (availableDistractors < howManyDistractors)
        {
            throw new Exception("There aren't enough distractors!  There are only "
                                + availableDistractors + " distractors.");
        }

        ArrayList allDistractors = new ArrayList();

        for (int i = 0; i < availableDistractors; i++)
        {
            Senseix.Message.Atom.Atom distractorAtom = protobufsProblemData.distractor.distractors[i];
            ProblemPart distractor = ProblemPart.CreateProblemPart(distractorAtom);
            allDistractors.Add(distractor);
        }         //find all the distractors

        ProblemPart[] resultDistractors = new ProblemPart[howManyDistractors];
        for (int i = 0; i < howManyDistractors; i++)
        {
            int randomDistractorIndex = UnityEngine.Random.Range(0, allDistractors.Count);
            resultDistractors[i] = (ProblemPart)allDistractors[randomDistractorIndex];
            allDistractors.RemoveAt(randomDistractorIndex);
        }         //take random ones

        return(resultDistractors);
    }
Пример #2
0
 public System.Collections.IEnumerator GetEnumerator()
 {
     foreach (Senseix.Message.Atom.Atom atom in atomList)
     {
         yield return(ProblemPart.CreateProblemPart(atom));
     }
 }
Пример #3
0
 /// <summary>
 /// Build an answer from a message received from the Thinksy server.  For internal use within the Thinksy plugin.
 /// </summary>
 public Answer(Senseix.Message.Problem.Answer protoAnswer)
 {
     foreach (Senseix.Message.Atom.Atom atom in protoAnswer.answers)
     {
         answerParts.Add(ProblemPart.CreateProblemPart(atom));
     }
 }
Пример #4
0
    private void UpdateAnswers()
    {
        availableAnswers.Clear();
        ProblemPart[] wrongAnswers = new ProblemPart[answerButtonTexts.Length - 1];

        if (ThinksyPlugin.GetMostRecentProblem().CountDistractors() >= wrongAnswers.Length)
        {
            wrongAnswers = ThinksyPlugin.GetMostRecentProblem().GetDistractors(wrongAnswers.Length);
        }
        else
        {
            for (int i = 0; i < wrongAnswers.Length; i++)
            {
                wrongAnswers [i] = ThinksyPlugin.GetMostRecentProblem().GetDistractor();
            }
        }

        foreach (ProblemPart wrongAnswer in wrongAnswers)
        {         //add the number of buttons minus one wrong answers
            availableAnswers.Add(wrongAnswer);
        }
        availableAnswers.Add(ThinksyPlugin.GetMostRecentProblem().GetCurrentCorrectAnswerPart());
        //add the one right answer

        Shuffle(availableAnswers);
    }
Пример #5
0
        static public bool ParseGetEncouragementsResponse(byte[] responseBytes)
        {
            Encouragement.EncouragementGetResponse getEncouragementResponse =
                Deserialize(responseBytes, typeof(Encouragement.EncouragementGetResponse)) as Encouragement.EncouragementGetResponse;

            Logger.BasicLog("I got an encouragement get response with " + getEncouragementResponse.encouragement_data.Count + " encouragements.");

            foreach (Encouragement.EncouragementData encouragementData in getEncouragementResponse.encouragement_data)
            {
                ProblemPart[] encouragementParts = new ProblemPart[encouragementData.encouragement_atoms.Count];
                for (int i = 0; i < encouragementParts.Length; i++)
                {
                    encouragementParts[i] = ProblemPart.CreateProblemPart(encouragementData.encouragement_atoms[i]);
                }
                ThinksyEvents.InvokeEncouragementReceived(encouragementParts);
            }

            ThinksyPlugin.NewHeartbeatTiming(getEncouragementResponse.frames_per_heartbeat);
            if (getEncouragementResponse.force_pull)
            {
                ProblemKeeper.PullNewProblems();
            }

            return(true);
        }
 public ProblemPart GetLearningActionPartByIndex(int index)
 {
     if (index < 0 || index > GetProto().atoms.Count)
     {
         throw new Exception("That is out of range.  There are " + GetProto().atoms.Count + " problem parts.");
     }
     return(ProblemPart.CreateProblemPart(GetProto().atoms[index]));
 }
Пример #7
0
 public void InstanceSetItemsToDisplay(ProblemPart[] items)
 {
     itemSpritesToDisplay = new Sprite[items.Length];
     for (int i = 0; i < items.Length; i++)
     {
         itemSpritesToDisplay[i] = items[i].GetSprite();
     }
     currentPageNumber = 0;
     UpdateDisplay ();
 }
Пример #8
0
 /// <summary>
 /// Questions can be represented as a series of ProblemParts
 /// which contain information to communicate the problem.
 /// This gets the question part at the given index.
 /// You can also iterate through a question using foreach
 /// </summary>
 public ProblemPart GetQuestionPart(int index)
 {
     try
     {
         return(ProblemPart.CreateProblemPart(atomList[index]));
     }
     catch
     {
         throw new Exception("Question part index out of range");
     }
 }
 private void EnqueueEmoticons(ProblemPart[] possibleEmoticons)
 {
     Debug.Log ("I received " + possibleEmoticons.Length + " possible emoticons.");
     foreach(ProblemPart possibleEmoticon in possibleEmoticons)
     {
         if (possibleEmoticon.HasSprite())
         {
             spritesToShowOff.Enqueue (possibleEmoticon.GetSprite());
         }
     }
     Debug.Log ("Emoticon Queue length now " + CountEmoticonsWaiting ().ToString ());
 }
Пример #10
0
    /// <summary>
    /// Gets the next correct answer part based on how many answer parts have been
    /// given so far.
    /// </summary>
    /// <returns>The next correct answer part.</returns>
    public ProblemPart GetCurrentCorrectAnswerPart()
    {
        int answersGivenSoFar = givenAnswer.AnswerPartsCount();

        if (answersGivenSoFar >= GetCorrectAnswer().AnswerPartsCount())
        {
            throw new Exception("There is no next correct answer part- all answer parts have already been given!");
        }
        ProblemPart nextCorrectAnswer = GetCorrectAnswer().GetAnswerPart(answersGivenSoFar);

        return(nextCorrectAnswer);
    }
Пример #11
0
 private void EnqueueMessages(ProblemPart[] possibleMessages)
 {
     Debug.Log ("I received " + possibleMessages.Length + " possible messages.");
     foreach(ProblemPart possibleMessage in possibleMessages)
     {
         if (possibleMessage.HasString())
         {
             messagesToShowOff.Enqueue (possibleMessage.GetString());
         }
     }
     Debug.Log ("Queue length now " + CountMessagesWaiting ().ToString ());
 }
Пример #12
0
 private void UpdateButtons()
 {
     //char[] letters = new char[]{'A', 'B', 'C', 'D', 'E'};
     for (int i = 0; i < answerButtonTexts.Length; i++)
     {         //set button text
         if (i >= availableAnswers.Count)
         {
             Debug.LogWarning("Not enough distractors");
             return;
         }
         ProblemPart part = (ProblemPart)availableAnswers[i];
         answerButtonTexts[i].text = part.GetString();             //"(" + letters[i] + ") " +
     }
 }
 private void EncouragementsReceived(ProblemPart[] encouragements)
 {
     foreach(ProblemPart encouragement in encouragements)
     {
         if (encouragement.HasSprite())
         {
             spriteEncouragementsToDisplay.Enqueue(encouragement.GetSprite());
         }
         if (encouragement.HasString())
         {
             stringEncouragementsToDisplay.Enqueue(encouragement.GetString());
         }
     }
     ShowAllEncouragements ();
 }
Пример #14
0
        static public bool ParseListItemsResponse(byte[] responseBytes)
        {
            Player.ListPlayerItemsResponse listItemsResponse =
                Deserialize(responseBytes, typeof(Player.ListPlayerItemsResponse)) as Player.ListPlayerItemsResponse;

            Logger.BasicLog("I got an items list response with " + listItemsResponse.item_atoms.Count + " items");

            //foreach(Message.Atom.Atom atom in listItemsResponse.item_atoms)
            //{
            //UnityEngine.Debug.Log(atom.filename);
            //}

            ProblemPart[] items = new ProblemPart[listItemsResponse.item_atoms.Count];
            for (int i = 0; i < listItemsResponse.item_atoms.Count; i++)
            {
                items[i] = ProblemPart.CreateProblemPart(listItemsResponse.item_atoms[i]);
            }

            ItemsDisplay.SetItemsToDisplay(items);

            return(true);
        }
Пример #15
0
        public static bool ParseGetEncouragementsResponse(byte[] responseBytes)
        {
            Encouragement.EncouragementGetResponse getEncouragementResponse =
                Deserialize (responseBytes, typeof(Encouragement.EncouragementGetResponse)) as Encouragement.EncouragementGetResponse;

            Logger.BasicLog ("I got an encouragement get response with " + getEncouragementResponse.encouragement_data.Count + " encouragements.");

            foreach (Encouragement.EncouragementData encouragementData in getEncouragementResponse.encouragement_data)
            {
                ProblemPart[] encouragementParts = new ProblemPart[encouragementData.encouragement_atoms.Count];
                for (int i = 0; i < encouragementParts.Length; i++)
                {
                    encouragementParts[i] = ProblemPart.CreateProblemPart(encouragementData.encouragement_atoms[i]);
                }
                ThinksyEvents.InvokeEncouragementReceived(encouragementParts);
            }

            ThinksyPlugin.NewHeartbeatTiming (getEncouragementResponse.frames_per_heartbeat);
            if (getEncouragementResponse.force_pull)
                ProblemKeeper.PullNewProblems ();

            return true;
        }
Пример #16
0
 /// <summary>
 /// Sets the given answer.  This can then be checked for correctness through CheckAnswer.
 /// </summary>
 public void AddGivenAnswerPart(ProblemPart newGivenAnswerPart)
 {
     GetGivenAnswer().AddAnswerPart(newGivenAnswerPart);
 }
Пример #17
0
 /// <summary>
 /// Adds a part to this answer.
 /// </summary>
 /// <param name="part">Added Part.</param>
 public void AddAnswerPart(ProblemPart part)
 {
     answerParts.Add(part);
     ThinksyQuestionDisplay.DisplayCurrentQuestion();
 }
Пример #18
0
    /// <summary>
    /// Gets distractors.
    /// These are wrong answers which can be presented as options to the player.
    /// </summary>
    /// <returns>The distractors.</returns>
    /// <param name="howManyDistractors">How many random distractors to return.</param>
    public ProblemPart[] GetDistractors(int howManyDistractors)
    {
        int availableDistractors = protobufsProblemData.distractor.distractors.Count;
        if (availableDistractors < howManyDistractors)
        {
            throw new Exception("There aren't enough distractors!  There are only "
                                + availableDistractors + " distractors.");
        }

        ArrayList allDistractors = new ArrayList();
        for (int i = 0; i < availableDistractors; i++)
        {
            Senseix.Message.Atom.Atom distractorAtom = protobufsProblemData.distractor.distractors[i];
            ProblemPart distractor = ProblemPart.CreateProblemPart(distractorAtom);
            allDistractors.Add(distractor);
        } //find all the distractors

        ProblemPart[] resultDistractors = new ProblemPart[howManyDistractors];
        for (int i = 0; i < howManyDistractors; i++)
        {
            int randomDistractorIndex = UnityEngine.Random.Range (0, allDistractors.Count);
            resultDistractors[i] = (ProblemPart)allDistractors[randomDistractorIndex];
            allDistractors.RemoveAt(randomDistractorIndex);
        } //take random ones

        return resultDistractors;
    }
Пример #19
0
 /// <summary>
 /// Invokes the encouragement received event.
 /// </summary>
 /// <param name="encouragementParts">the text/image pieces which make up
 /// the encouragement.</param>
 public static void InvokeEncouragementReceived(ProblemPart[] encouragementParts)
 {
     if (onEncouragementReceived != null)
         onEncouragementReceived (encouragementParts);
 }
Пример #20
0
 /// <summary>
 /// Sets the given answer.  This can then be checked for correctness through CheckAnswer.
 /// </summary>
 public void AddGivenAnswerPart(ProblemPart newGivenAnswerPart)
 {
     GetGivenAnswer().AddAnswerPart(newGivenAnswerPart);
 }
Пример #21
0
 public static void SetItemsToDisplay(ProblemPart[] items)
 {
     GetSingletonInstance ().InstanceSetItemsToDisplay (items);
 }
Пример #22
0
        public static bool ParseListItemsResponse(byte[] responseBytes)
        {
            Player.ListPlayerItemsResponse listItemsResponse =
                Deserialize (responseBytes, typeof(Player.ListPlayerItemsResponse)) as Player.ListPlayerItemsResponse;

            Logger.BasicLog ("I got an items list response with " + listItemsResponse.item_atoms.Count + " items");

            //foreach(Message.Atom.Atom atom in listItemsResponse.item_atoms)
            //{
                //UnityEngine.Debug.Log(atom.filename);
            //}

            ProblemPart[] items = new ProblemPart[listItemsResponse.item_atoms.Count];
            for (int i = 0; i < listItemsResponse.item_atoms.Count; i++)
            {
                items[i] = ProblemPart.CreateProblemPart(listItemsResponse.item_atoms[i]);
            }

            ItemsDisplay.SetItemsToDisplay (items);

            return true;
        }
    private void PopulateRichTextAreas(Problem problemToDisplay)
    {
        Question question       = problemToDisplay.GetQuestion();
        int      textAreaCount  = question.GetQuestionPartCount();
        float    ySpacePerArea  = 1f / (float)(textAreaCount - question.GetMultipleChoiceLetterCount());
        float    xSpacePerImage = (float)1 / Mathf.Clamp((float)question.GetMaximumQuestionPartRepeated(), 1, imagesPerRow);
        float    ySpacePerImage = (float)1 / Mathf.Ceil((float)question.GetMaximumQuestionPartRepeated()
                                                        / (float)imagesPerRow);

        int  row = 0;
        bool previousAreaWasMultipleChoice = false;

        if (textAreaCount == 0)
        {
            Senseix.Logger.BasicLog("I got a problem with no question atoms.");
            return;            //throw new UnityException ("I got a problem with no question atoms.");
        }
        richTextAreas = new GameObject[textAreaCount];

        for (int i = 0; i < textAreaCount; i++)
        {
            GameObject  newArea     = Instantiate(questionTextPrefab) as GameObject;
            ProblemPart problemPart = problemToDisplay.GetQuestion().GetQuestionPart(i);

            if (newArea.GetComponent <RectTransform>() == null ||
                newArea.GetComponent <Text>() == null)
            {
                throw new UnityException("richTextArea must have a rect transform and Text");
            }

            if (problemPart.HasString())
            {
                newArea.GetComponent <Text>().text += problemPart.GetString();
            }

            float indentedX = 0f;
            if (previousAreaWasMultipleChoice)
            {
                indentedX = indentMultipleChoices;
            }

            newArea.GetComponent <RectTransform>().SetParent(questionParent);
            PositionRectTransform(newArea.GetComponent <RectTransform>(),
                                  indentedX,
                                  1 - (row + 1) * ySpacePerArea,
                                  1,
                                  1 - row * ySpacePerArea);

            if (problemPart.HasSprite())
            {
                //squish this a little bit to provide space between image groups
                newArea.GetComponent <RectTransform>().anchorMin += new Vector2(0f, spaceImageAreas);
                newArea.GetComponent <RectTransform>().anchorMax -= new Vector2(0f, spaceImageAreas);


                for (int j = 0; j < problemPart.TimesRepeated(); j++)
                {
                    GameObject newImage = Instantiate(questionImagePrefab) as GameObject;
                    newImage.GetComponent <RectTransform>().SetParent(newArea.transform);
                    int imageColumn = j % imagesPerRow;
                    int imageRow    = Mathf.FloorToInt((float)j / (float)imagesPerRow);
                    PositionRectTransform(newImage.GetComponent <RectTransform>(),
                                          (imageColumn * xSpacePerImage),
                                          1 - (imageRow + 1) * ySpacePerImage,
                                          ((imageColumn + 1) * xSpacePerImage),
                                          1 - imageRow * ySpacePerImage);

                    newImage.GetComponent <Image>().sprite = problemPart.GetSprite();
                }
            }

            richTextAreas[i] = newArea;

            if (!problemPart.IsMultipleChoiceLetter())
            {
                row++;
                previousAreaWasMultipleChoice = false;
            }
            else
            {
                previousAreaWasMultipleChoice = true;
            }
        }
    }
Пример #24
0
 /// <summary>
 /// Adds a part to this answer.
 /// </summary>
 /// <param name="part">Added Part.</param>
 public void AddAnswerPart(ProblemPart part)
 {
     answerParts.Add(part);
     ThinksyQuestionDisplay.DisplayCurrentQuestion ();
 }