Пример #1
0
        public ImageQuestion GetImageQuestion(int ID)
        {
            if (_dbContext.ImageQuestion.Where(q => q.ID == ID).Count() == 0)
            {
                throw new Exception("Er is geen vraag gevonden met het ID : `" + ID.ToString() + "`");
            }

            ImageQuestion Question = new ImageQuestion();

            Models.DataModels.ImageQuestion ImageQuestion = _dbContext.ImageQuestion.Find(ID);

            Question.ID       = ImageQuestion.ID;
            Question.X1       = ImageQuestion.AnswerX1;
            Question.Y1       = ImageQuestion.AnswerY1;
            Question.IMG      = ImageQuestion.IMG;
            Question.Question = ImageQuestion.Question;

            if (ImageQuestion.AnswerX2 != 0 && ImageQuestion.AnswerX2 != 0)
            {
                Question.X2 = Convert.ToInt32(ImageQuestion.AnswerX2);
            }

            if (ImageQuestion.AnswerY2 != 0 && ImageQuestion.AnswerY2 != 0)
            {
                Question.Y2 = Convert.ToInt32(ImageQuestion.AnswerY2);
            }

            if (ImageQuestion.AnswerRatio != 0 && ImageQuestion.AnswerRatio != 0)
            {
                Question.Radius = Convert.ToInt32(ImageQuestion.AnswerRatio);
            }

            return(Question);
        }
Пример #2
0
        public ImageQuestion GetImageQuestion(int ID)
        {
            if (dbContext.ImageQuestion.Where(q => q.ID == ID).Count() == 0)
            {
                throw new Exception("Er is geen vraag gevonden met het ID : `" + ID.ToString() + "`");
            }

            ImageQuestion question = new ImageQuestion();

            Models.DataModels.ImageQuestion iq = dbContext.ImageQuestion.Find(ID);

            question.ID       = iq.ID;
            question.X1       = iq.answerX1;
            question.Y1       = iq.answerY1;
            question.img      = iq.img;
            question.Question = iq.Question;

            if (iq.answerX2 != 0 && iq.answerX2 != null)
            {
                question.X2 = Convert.ToInt32(iq.answerX2);
            }

            if (iq.answerY2 != 0 && iq.answerY2 != null)
            {
                question.Y2 = Convert.ToInt32(iq.answerY2);
            }

            if (iq.answerRatio != 0 && iq.answerRatio != null)
            {
                question.Radius = Convert.ToInt32(iq.answerRatio);
            }

            return(question);
        }
Пример #3
0
 public void Test_CreateImageQuestion_Question_2_Words()
 {
     NewImageQuestion          = NewImageQuestion_Copy;
     NewImageQuestion.Question = "wdjkawdwd dwadwadw";
     _postedFileBase           = new TestObjects.MyTestPostedFileBase(test_Stream, "test/content", "test-file.png");
     handler.CreateImageQuestion(NewImageQuestion, _postedFileBase, GameID);
 }
Пример #4
0
 public void Test_UpdateImageQuestion_Question_Y1_0()
 {
     ExistingImageQuestion    = ExistingImageQuestion_copy;
     ExistingImageQuestion.Y1 = 0;
     _postedFileBase          = new TestObjects.MyTestPostedFileBase(test_Stream, "test/content", "test-file.png");
     handler.UpdateImageQuestion(ExistingImageQuestion, _postedFileBase);
 }
Пример #5
0
 public void Test_CreateImageQuestion_Question_Char_51()
 {
     NewImageQuestion          = NewImageQuestion_Copy;
     NewImageQuestion.Question = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
     _postedFileBase           = new TestObjects.MyTestPostedFileBase(test_Stream, "test/content", "test-file.png");
     handler.CreateImageQuestion(NewImageQuestion, _postedFileBase, GameID);
 }
