コード例 #1
0
        public async Task <IHttpActionResult> Get(int id)
        {
            var userId = User.Identity.Name;

            TriviaQuestion nextQuestion = await this.NextQuestionAsync(userId);

            if (nextQuestion == null)
            {
                return(this.NotFound());
            }

            return(this.Ok(nextQuestion));
        }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        //if(!isAnswered)
        //{
        if (checkedAnswer == IsAnswerCorrect.unanswered)
        {
            switch (checkedAnswer)
            {
            case (IsAnswerCorrect.unanswered):
                break;

            case (IsAnswerCorrect.yes):
                foreach (var button in ButtonList)
                {
                    button.image.color = Color.gray;
                }
                btnClickedButton.image.color = Color.green;
                //closeTimer = 5000f;
                isAnswered     = true;
                ActiveQuestion = QuestionQueue.Dequeue();
                QuestionQueue.Enqueue(ActiveQuestion);
                transform.parent.gameObject.SetActive(false);
                break;

            case (IsAnswerCorrect.no):
                foreach (var button in ButtonList)
                {
                    button.image.color = Color.gray;
                }
                btnClickedButton.image.color = Color.red;
                //closeTimer = 5000f;
                ActiveQuestion = QuestionQueue.Dequeue();
                QuestionQueue.Enqueue(ActiveQuestion);
                isAnswered = true;
                transform.parent.gameObject.SetActive(false);
                break;
            }
        }
        //}


        //if (checkedAnswer == IsAnswerCorrect.no || checkedAnswer == IsAnswerCorrect.yes)
        //{
        //    if (closeTimer > 0f)
        //        closeTimer -= Time.deltaTime;
        //    if (closeTimer <= 0f)
        //        gameObject.SetActive(false);


        //}
    }
コード例 #3
0
        public IHttpActionResult DeleteTriviaQuestion(int id)
        {
            TriviaQuestion triviaQuestion = db.TriviaQuestions.Find(id);

            if (triviaQuestion == null)
            {
                return(NotFound());
            }

            db.TriviaQuestions.Remove(triviaQuestion);
            db.SaveChanges();

            return(Ok(triviaQuestion));
        }
コード例 #4
0
        public async Task <IActionResult> Get()
        {
            var userId = User.Identity.Name;

            TriviaQuestion nextQuestion =
                await this.questionsService.NextQuestionAsync(userId);

            if (nextQuestion == null)
            {
                return(HttpNotFound());
            }

            return(Ok(nextQuestion));
        }
コード例 #5
0
        public async Task <TriviaQuestion> Get()
        {
            var userId = User.Identity.Name;

            TriviaQuestion nextQuestion =
                await this.questionsService.NextQuestionAsync(userId);

            if (nextQuestion == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(nextQuestion);
        }
コード例 #6
0
        // GET: /Question/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TriviaQuestion triviaquestion = await db.TriviaQuestions.FindAsync(id);

            if (triviaquestion == null)
            {
                return(HttpNotFound());
            }
            return(View(triviaquestion));
        }
コード例 #7
0
        public async Task <IHttpActionResult> DeleteTriviaQuestion(int id)
        {
            TriviaQuestion triviaQuestion = await _db.TriviaQuestions.FindAsync(id);

            if (triviaQuestion == null)
            {
                return(NotFound());
            }

            _db.TriviaQuestions.Remove(triviaQuestion);
            await _db.SaveChangesAsync();

            return(Ok(triviaQuestion));
        }
コード例 #8
0
        // GET: TriviaQuestions/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TriviaQuestion triviaQuestion = _db.TriviaQuestions.Find(id);

            if (triviaQuestion == null)
            {
                return(HttpNotFound());
            }
            return(View(triviaQuestion));
        }
コード例 #9
0
        public void TestGetQuestion()
        {
            TriviaQuestion triviaQuestion =
                _triviaApiClient.GetQuestionAsync(new TriviaPlayer()
            {
                Id = "846617cd-f4dc-46b4-8106-f24a7a0bccd7"
            }).Result;

            Assert.AreNotEqual(null, triviaQuestion);
            Assert.AreEqual(false, string.IsNullOrEmpty(triviaQuestion.Text));
            System.Diagnostics.Debug.WriteLine($"Deserialized question text: {triviaQuestion.Text}");
            Assert.AreNotEqual(null, triviaQuestion.QuestionOptions);
            Assert.AreNotEqual(0, triviaQuestion.QuestionOptions.Count);
        }