Пример #6
0
 public void Test_UpdateImageQuestion_Question_2_Words()
 {
     ExistingImageQuestion          = ExistingImageQuestion_copy;
     ExistingImageQuestion.Question = "wdjkawdwd dwadwadw";
     _postedFileBase = new TestObjects.MyTestPostedFileBase(test_Stream, "test/content", "test-file.png");
     handler.UpdateImageQuestion(ExistingImageQuestion, _postedFileBase);
 }
    /**
     * Create a new question in the DataModel and fill it with default value
     **/
    public void NewQuestionPanelData()
    {
        nbQ++;
        imagePrefab = Instantiate(Resources.Load <RectTransform>("Prefabs/ImgSample"), GameObject.Find("ImgGrid").transform);
        // set the new panel attributes to default values
        imagePrefab.name = "ImgSample" + nbQ;
        imagePrefab.GetComponent <PanelModel>().PanelNumber = nbQ;
        imagePrefab.GetComponent <PanelModel>().ImportDone  = false;
        // updating interface (language, events while clicking on button)
        imagePrefab.Find("Delete").GetComponent <Button>().onClick.AddListener(() => RemoveQuestion());
        imagePrefab.Find("Delete").GetComponentInChildren <TextMeshProUGUI>().text = DataModel.TextToUse["menu_remove"];
        imagePrefab.Find("ValidateQuestion").GetComponent <Button>().onClick.AddListener(() => SaveQuestion());
        imagePrefab.Find("ValidateQuestion").Find("ImportButton").GetComponent <Button>().onClick.AddListener(() => OpenImageFileBrowser());
        imagePrefab.Find("ValidateQuestion").Find("ImportButton").GetComponentInChildren <TextMeshProUGUI>().text = DataModel.TextToUse["import_image"];
        imagePrefab.Find("ValidateQuestion").GetComponentInChildren <TextMeshProUGUI>().text = DataModel.TextToUse["menu_validate"];
        for (int i = 1; i < 5; i++)
        {
            imagePrefab.Find("ValidateQuestion").Find("QField").Find("AnswerField").Find("A" + i + "Field").Find("Text Area").GetComponentInChildren <TextMeshProUGUI>().text = DataModel.TextToUse["enter_answertext"];
            imagePrefab.Find("ValidateQuestion").Find("QField").Find("AnswerField").Find("A" + i + "Field").Find("TrueA" + i).GetComponentInChildren <TextMeshProUGUI>().text = DataModel.TextToUse["correct_answer"];
        }
        //add a neutral question when user press the AddQuestion button and add it to the DataModel
        AnswerData[]  ans      = { new AnswerData("a", true), new AnswerData("b", false), new AnswerData("c", false), new AnswerData("d", false) };
        ImageQuestion question = new ImageQuestion("new question", ans);

        imagePrefab.Find("ValidateQuestion").Find("QField").Find("AnswerField").Find("A1Field").Find("TrueA1").GetComponent <Toggle>().isOn = true;
        DataModel.Rounds[DataModel.IroundCur].Topics[DataModel.ItopicCur].Questions.Add(question);
    }
Пример #8
0
        private void OnDelete(object sender, RoutedEventArgs e)
        {
            _question = (ImageQuestion)QuestionData.DataContext;
            Button button = sender as Button;

            _question.DeleteImage((ImageQuestion.ImageItem)button.DataContext);
        }
Пример #9
0
        //Create

        public void CreateImageQuestion(ImageQuestion Question, HttpPostedFileBase File, int GameID)
        {
            if (_dbContext.Game.Where(g => g.ID == GameID).Count() == 0)
            {
                throw new Exception("Er is geen game gevonden met het ID : `" + GameID.ToString() + "`");
            }
            if (Question.Question.Length < 5 || Question.Question.Length > 50)
            {
                throw new Exception("Een vraag moet tussen de 5 en 50 characters bevatten!");
            }
            if (Question.Question.Split(' ').Count() < 3)
            {
                throw new Exception("Een vraag moet uit meer dan 3 woorden bestaan!");
            }
            if (Question.X1 == 0 || Question.Y1 == 0)
            {
                throw new Exception("Er moet een antwoord gegeven worden!");
            }
            if (File == null)
            {
                throw new Exception("Je moet een afbeelding uploaden!");
            }


            string IMG = UploadHandler.UploadImage(File, UploadHandler.GetImageSize(PreDefImageSize.QuestionImage), PreDefImageLocation.QuestionImage).Name;

            Question.IMG = "/" + UploadHandler.GetImageUrlPath(PreDefImageLocation.QuestionImage) + IMG;

            Models.DataModels.ImageQuestion ImageQuestion = new Models.DataModels.ImageQuestion()
            {
                AnswerRatio = Question.Radius,
                AnswerX1    = Question.X1,
                AnswerX2    = Question.X2,
                AnswerY1    = Question.Y1,
                AnswerY2    = Question.Y2,
                Question    = Question.Question,
                IMG         = Question.IMG,
                ID          = Question.ID
            };
            _dbContext.ImageQuestion.Add(ImageQuestion);
            _dbContext.SaveChanges();

            int QuestionID = _dbContext.ImageQuestion.OrderByDescending(o => o.ID).FirstOrDefault().ID;

            _dbContext.ChartGroup.Add(new Models.DataModels.ChartGroup());
            _dbContext.SaveChanges();
            int ChartGroupID = _dbContext.ChartGroup.OrderByDescending(o => o.ID).FirstOrDefault().ID;

            Models.DataModels.Question NewQuestion = new Models.DataModels.Question()
            {
                ChartGroupID   = ChartGroupID,
                GameID         = GameID,
                QuestionType   = Models.DataModels.QuestionType.ImageQuestion,
                QuestionTypeID = QuestionID
            };

            _dbContext.Question.Add(NewQuestion);
            _dbContext.SaveChanges();
        }
Пример #10
0
 public Question(object _answer, int _type = QType.text, object _content = null, string Qname = "Sans nom", ImageQuestion imageQuestion = ImageQuestion.None)
 {
     type    = _type;
     content = _content;
     name    = Qname;
     if (type != QType.image)
     {
         imageQuestion = ImageQuestion.None;
     }
 }
Пример #11
0
 private void CompareImageQuestions(ImageQuestion a, ImageQuestion b)
 {
     Assert.AreEqual(a.IMG, b.IMG);
     Assert.AreEqual(a.Question, b.Question);
     Assert.AreEqual(a.X1, b.X1);
     Assert.AreEqual(a.X2, b.X2);
     Assert.AreEqual(a.Y1, b.Y1);
     Assert.AreEqual(a.Y2, b.Y2);
     Assert.AreEqual(a.Radius, b.Radius);
 }