コード例 #10
0
        public void GetByID_ShouldReturnCorrectQuestion()
        {
            //Arrange
            TriviaQuestion_Repo repo        = new TriviaQuestion_Repo();
            TriviaQuestion      newQuestion = new TriviaQuestion(001, "What is a lowercase A?", "a", "b", "c", "d", TriviaCategory.General);

            repo.AddQuestionToList(newQuestion);
            int ID = 001;

            //Act
            TriviaQuestion searchResult = repo.GetQuestionById(ID);

            //Assert
            Assert.AreEqual(searchResult.QuestionID, ID);
        }
コード例 #11
0
        // GET: Admin/Create
        public ActionResult Create()
        {
            TriviaQuestion newQuestion = new TriviaQuestion
            {
                Answers = new List <TriviaAnswer>
                {
                    new TriviaAnswer(),
                    new TriviaAnswer(),
                    new TriviaAnswer(),
                    new TriviaAnswer()
                }
            };

            return(View(newQuestion));
        }
コード例 #12
0
        // GET: Question/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            TriviaQuestion triviaQuestion = await _context.TriviaQuestion.SingleAsync(m => m.Id == id);

            if (triviaQuestion == null)
            {
                return(HttpNotFound());
            }
            return(View(triviaQuestion));
        }
コード例 #13
0
        public void DeleteExistingContant_ShouldReturnTrue()
        {
            //Arrange
            TriviaQuestion_Repo repo        = new TriviaQuestion_Repo();
            TriviaQuestion      oldQuestion = new TriviaQuestion(001, "What is a lowercase A?", "a", "b", "c", "d", TriviaCategory.General);

            repo.AddQuestionToList(oldQuestion);

            //Act
            TriviaQuestion oldContent = repo.GetQuestionById(001);

            bool removeResult = repo.DeleteExistingQuestion(oldContent);

            //Assert
            Assert.IsTrue(removeResult);
        }
コード例 #14
0
        public void UpdateExistingQuestion_ShouldReturnTrue()
        {
            //Arrange
            TriviaQuestion_Repo repo        = new TriviaQuestion_Repo();
            TriviaQuestion      oldQuestion = new TriviaQuestion(001, "What is a lowercase A?", "a", "b", "c", "d", TriviaCategory.General);

            repo.AddQuestionToList(oldQuestion);

            TriviaQuestion newQuestion = new TriviaQuestion(001, "What is a lowercase A?", "a", "b", "c", "d", TriviaCategory.Science);

            //Act
            bool updateResult = repo.UpdateExistingQuestion(oldQuestion.QuestionID, newQuestion);

            //Assert
            Assert.IsTrue(updateResult);
        }
コード例 #15
0
        public void GetQuestions_ShouldReturnCorrectCollection()
        {
            //Arrange
            TriviaQuestion      question = new TriviaQuestion();
            TriviaQuestion_Repo repo     = new TriviaQuestion_Repo();

            repo.AddQuestionToList(question);

            //Act
            List <TriviaQuestion> questions = repo.GetQuestions();

            bool directoryHasQuestions = questions.Contains(question);

            //Assert
            Assert.IsTrue(directoryHasQuestions);
        }
コード例 #16
0
        public ActionResult TriviaQuestion(TriviaQuestion triviaQues)
        {
            int score = triviaService.GetUserScore(Session["UserName"].ToString());

            if (triviaQues.Answer == triviaQues.CorrectAnswer)
            {
                score += 4;
            }
            else
            {
                score = score - 1;
            }
            triviaService.InsertPlayerStats(triviaQues.QuestionID, Session["UserName"].ToString(), score);

            ViewBag.Score = score.ToString();
            return(RedirectToAction("Trivia", "Home"));
        }
コード例 #17
0
        public async Task <QuestionViewModel> GetQuestionAsync(TriviaQuestion entity, bool isLast)
        {
            var question = new QuestionViewModel();
            await Task.Run(() =>
            {
                question.Id      = entity.Id;
                question.Title   = entity.Title;
                question.IsLast  = isLast;
                question.Options = new List <OptionViewModel>();
                foreach (var option in entity.Options)
                {
                    question.Options.Add(new OptionViewModel(option));
                }
            });

            return(question);
        }