Пример #12
0
    private void RunningQuestions()
    {
        goingToNextQuestion = false;
        // Make required objects to disappear at the start of question
        GameObject.Find("ArrowButton").GetComponent <Button>().interactable = false;

        arrow.GetComponent <CanvasGroup>().alpha = 0;
        foreach (GameObject e in timerPanelList)
        {
            e.GetComponent <CanvasGroup>().alpha = 0;
        }
        foreach (GameObject p in answerList)
        {
            p.GetComponent <CanvasGroup>().alpha = 0;
        }

        isNextAvailable = false;

        GameObject.Find("QuestionCounter").GetComponent <TextMeshProUGUI>().text = "Question " + actualQuestion + " / " + numberOfQuestions;

        // Either this is a MusicQuestion and we musicQuestionIsPlaying its music or we musicQuestionIsPlaying the basic question music
        ImageQuestion imageQ = (ImageQuestion)DataModel.CurQuestion();
        var           x      = new WWW("file:///" + localpath + '/' + imageQ.ImagePath);

        sprite = Sprite.Create(x.texture, new Rect(0, 0, x.texture.width, x.texture.height), new Vector2(0, 0));
        GameObject.Find("Questionimage").GetComponent <Image>().sprite = sprite;

        music            = (AudioClip)Resources.Load("Sounds/" + DataModel.QuestionMusicName);
        musicSource.clip = music;
        DisableTeam();

        StartCoroutine(DisplayText());

        foreach (PlayerModel e in teamsctrl)
        {
            ChangeTeamColor(0, e);
        }

        musicSource.Play();

        // After 10 seconds, the timer and answers appears, 7 seconds after that a false answer disappears, again 4 seconds after and at 25 sec teams can't answer
        // anymore. Finally at 28 seconds, the true answer is revealed and points are given
        Invoke("RevealAnswers", 10);
        Invoke("EliminateFalseAnswer", 17);
        Invoke("EliminateFalseAnswer", 21);
        Invoke("DisableTeam", 25);
        Invoke("FinalAnswerPhase", 28);
    }
Пример #13
0
 private void OnTakePhotoButton(object sender, RoutedEventArgs e)
 {
     _question = (ImageQuestion)QuestionData.DataContext;
     if (!_question.IsFull())
     {
         try
         {
             _question.Parent.Parent.TakingPhoto = true;
             _question.CameraTask.Show();
         }
         catch (InvalidOperationException) //catching double clicks
         {
         }
     }
     else
     {
         DisplayCapacityWarning();
     }
 }
    public bool GeneralSave()
    {
        bool allpassed = true;

        PanelModel[] questions = gameObject.GetComponentsInChildren <PanelModel>();
        foreach (PanelModel qi in questions)
        {
            if (qi.ImportDone)
            {
                int QuestionNumber = qi.PanelNumber;

                TMP_InputField[]  answersInput     = qi.transform.Find("ValidateQuestion").Find("QField").Find("AnswerField").GetComponentsInChildren <TMP_InputField>(); //get the answers
                Toggle[]          answersIsCorrect = new Toggle[answersInput.Length];
                List <AnswerData> answers          = new List <AnswerData>();

                for (int i = 0; i < answersInput.Length; i++)
                {
                    answersIsCorrect[i] = answersInput[i].GetComponentInChildren <Toggle>(); //get the correct statement of an answer
                    answers.Add(new AnswerData(answersInput[i].text, answersIsCorrect[i].isOn));
                }

                ImageQuestion question = new ImageQuestion(qi.Filepath, answers.ToArray());                                 //create a new ImageQuestion
                question.ImagePath = qi.Filepath;
                DataModel.Rounds[DataModel.IroundCur].Topics[DataModel.ItopicCur].Questions[QuestionNumber - 1] = question; //add the question in the current topic in DataModel
            }
            else
            {
                allpassed  = false;
                currentObj = qi.gameObject;
                StartCoroutine(ChangeColor());
                break;
            }
        }

        if (allpassed)
        {
            DataModel.Save(DataModel.CurrentFilename);
        }
        return(allpassed);
    }
    public void SaveQuestion()
    {
        currentObj = EventSystem.current.currentSelectedGameObject.GetComponentInParent <PanelModel>().gameObject;
        if (currentObj.GetComponent <PanelModel>().ImportDone)
        {
            int QuestionNumber                 = currentObj.GetComponentInParent <PanelModel>().PanelNumber;
            TMP_InputField[]  answersInput     = EventSystem.current.currentSelectedGameObject.transform.Find("QField").Find("AnswerField").GetComponentsInChildren <TMP_InputField>();//get the answers
            Toggle[]          answersIsCorrect = new Toggle[answersInput.Length];
            List <AnswerData> answers          = new List <AnswerData>();

            for (int i = 0; i < answersInput.Length; i++)
            {
                answersIsCorrect[i] = answersInput[i].GetComponentInChildren <Toggle>(); //get the correct statement of an answer
                answers.Add(new AnswerData(answersInput[i].text, answersIsCorrect[i].isOn));
            }

            ImageQuestion question = new ImageQuestion(currentObj.GetComponentInParent <PanelModel>().Filepath, answers.ToArray()); //create a new ImageQuestion
            DataModel.Rounds[DataModel.IroundCur].Topics[DataModel.ItopicCur].Questions[QuestionNumber - 1] = question;             //add the question in the current topic in DataModel
        }
        else
        {
            StartCoroutine(ChangeColor());
        }
    }