コード例 #18
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var    activity    = (IMessageActivity)await result;
            int    usersAnswer = -1;
            string answer      = activity.Text.Replace("trivia", string.Empty);

            if (int.TryParse(answer, out usersAnswer))
            {
                await context.PostAsync($"You chose: {answer}");

                if (_game.Answer(usersAnswer))
                {
                    await context.PostAsync("Correct!");
                }
                else
                {
                    await context.PostAsync("Sorry, that's wrong :-(");
                }

                await context.PostAsync($"Your score is: {_game.Score()}/{_game._questions.Count}. Next question!");

                TriviaQuestion nextQuestion = _game.MoveToNextQuestion();
                if (nextQuestion != null)
                {
                    await context.PostAsync(nextQuestion.Question);

                    await context.PostAsync(MakeChoiceCard(context, nextQuestion));

                    context.Wait(MessageReceivedAsync);
                }
                else
                {
                    await context.PostAsync("That's it! :-)");

                    context.Done("");
                    _game = null;
                }
            }
            else if (activity.Text != "trivia")
            {
                await context.PostAsync("I didn't quite get that, I am only programmed to accept numbers :-(");

                context.Wait(MessageReceivedAsync);
            }
        }
コード例 #19
0
        public async Task <IHttpActionResult> Get()
        {
            var userId = User.Identity.Name;

            userId = "jschuebel";


            //try
            //{

            //    using (SqlConnection connection = new SqlConnection("tcp:f25y9q8phy.database.windows.net,1433;Initial Catalog=ssstest1db;Persist Security Info=False;User ID=jschuebel;Password=Weebjs56;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"))
            //    {
            //        Console.WriteLine("\nQuery data example:");
            //        Console.WriteLine("=========================================\n");

            //        connection.Open();

            //        using (SqlCommand command = new SqlCommand("select * from TriviaQuestion", connection))
            //        {
            //            using (SqlDataReader reader = command.ExecuteReader())
            //            {
            //                while (reader.Read())
            //                {
            //                    Console.WriteLine("{0} {1}", reader.GetString(0), reader.GetString(1));
            //                }
            //            }
            //        }
            //    }
            //}
            //catch (SqlException e)
            //{
            //    Console.WriteLine(e.ToString());
            //}



            TriviaQuestion nextQuestion = await this.NextQuestionAsync(userId);

            if (nextQuestion == null)
            {
                return(this.NotFound());
            }

            return(this.Ok(nextQuestion));
        }
コード例 #20
0
ファイル: ProgramUI.cs プロジェクト: JoshHambright/TriviaGame
        public void ImportQuestions(string path)
        {
            string[] lines = System.IO.File.ReadAllLines(path);
            foreach (string line in lines)
            {
                string[]       columns     = line.Split(',');
                int            id          = Convert.ToInt32(columns[0]);
                string         question    = columns[1];
                string         rightAnswer = columns[2];
                string         wrong1      = columns[3];
                string         wrong2      = columns[4];
                string         wrong3      = columns[5];
                TriviaCategory category;
                switch (columns[6])
                {
                case "General":
                    category = TriviaCategory.General;
                    break;

                case "History":
                    category = TriviaCategory.History;
                    break;

                case "Geography":
                    category = TriviaCategory.Geography;
                    break;

                case "Pop Culture":
                    category = TriviaCategory.PopCulture;
                    break;

                case "Science":
                    category = TriviaCategory.Science;
                    break;

                default:
                    category = TriviaCategory.General;
                    break;
                }


                TriviaQuestion question1 = new TriviaQuestion(id, question, rightAnswer, wrong1, wrong2, wrong3, category);
                _repo.AddQuestionToList(question1);
            }
        }
コード例 #21
0
    /*
     * public void GiveDataButton() {
     *  string mapID = "mapID123";
     *  double lat = 1.23;
     *  double lon = 4.56;
     *  double alt = 7.89;
     *  double x = 0.12;
     *  double y = 3.45;
     *  double z = 1/3;
     *
     *  string activity = "activityID123" + "," + "activityTitleTrivia" + ","
     + lat + "," + lon + "," + alt + "," + x + "," + y + "," + z;
     +  NativeAPI.giveActivityData(mapID, activity);
     + }
     */

    /*
     * void GetInitInfo(string info) {
     *  char[] charSeparators = new char[] {','};
     *  string[] result = info.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
     *  // Convert info from native to sbContextManager.InitSBContext()
     *
     *  Debug.Log("**** Info From Native Data:" + "\n**** " + result[0] +
     *            "\n**** " + result[1]);
     * }
     */

    void GetTriviaInfo(string triviaInfo)
    {
        // Convert info from native to TriviaQuestion
        char[]   charSeparators = new char[] { ',' };
        string[] result         = triviaInfo.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);

        TriviaQuestion triviaQuestion = new TriviaQuestion();

        triviaQuestion.question = result[0];
        triviaQuestion.optionList.Add(result[1]);
        triviaQuestion.optionList.Add(result[2]);
        triviaQuestion.optionList.Add(result[3]);
        triviaQuestion.optionList.Add(result[4]);
        triviaQuestion.selectedIndex = Int32.Parse(result[5]);
        triviaQuestion.hints         = result[6];

        triviaContentFacade.OnEditTriviaDone(triviaQuestion);
    }