Пример #16
0
        //update

        public void UpdateImageQuestion(ImageQuestion question, HttpPostedFileBase file)
        {
            if (dbContext.ImageQuestion.Where(q => q.ID == question.ID).Count() == 0)
            {
                throw new Exception("Er is geen vraag gevonden met het ID : `" + question.ID.ToString() + "`");
            }
            if (question.Question.Length < 5 || question.Question.Length > 50)
            {
                throw new Exception("Een vraag moet tussen de 5 en 50 characters bevatten!");
            }
            if (question.Question.Split(' ').Count() < 3)
            {
                throw new Exception("Een vraag moet uit meer dan 3 woorden bestaan!");
            }
            if (question.X1 == 0 || question.Y1 == 0)
            {
                throw new Exception("Er moet een antwoord gegeven worden!");
            }


            if (file != null)
            {
                string img = UploadHandler.UploadImage(file, UploadHandler.GetImageSize(PreDefImageSize.QuestionImage), PreDefImageLocation.QuestionImage).Name;
                question.img = "/" + UploadHandler.GetImageUrlPath(PreDefImageLocation.QuestionImage) + img;
            }

            Models.DataModels.ImageQuestion iq = dbContext.ImageQuestion.Where(q => q.ID == question.ID).First();
            iq.answerX1    = question.X1;
            iq.answerX2    = question.X2;
            iq.answerY1    = question.Y1;
            iq.answerY2    = question.Y2;
            iq.answerRatio = question.Radius;
            iq.Question    = question.Question;
            iq.img         = question.img;
            dbContext.SaveChanges();
        }
Пример #17
0
    void Start()
    {
        answerlist = new List <string>();

        challengeRedMsg.gameObject.SetActive(false);
        challengeBlackMsg.gameObject.SetActive(false);
        newChallengeBtn.gameObject.SetActive(false);
        leaderBoardsBtn.gameObject.SetActive(false);

        imageRootURL = GameControl.instance.ImageRootURL;

        // cache counter text
        counterText = counter.GetComponent <Text>();

        // cache question panel components
        imageQuestion      = questionPanel.GetComponentInChildren <ImageQuestion>();
        questionPanelText  = questionPanel.GetComponentInChildren <Text>();
        questionPanelImage = questionPanel.GetComponent <Image>();

        // cache answer components
        answer1Text     = answer1.GetComponentInChildren <Text>();
        answer2Text     = answer2.GetComponentInChildren <Text>();
        answer3Text     = answer3.GetComponentInChildren <Text>();
        answer4Text     = answer4.GetComponentInChildren <Text>();
        answer1Image    = answer1.GetComponentInChildren <Image>();
        answer2Image    = answer2.GetComponentInChildren <Image>();
        answer3Image    = answer3.GetComponentInChildren <Image>();
        answer4Image    = answer4.GetComponentInChildren <Image>();
        answer1FadeMe   = answer1.GetComponentInChildren <FadeMe>();
        answer2FadeMe   = answer2.GetComponentInChildren <FadeMe>();
        answer3FadeMe   = answer3.GetComponentInChildren <FadeMe>();
        answer4FadeMe   = answer4.GetComponentInChildren <FadeMe>();
        answer1Question = answer1.GetComponent <AnswerQuestion>();
        answer2Question = answer2.GetComponent <AnswerQuestion>();
        answer3Question = answer3.GetComponent <AnswerQuestion>();
        answer4Question = answer4.GetComponent <AnswerQuestion>();

        // cache score, challenge name panels
        scorePanelText         = ScorePanel.GetComponentInChildren <Text>();
        scorePanelAnimator     = ScorePanel.GetComponentInChildren <Animator>();
        challengeNamePanelText = ChallengeNamePanel.GetComponentInChildren <Text>();

        pointsTextAnimation = pointstext.GetComponent <Animation>();

        if (GameControl.instance.isRandomized)
        {
            indicies = SeqUpTo(CSVreader.instance.grid.GetLength(1)).OrderBy(x => random.Next()).ToArray();
        }
        else
        {
            indicies = SeqUpTo(CSVreader.instance.grid.GetLength(1)).ToArray();
        }

        // cache game particles
        smallStarParticles   = summaryfx.transform.Find("Small Stars").GetComponent <ParticleSystem>();
        blobParticles        = summaryfx.transform.Find("Blobs").GetComponent <ParticleSystem>();
        faceHappyParticles   = summaryfx.transform.Find("Face_happy").GetComponent <ParticleSystem>();
        faceNeutralParticles = summaryfx.transform.Find("Face_neutral").GetComponent <ParticleSystem>();
        faceSadParticles     = summaryfx.transform.Find("Face_sad").GetComponent <ParticleSystem>();
        tooSlowParticles     = tooslowfx.GetComponentInChildren <ParticleSystem>();
        rightAnswerParticles = rightfx.GetComponentInChildren <ParticleSystem>();
        wrongAnswerParticles = wrongfx.GetComponentInChildren <ParticleSystem>();

        // start countdown
        CountdowntoStart();
    }