コード例 #22
0
    void Initialize()
    {
        isInitialized  = true;
        ActiveQuestion = null;
        QuestionQueue  = new Queue <TriviaQuestion>();
        Questions      = new List <TriviaQuestion>();
        Answers        = new List <string>();
        checkedAnswer  = IsAnswerCorrect.unanswered;
        isAnswered     = false;
        //Get Question object from API
        Questions  = ApiHelper.GetQuestions();
        closeTimer = 0f;

        //initialise queue for each question from API
        foreach (TriviaQuestion question in Questions)
        {
            QuestionQueue.Enqueue(question);
        }
    }
コード例 #23
0
ファイル: ProgramUI.cs プロジェクト: JoshHambright/TriviaGame
        private void SeedQuestions()
        {
            //Seed Questions for testing if not using the .csv files
            TriviaQuestion question1 = new TriviaQuestion(
                001, "What vegetable has varieties known as Bell Tower, Orobelle, and Jupiter?", "Pepper", "Squash", "Onion", "Corn", TriviaCategory.General);
            TriviaQuestion question2 = new TriviaQuestion(
                002, "What was the name of Michael J Fox's character in the television sitcom Family Ties?", "Alex Keaton", "Marty McFly", "Stuart Little", "Mike Flaherty", TriviaCategory.PopCulture);
            TriviaQuestion question3 = new TriviaQuestion(
                003, "How many Federal Holidays are there in the United States?", "10", "7", "13", "18", TriviaCategory.General);
            TriviaQuestion question4 = new TriviaQuestion(
                004, "What is the name of the world's longest river?", "Nile", "Amazon", "Mississippi", "Wabash", TriviaCategory.Geography);
            TriviaQuestion question5 = new TriviaQuestion(
                005, "Who is considered the father of the World Wide Web?", "Tim Berners-Lee", "Steve Jobs", "Bill Gates", "Jeff Bezos", TriviaCategory.History);

            _repo.AddQuestionToList(question1);
            _repo.AddQuestionToList(question2);
            _repo.AddQuestionToList(question3);
            _repo.AddQuestionToList(question4);
            _repo.AddQuestionToList(question5);
        }
コード例 #24
0
        // Assembles a Hero Card
        private IMessageActivity MakeChoiceCard(IDialogContext context, TriviaQuestion question)
        {
            var activity = context.MakeMessage();

            // make sure the attachments have been initialized, we use the attachments to add buttons to the activity message
            if (activity.Attachments == null)
            {
                activity.Attachments = new List <Attachment>();
            }

            var actions     = new List <CardAction>();
            var choiceIndex = 0;

            // For each card action, add a choice from the question to the action buttons
            foreach (var item in question.Choices)
            {
                actions.Add(new CardAction
                {
                    Title = $"({choiceIndex}) {item}",
                    Value = $"{choiceIndex}",

                    // PostBack means the Value will be sent back to the dialog as if the user
                    // typed it but it will be hidden from the chat window
                    Type = ActionTypes.PostBack
                });

                // Index the choices
                choiceIndex++;
            }

            // Create a hero card to "hold" the buttons and add it to the message activities attachments
            activity.Attachments.Add(
                new HeroCard
            {
                Title   = $"Choose One",
                Buttons = actions
            }.ToAttachment()
                );

            return(activity);
        }
コード例 #25
0
        private List <string> RandomizedAnswers(TriviaQuestion x)
        {
            List <string> answers = new List <string>(x.Answers);

            answers.Add(x.CorrectAnswer);

            List <string> randomized = new List <string>(answers.Count);

            Random r = new Random();
            int    randomIndex;

            while (answers.Count > 0)
            {
                randomIndex = r.Next(0, answers.Count); //Choose a random object in the list
                randomized.Add(answers[randomIndex]);   //add it to the new, random list
                answers.RemoveAt(randomIndex);          //remove to avoid duplicates
            }

            Answers = randomized;
            return(randomized);
        }