Пример #18
0
 public void Test_CreateImageQuestion_GameID_Wrong()
 {
     NewImageQuestion = NewImageQuestion_Copy;
     handler.CreateImageQuestion(NewImageQuestion, null, 999);
 }
Пример #19
0
 public QuestionInfo(ImageQuestion question) : this(question as Question)
 {
     this.sprite = question.Sprite;
 }
Пример #20
0
    public void Load(string filepath)
    {
        string     path       = filepath;
        string     jsonString = File.ReadAllText(path);
        JSONObject dataJson   = (JSONObject)JSON.Parse(jsonString);

        // Set values
        QuizName     = dataJson["Quizname"].Value;
        CurTopicName = dataJson["CurTopicName"].Value;
        RoundNumber  = dataJson["RoundNumber"].AsInt;
        //indexes
        IroundCur    = dataJson["IroundCur"].AsInt;
        ItopicCur    = dataJson["ItopicCur"].AsInt;
        IquestionCur = dataJson["IquestionCur"].AsInt;

        Scores = new int[NumberOfTeams];
        Jokers = new bool[NumberOfTeams];

        for (int i = 0; i < Scores.Length; i++)
        {
            Scores[i] = dataJson[("Score" + i)].AsInt;
            Jokers[i] = dataJson[("Joker" + i)].AsBool;
        }

        // Rounds
        List <RoundData> rdList = new List <RoundData>();

        for (int i = 0; i < dataJson["Rounds"].AsArray.Count; i++)
        {
            List <TopicData> tdList = new List <TopicData>();
            for (int j = 0; j < dataJson["Rounds"].AsArray[i]["Topics"].AsArray.Count; j++)
            {
                List <QuestionData> qdList = new List <QuestionData>();
                for (int k = 0; k < dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray.Count; k++)
                {
                    AnswerData[] adTab = new AnswerData[dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Answers"].AsArray.Count];
                    for (int l = 0; l < adTab.Length; l++)
                    {
                        AnswerData ad = new AnswerData(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Answers"].AsArray[l]["AnswerText"].Value,
                                                       dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Answers"].AsArray[l]["IsTrue"].AsBool);

                        adTab[l] = ad;
                    }

                    switch (dataJson["Rounds"].AsArray[i]["Type"].Value)
                    {
                    case "Blind test":
                        MusicQuestion mq = new MusicQuestion(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["MusicPath"].Value,
                                                             adTab);
                        mq.StartTrack = dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["StartTrack"].AsFloat;
                        mq.Volume     = dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Volume"].AsFloat;
                        mq.Fade       = dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Fade"].AsBool;
                        qdList.Add((QuestionData)mq);
                        break;

                    case "Musique":
                        MusicQuestion mq2 = new MusicQuestion(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["MusicPath"].Value,
                                                              adTab);
                        mq2.StartTrack = dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["StartTrack"].AsFloat;
                        mq2.Volume     = dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Volume"].AsFloat;
                        mq2.Fade       = dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Fade"].AsBool;
                        qdList.Add((QuestionData)mq2);
                        break;

                    case "Image":
                        ImageQuestion iq = new ImageQuestion(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["ImagePath"].Value,
                                                             adTab);
                        qdList.Add((QuestionData)iq);
                        break;

                    case "QCM":
                        TextQuestion tq = new TextQuestion(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Question"].Value,
                                                           adTab);
                        qdList.Add((QuestionData)tq);
                        break;

                    case "MCQ":
                        TextQuestion tq2 = new TextQuestion(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Question"].Value,
                                                            adTab);
                        qdList.Add((QuestionData)tq2);
                        break;

                    case "TrueFalse":
                        TrueFalseQuestion tf = new TrueFalseQuestion(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Question"].Value,
                                                                     adTab);
                        qdList.Add((QuestionData)tf);
                        break;

                    case "VraiFaux":
                        TrueFalseQuestion tf2 = new TrueFalseQuestion(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Question"].Value,
                                                                      adTab);
                        qdList.Add((QuestionData)tf2);
                        break;

                    default:
                        Debug.LogError("Type de question non-reconnu");
                        break;
                    }
                }
                TopicData td = new TopicData(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Name"].Value,
                                             qdList);
                td.IsAvailable = dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["IsAvailable"].AsBool;

                tdList.Add(td);
            }

            RoundData rd = new RoundData(dataJson["Rounds"].AsArray[i]["Type"].Value, tdList, dataJson["Rounds"].AsArray[i]["IsBuzzActivate"].AsBool);

            rdList.Add(rd);
        }
        Rounds = rdList;
    }
Пример #21
0
    /**
     * @author David
     *
     * Saving the current state of DataModel in the data.json file
     **/
    public static void Save(string filepath)
    {
        JSONObject dataJson = new JSONObject();

        dataJson.Add("Quizname", QuizName);
        dataJson.Add("CurTopicName", CurTopicName);
        dataJson.Add("RoundNumber", RoundNumber);
        // indexes
        dataJson.Add("IroundCur", IroundCur);
        dataJson.Add("ItopicCur", ItopicCur);
        dataJson.Add("IquestionCur", IquestionCur);

        for (int i = 0; i < Scores.Length; i++)
        {
            dataJson.Add("Score" + i, Scores[i]);
            dataJson.Add("Joker" + i, Jokers[i]);
        }

        JSONArray roundsJsonArray = new JSONArray();

        foreach (RoundData rd in Rounds)
        {
            JSONObject roundJson = new JSONObject();
            roundJson.Add("Type", rd.Type);
            roundJson.Add("IsBuzzActivate", rd.IsBuzzRound);
            JSONArray topicsJsonArray = new JSONArray();
            foreach (TopicData td in rd.Topics)
            {
                JSONObject topicJson = new JSONObject();

                topicJson.Add("Name", td.Name);
                topicJson.Add("IsAvailable", td.IsAvailable);

                JSONArray questionsJsonArray = new JSONArray();
                foreach (QuestionData qd in td.Questions)
                {
                    JSONObject questionJson = new JSONObject();

                    switch (qd.GetType().ToString())
                    {
                    case "MusicQuestion":
                        MusicQuestion mq = (MusicQuestion)qd;
                        questionJson.Add("MusicPath", mq.MusicPath);
                        questionJson.Add("StartTrack", mq.StartTrack);
                        questionJson.Add("Volume", mq.Volume);
                        questionJson.Add("Fade", mq.Fade);
                        break;

                    case "ImageQuestion":
                        ImageQuestion iq = (ImageQuestion)qd;
                        questionJson.Add("ImagePath", iq.ImagePath);
                        break;

                    case "TextQuestion":
                        TextQuestion tq = (TextQuestion)qd;
                        questionJson.Add("Question", tq.Question);
                        break;

                    case "TrueFalseQuestion":
                        TrueFalseQuestion tfq = (TrueFalseQuestion)qd;
                        questionJson.Add("Question", tfq.Question);
                        break;

                    default: Debug.LogError("Type de question non-reconnu"); break;
                    }

                    JSONArray answersJsonArray = new JSONArray();

                    foreach (AnswerData ad in qd.Answers)
                    {
                        JSONObject answerJson = new JSONObject();

                        answerJson.Add("AnswerText", ad.AnswerText);
                        answerJson.Add("IsTrue", ad.IsTrue);

                        answersJsonArray.Add(answerJson);
                    }
                    questionJson.Add("Answers", answersJsonArray);

                    questionsJsonArray.Add(questionJson);
                }
                topicJson.Add("Questions", questionsJsonArray);

                topicsJsonArray.Add(topicJson);
            }

            roundJson.Add("Topics", topicsJsonArray);

            roundsJsonArray.Add(roundJson);
        }

        dataJson.Add("Rounds", roundsJsonArray);

        File.WriteAllText(filepath, dataJson.ToString());
    }
Пример #22
0
 /// <summary>
 /// Default constuctor which initializes component on page.
 /// </summary>
 public ImageQuestionControl()
 {
     InitializeComponent();
     _question = (ImageQuestion)QuestionData.DataContext;
 }
Пример #23
0
        private List <EmbedBuilder> GeneratePictureContent(Question q, ImageQuestion type = ImageQuestion.RecognizePictureSingle)
        {
            EmbedBuilder imgEb1 = new EmbedBuilder();

            if (type == ImageQuestion.RecognizePictureSingle)
            {
                Console.WriteLine("Création d'une image avec 4 réponses a) b) c) d)");
                int    randomNumber = r.Next(0, recognizeThingsPictures.Count());
                string url = null;
                string name = recognizeThingsPictures[randomNumber];
                string a, b, c, d;
                string title  = "Que représente cette image ?";
                string answer = "Non définie";
                a = b = c = d = "N/A";
                switch (name)
                {
                case "Tank":
                    url    = "https://www.industrie-techno.com/mediatheque/5/4/4/000012445_imageArticlePrincipaleLarge.jpg";
                    a      = "Un prototype Polonais en construction";
                    b      = "Un char apparu dans le film Bladde Runner 2049";
                    c      = "Un Fan-Art";
                    d      = "Un nouveau char américain";
                    answer = a;
                    break;

                case "JeanneA":
                    url    = "http://www.musee-orsay.fr/typo3temp/zoom/tmp_828c5c0a84bf57e06bc87366dc30b237.gif";
                    title  = "Que représente cette statue";
                    a      = "Une jeune paysanne priant pour son mari";
                    b      = "Jeanne D'Arc";
                    c      = "Fernande Olivier";
                    d      = "Camille Claudel";
                    answer = b;
                    break;

                case "JeuneFillePerle":
                    // lien ne marche pas
                    url    = "https://cdn.radiofrance.fr/s3/cruiser-production/2016/05/5791f11c-4124-45b9-b493-2bd99aace836/738_meisje_met_de_parel.jpg";
                    title  = "Quel est l'auteur de ce tableau intitulé 'La jeune fille à la Perle'?";
                    a      = "Monet";
                    b      = "Vermeer";
                    c      = "Peeter de Hooch";
                    d      = "Van Gogh";
                    answer = b;
                    break;

                case "SpireDublin":
                    title  = "Quel représente ce monument?";
                    url    = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/E4324-Spire-of-Dublin.jpg/390px-E4324-Spire-of-Dublin.jpg";
                    a      = "La Spire de Dublin";
                    b      = "L'épine de Berlin ";
                    c      = "Le pic de Berlin";
                    d      = "La Pointe de Dublin";
                    answer = a;
                    break;

                case "SacreNapo":
                    title  = "En quelle année s'est déroulée cette scène?";
                    url    = "https://upload.wikimedia.org/wikipedia/commons/thumb/0/08/Jacques-Louis_David%2C_The_Coronation_of_Napoleon_edit.jpg/1200px-Jacques-Louis_David%2C_The_Coronation_of_Napoleon_edit.jpg";
                    a      = "1806";
                    b      = "1807";
                    c      = "1808";
                    d      = "1805";
                    answer = a;
                    break;

                case "Alkpote":
                    title  = "Quel est le nom de ce rappeur?";
                    url    = "https://www.trunksmagazine.com/wp-content/uploads/2017/07/86d0dd081a35d7e08781c2c889b6a788.1000x1000x1.jpg";
                    a      = "Ninho";
                    b      = "Lartiste";
                    c      = "Alkpote";
                    d      = "Sadek";
                    answer = c;
                    break;

                case "Acteur":
                    title  = "Quel est le nom de l'acteur sur ce meme?";
                    url    = "http://www.tuxboard.com/photos/2017/02/Kayode-Ewumi-meme-720x416.jpg";
                    a      = "Chadwick Boseman";
                    b      = "Will Smith";
                    c      = "Daniel Kaluuya";
                    d      = "Kayode Ewumi";
                    answer = d;
                    break;

                case "Coree":
                    title  = "De quand date cette image?";
                    url    = "https://cdn.cnn.com/cnnnext/dam/assets/180426203126-06-korea-summit-0426-exlarge-169.jpg";
                    a      = "avril 2017";
                    b      = "avril 2018";
                    c      = "mars 2018";
                    d      = "mai 2017";
                    answer = b;
                    break;

                case "Spiderman":
                    title  = "Quel est l'acteur principal de cette série de films?";
                    url    = "https://vignette.wikia.nocookie.net/spiderman/images/5/52/Spider-Man.jpg/revision/latest?cb=20131201182543";
                    a      = "Tobey Maguire";
                    b      = "Andrew Garfield";
                    c      = "Tom Holland";
                    answer = a;
                    break;

                case "Oiseau":
                    title  = "Quel est cet oiseau?";
                    url    = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d4/Black_eagle.jpg/290px-Black_eagle.jpg";
                    a      = "Aigle royal";
                    b      = "Aigle gris";
                    c      = "Aigle noir";
                    d      = "Buse noire";
                    answer = c;
                    break;
                }

                // On met les réponses dans l'ordre dans une première liste
                List <string> initAnswers = new List <string>
                {
                    a,
                    b,
                    c,
                    d
                };

                // On enregistre la bonne réponse de type texte
                q.answer = answer;


                // Mélange des réponses dans une nouvelle liste
                var randomAnswers = initAnswers.OrderBy(elem => Guid.NewGuid()).ToList();


                // On enregistre la bonne icone de réponse
                if (randomAnswers[0] == answer)
                {
                    q.answerLetter = "🇦";
                }
                else if (randomAnswers[1] == answer)
                {
                    q.answerLetter = "🇧";
                }
                else if (randomAnswers[2] == answer)
                {
                    q.answerLetter = "🇨";
                }
                else if (randomAnswers[3] == answer)
                {
                    q.answerLetter = "🇩";
                }

                // Ajout du titre à l'embed
                imgEb1.WithTitle(title);

                // Création du corps à l'aide des réponses placées aléatoirement
                imgEb1.WithDescription("a) " + randomAnswers[0] + "\nb) " + randomAnswers[1] + "\nc) " + randomAnswers[2] + "\nd) " + randomAnswers[3]);
                // Ajout d'une image à l'embed
                imgEb1.WithImageUrl(url);
                // Ajout de l'embed à la liste des embeds
                ebListSimple.Add(imgEb1);
                // On précise le type de cette question
                q.imageQuestion = type;

                // On peut enfin retourner notre embed terminé
                return(ebListSimple);
            }
            else if (type == ImageQuestion.CorrespondingImageMultiple)
            {
                Console.WriteLine("Création de plusieurs images qui doivent correspondre à une question");
                List <string> correctImage = new List <string>(new string[] { "TableauVermeer" });
                EmbedBuilder  imgEb2       = new EmbedBuilder();
                EmbedBuilder  imgEb3       = new EmbedBuilder();
                EmbedBuilder  imgEb4       = new EmbedBuilder();

                // r : nombre aléatoire de type Random(), R.Next(a,b) : prendre un nombre aléatoire entre a et b
                int    randomNumber = r.Next(0, correctImage.Count());
                string name = correctImage[randomNumber];
                string url1, url2, url3, url4 = null;
                switch (name)
                {
                case "TableauVermeer":
                    url1 = "https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/VermeerMilkmaid.jpg/230px-VermeerMilkmaid.jpg";
                    url2 = "http://www.rivagedeboheme.fr/medias/images/vermeer-la-jeune-fille-a-la-perle-1665-1667.jpg";
                    url3 = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/46/Cropped_version_of_Jan_Vermeer_van_Delft_002.jpg/260px-Cropped_version_of_Jan_Vermeer_van_Delft_002.jpg";
                    url4 = "https://upload.wikimedia.org/wikipedia/commons/7/78/Pieter_de_Hooch_-_The_Golf_Players_-_c.1658.jpg";

                    ebListMultiple.Add(imgEb1.WithImageUrl(url1).WithTitle("Réponse :regional_indicator_a:"));
                    ebListMultiple.Add(imgEb2.WithImageUrl(url2).WithTitle("Réponse :regional_indicator_b:"));
                    ebListMultiple.Add(imgEb3.WithImageUrl(url3).WithTitle("Réponse :regional_indicator_c:"));
                    ebListMultiple.Add(imgEb4.WithImageUrl(url4).WithTitle("Réponse :regional_indicator_d:"));
                    q.name         = "Lequel de ces tableaux n'a pas été peint par Vermeer?"; // Ce qui est affiché trop de fois d'affilée
                    q.answer       = "Vermeer";
                    q.answerLetter = "🇨";
                    break;

                default:
                    url1 = "https://blog.sqlauthority.com/i/a/errorstop.png";
                    ebListMultiple.Add(imgEb1.WithImageUrl(url1));
                    q.name = "Erreur, image non trouvée dans la liste";
                    break;
                }
                q.imageQuestion = type;
                List <EmbedBuilder> MagicList = new List <EmbedBuilder> {
                    imgEb1, imgEb2, imgEb3, imgEb4
                };
                return(MagicList);
            }
            return(ebListMultiple);
        }
Пример #24
0
        //Create

        public void CreateImageQuestion(ImageQuestion question, HttpPostedFileBase file, int GameID)
        {
            if (dbContext.Game.Where(g => g.ID == GameID).Count() == 0)
            {
                throw new Exception("Er is geen game gevonden met het ID : `" + GameID.ToString() + "`");
            }
            if (question.Question.Length < 5 || question.Question.Length > 50)
            {
                throw new Exception("Een vraag moet tussen de 5 en 50 characters bevatten!");
            }
            if (question.Question.Split(' ').Count() < 3)
            {
                throw new Exception("Een vraag moet uit meer dan 3 woorden bestaan!");
            }
            if (question.X1 == 0 || question.Y1 == 0)
            {
                throw new Exception("Er moet een antwoord gegeven worden!");
            }
            if (file == null)
            {
                throw new Exception("Je moet een afbeelding uploaden!");
            }


            string img = UploadHandler.UploadImage(file, UploadHandler.GetImageSize(PreDefImageSize.QuestionImage), PreDefImageLocation.QuestionImage).Name;

            question.img = "/" + UploadHandler.GetImageUrlPath(PreDefImageLocation.QuestionImage) + img;

            Models.DataModels.ImageQuestion imageQuestion = new Models.DataModels.ImageQuestion()
            {
                answerRatio = question.Radius,
                answerX1    = question.X1,
                answerX2    = question.X2,
                answerY1    = question.Y1,
                answerY2    = question.Y2,
                Question    = question.Question,
                img         = question.img,
                ID          = question.ID
            };
            dbContext.ImageQuestion.Add(imageQuestion);
            dbContext.SaveChanges();
            //string qry = "INSERT INTO `imagequestion` (`ID`, `img`, `question`, `answerX1`, `answerX2`, `answerY1`, `answerY2`, `answerRatio`) VALUES (NULL, '"+question.img+"', '"+question.Question+"', '"+question.X1+"', '"+question.X2+"', '"+question.Y1+"', '"+question.Y2+"', '"+question.Radius+"')";
            //SQL.Insert(qry);

            int questionID = dbContext.ImageQuestion.OrderByDescending(o => o.ID).FirstOrDefault().ID;

            dbContext.ChartGroup.Add(new Models.DataModels.ChartGroup());
            dbContext.SaveChanges();
            int chartGroupID = dbContext.ChartGroup.OrderByDescending(o => o.ID).FirstOrDefault().ID;

            Models.DataModels.Question q = new Models.DataModels.Question()
            {
                ChartGroupID   = chartGroupID,
                GameID         = GameID,
                QuestionType   = Models.DataModels.QuestionType.ImageQuestion,
                QuestionTypeID = questionID
            };

            dbContext.Question.Add(q);
            dbContext.SaveChanges();
            //string QuestionID = SQL.Select("SELECT `ID` FROM `imagequestion` WHERE `question` = '"+question.Question+ "' AND `img` = '"+question.img+"'").Last();

            //SQL.Insert("INSERT INTO `chartgroup`(`ID`) VALUES(NULL); INSERT INTO `question` (`ID`, `gameID`, `Type`, `QuestionTypeID`, `ChartGroupID`) VALUES (NULL, '" + GameID.ToString()+"', '0', '"+QuestionID+ "', ( SELECT MAX(`chartgroup`.`ID`) FROM `chartgroup`))");
        }
Пример #25
0
 public void Test_CreateImageQuestion_Question_IMG_NULL()
 {
     NewImageQuestion = NewImageQuestion_Copy;
     handler.CreateImageQuestion(NewImageQuestion, null, GameID);
 }