コード例 #26
0
ファイル: Trivia.cs プロジェクト: lkboyd/SeedPaths
        //This functions gets the full list of trivia questions from the Trivia.txt document
        static List <TriviaQuestion> GetTriviaList()
        {
            //Get Contents from the file.  Remove the special char "\r".  Split on each line.  Convert to a list.
            List <string> contents = File.ReadAllText("trivia.txt").Replace("\r", "").Split('\n').ToList();



            //Each item in list "contents" is now one line of the Trivia.txt document.

            //make a new list to return all trivia questions
            List <TriviaQuestion> returnList = new List <TriviaQuestion>();

            // TODO: go through each line in contents of the trivia file and make a trivia object.
            //       add it to our return list.
            // Example: Trivia newTrivia = new Trivia("what is my name?*question");
            //Return the full list of trivia questions
            TriviaQuestion Question1 = new TriviaQuestion(contents[0]);

            returnList.Add(Question1);
            return(returnList);
        }
コード例 #27
0
 public void NewQuestion(TriviaQuestion question)
 {
     Curtain.SetActive(false);
     CurrentQuwestion  = question;
     QuestionText.text = question.Question;
     AnswerABck.color  = Color.white;
     AnswerAText.text  = question.AnswerA;
     AnswerBBck.color  = Color.white;
     AnswerBText.text  = question.AnswerB;
     AnswerCBck.color  = Color.white;
     AnswerCText.text  = question.AnswerC;
     AnswerDBck.color  = Color.white;
     AnswerDText.text  = question.AnswerD;
     Timer             = qTime;
     GOTimer           = gameOverTime;
     TimerText.text    = Timer.ToString("c0");
     gameObject.SetActive(true);
     fails   = 0;
     TimesUp = false;
     SetState(State.Playing);
 }
コード例 #28
0
        public static HeroCard CreateQuestionCard(TriviaQuestion triviaQuestion)
        {
            List <CardAction> buttons = new List <CardAction>();

            foreach (TriviaQuestionOption triviaQuestionOption in triviaQuestion.QuestionOptions)
            {
                buttons.Add(new CardAction()
                {
                    Title = triviaQuestionOption.Text,
                    Type  = ActionTypes.ImBack,
                    Value = triviaQuestionOption.Id
                });
            }

            HeroCard card = new HeroCard()
            {
                Subtitle = triviaQuestion.Text,
                Buttons  = buttons,
            };

            return(card);
        }
コード例 #29
0
        private TriviaQuestion ParseRandomly(string htmlContent)
        {
            var paragraphs          = ExtractParagraps(htmlContent).ToList();
            var randomParagraphText = paragraphs.RandomElement();

            var cleanText  = Regex.Replace(randomParagraphText, SquareBracetsPattern, string.Empty);
            var textEntity = new Text(cleanText);

            textEntity.RemoveOneWordSentances();

            var sentanceEntity = textEntity.Sentances.RandomElement();
            var words          = sentanceEntity.Words;
            var cleanWords     = CleanFromGarbish(words);

            var randomWord  = cleanWords.RandomElement();
            var boilerPlate = new string('_', randomWord.Length);

            var question = sentanceEntity.Text.Replace(randomWord, boilerPlate);

            var shuffledAnswers = new List <string> {
                "*", "W1", "W2", "W3"
            };

            shuffledAnswers.Shuffle();
            var correctIndex = shuffledAnswers.IndexOf("*");

            shuffledAnswers[correctIndex] = randomWord;

            var triviaQuestion = new TriviaQuestion
            {
                Question = question,
                Correct  = correctIndex + 1,
                Answers  = shuffledAnswers
            };

            return(triviaQuestion);
        }
コード例 #30
0
    // Gets a table entity in a specified table by using a partition key containing a string
    public TriviaQuestion[] GetQuestionsByPartitionKeyContains(string tableName, string partitionKey)
    {
        XmlNodeList           nodes      = TableHelper.GetTable(tableName);
        List <TriviaQuestion> returnlist = new List <TriviaQuestion>();

        foreach (XmlNode node in nodes)
        {
            TriviaQuestion que = new TriviaQuestion();
            que.PartitionKey  = node.ChildNodes[0].InnerText;
            que.RowKey        = node.ChildNodes[1].InnerText;
            que.Org           = node.ChildNodes[3].InnerText;
            que.Location      = node.ChildNodes[4].InnerText;
            que.Question      = node.ChildNodes[5].InnerText;
            que.AnswerA       = node.ChildNodes[6].InnerText;
            que.AnswerB       = node.ChildNodes[7].InnerText;
            que.AnswerC       = node.ChildNodes[8].InnerText;
            que.AnswerD       = node.ChildNodes[9].InnerText;
            que.CorrectAnswer = node.ChildNodes[10].InnerText;
            que.Value         = int.Parse(node.ChildNodes[11].InnerText);

            returnlist.Add(que);
        }
        return(returnlist.ToArray());
    }