/* static void uppgift4() * { * List<QuestionCard>min; * min = new List<QuestionCard>(); * QuestionCard card; * card = new QuestionCard(); * card.question = "Vad heter jag?"; * card.answer = "Erik"; * min.Add(card); * * QuestionCard card1; * card1 = new QuestionCard(); * card1.question = "Vad är sveriges huvudstad?"; * card1.answer = "Stockholm"; * min.Add(card1); * * QuestionCard card2; * card2 = new QuestionCard(); * card2.question = "hur gammal är jag?"; * card2.answer = "20"; * min.Add(card2); * }*/ static void uppgift5() { List <QuestionCard> cards; cards = new List <QuestionCard>(); QuestionCard card; card = new QuestionCard("vad heter norges huvudstad?", "oslo"); cards.Add(card); card = new QuestionCard("vad heter danmarks huvudstad?", "köpenhamn"); cards.Add(card); card = new QuestionCard("vad heter finlands huvudstad?", "helsingfors"); cards.Add(card); foreach (QuestionCard mycard in cards) { string answer; Console.WriteLine(mycard.GetQuestion()); answer = Console.ReadLine(); if (mycard.IsCorrect(answer)) { Console.WriteLine("det var rätt"); } else { Console.WriteLine("det var fel"); } } }
void InitQuestionUI(QuestionCard q) { question.text = q.Question; for (int i = 0; i < q.Answers.Count; i++) { AnswerPanel p = panels[i]; p.gameObject.SetActive(true); switch (countMode) { case CountMode.Numeric: p.AnswerNumber.text = numeric[i]; break; case CountMode.Alphabetic: p.AnswerNumber.text = alphabetic[i]; break; case CountMode.Roman: p.AnswerNumber.text = roman[i]; break; default: p.AnswerNumber.text = numeric[i]; break; } p.AnswerText.text = q.Answers[i]; p.Bulb.GetComponent <MeshRenderer>().enabled = true; p.Bulb.GetComponent <MeshRenderer>().material.SetColor(emissionId, colorsDimm[i]); } }
/// <summary> /// reduces the amount of answers in each question to the specified amount /// </summary> /// <param name="questionCatalog"></param> /// <param name="newAnswerCount"></param> /// <returns></returns> public List <QuestionCard> TrimQuestions(List <QuestionCard> questionCatalog, int newAnswerCount, bool shuffleAnswers) { List <QuestionCard> newQuestionCatalog = new List <QuestionCard>(questionCatalog.Count); for (int i = 0; i < questionCatalog.Count; i++) { Debug.Log("before clone: " + questionCatalog[i].ToString()); QuestionCard currentCard = (QuestionCard)questionCatalog[i].Clone(); Debug.Log("after clone: " + currentCard.ToString()); List <string> answers = currentCard.Answers; int amountToRemove = answers.Count - newAnswerCount; for (int removed = 0; removed < amountToRemove;) { int r = UnityEngine.Random.Range(0, answers.Count); if (r != currentCard.TrueAnswer) { answers.RemoveAt(r); removed++; } } if (shuffleAnswers) { currentCard.Reshuffle(); } newQuestionCatalog.Add(currentCard); } return(newQuestionCatalog); }
void InitQuestionUI(QuestionCard q) { centerImg.gameObject.SetActive(true); question.text = q.Question; for (int i = 0; i < q.Answers.Count; i++) { AnswerPanel p = panels[i]; p.gameObject.SetActive(true); switch (countMode) { case CountMode.Numeric: p.AnswerNumber.text = numeric[i]; break; case CountMode.Alphabetic: p.AnswerNumber.text = alphabetic[i]; break; case CountMode.Roman: p.AnswerNumber.text = roman[i]; break; default: p.AnswerNumber.text = numeric[i]; break; } p.AnswerText.text = q.Answers[i]; } centerImg.sprite = q.Image; }
public void CardQuestion() { var b = false; do { var question = new System.Random().Next(musicalInstruments.Count()); Question = musicalInstruments[question]; if (Cikanlar.Any(a => a == Question)) { b = false; } else { b = true; } } while (b == false); if (b == true) { Cikanlar.Add(Question); } var questionCard = new QuestionCard() { Card = soruCard, Instrument = Question }; question = questionCard; }
public async Task <IActionResult> Edit(int id, [Bind("QuestionCardId,Description")] QuestionCard questionCard) { if (id != questionCard.QuestionCardId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(questionCard); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!QuestionCardExists(questionCard.QuestionCardId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(questionCard)); }
public void AskAQuestionWrong() { Trivia trivia = new Trivia(new Random()); trivia.StartTriviaGame(1, 0); QuestionCard currentQuestion = trivia.AskQuestion(); Assert.IsFalse(currentQuestion.WasThePlayerCorrect("THIS IS THE WRONG ANSWER YOU BLOODY IDIOTS!")); }
public async Task <int> CreateQuestionCard(CreateQuestionCardModel model) { QuestionCard newCard = MapToEntity(model); context.QuestionCards.Add(newCard); await context.SaveChangesAsync(); return(newCard.QuestionCardId); }
public void AskAQuestionRight() { Trivia trivia = new Trivia(new Random()); trivia.StartTriviaGame(1, 0); QuestionCard currentQuestion = trivia.AskQuestion(); Assert.IsTrue(currentQuestion.WasThePlayerCorrect(currentQuestion.GiveCorrectAnswer())); }
private void Card_OnAnswered(QuestionCard sender, bool isCorrect) { if (isCorrect) { me.MP += 20; } Me_OnValueChange(me); opp.MP -= 1; Opp_OnValueChange(opp); }
public static QuestionCard UpdateCurrentQuestion() { QuestionCard newCard = QuestionDeck[0]; QuestionDeck.RemoveAt(0); currentQuestion = newCard; return(currentQuestion); }
public async Task <IActionResult> Create([Bind("QuestionCardId,Description")] QuestionCard questionCard) { if (ModelState.IsValid) { _context.Add(questionCard); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(questionCard)); }
private GameObject CreateCard(Question q, Vector3 position) { GameObject cardDummy = Instantiate(cardPrefab, position, Quaternion.identity, null); QuestionCard card = cardDummy.GetComponent <QuestionCard>(); if (card != null) { card.SetUpCard(q); } return(cardDummy); }
/// <summary> /// The Lamps glow for the set "glowTime" while reading the available Answers. /// The mesh filter changes from glowing to normal after the glowTime is finished. /// The User has the set time "answerTime" to think what the right answer is. /// The Lamp corresponding to the right answer glows up and the other Lamps and answers disappear (are disabled). /// </summary> /// <param name="q"></param> /// <returns></returns> IEnumerator AskQuestion(QuestionCard q) { InitQuestionUI(q); Vector3 cornerPosition = room.Corners[q.TrueAnswer]; //highlight the answers for (int i = 0; i < q.Answers.Count; i++) { GameObject bulb = panels[i].Bulb; MeshFilter mF = bulb.GetComponent <MeshFilter>(); MeshRenderer mR = bulb.GetComponent <MeshRenderer>(); mF.mesh = glowing; mR.material.SetColor(emissionId, colorsBright[i]); yield return(new WaitForSeconds(glowTime)); mR.material.SetColor(emissionId, colorsDimm[i]); mF.mesh = normal; } countDownBar.enabled = true; yield return(timer.UITimer(answerTime, countDownMask, countDownText)); Vector3 playerPosition = BodyDisplay.Instance.GetBodyPosition(); if (BodyDisplay.Instance.GetBodyBoundingBox(out Bounds b)) { if (b.IntersectXZCircle(cornerPosition, 1f)) { Debug.Log("Correct"); } } //TODO: Get the position of the player and compare it to the specified corner. countDownBar.enabled = false; for (int i = 0; i < q.Answers.Count; i++) { AnswerPanel p = panels[i]; if (i != q.TrueAnswer) { p.gameObject.SetActive(false); } else { p.Bulb.GetComponent <MeshFilter>().mesh = glowing; p.Bulb.GetComponent <MeshRenderer>().material.SetColor(emissionId, colorsBright[i]); } } yield return(new WaitForSeconds(showCorrectAnswerTime)); }
public void TriviaGameTest() { GameControl gameControl = GameControl.GetMaintained(); gameControl.ChooseLayout(1); gameControl.PurchaseSecret(); QuestionCard question = gameControl.GetQuestion(); Debug.WriteLine("question: " + gameControl.GetQuestion()); Debug.WriteLine("correct? " + gameControl.AnswerQuestion(question.GiveCorrectAnswer())); Debug.WriteLine("State: " + gameControl.DidPlayerWin()); }
private void newQuestion() { Question q = QuestionGenerator.Generate(null, qList); QuestionCard card = new QuestionCard(); card.Question = q; card.QuestionNo = questionNo; questionNo++; card.Dock = DockStyle.Bottom; card.BackColor = Color.Transparent; card.OnAnswered += Card_OnAnswered; card.OnClosed += Card_OnClosed; panelQuestionAlign.Controls.Add(card); }
private void newExQuestion() { Question q = QuestionGenerator.Generate(null, ExqList); QuestionCard card = new QuestionCard(); card.Question = q; card.QuestionNo = exQuestionNo; exQuestionNo++; card.Dock = DockStyle.Right; card.BackColor = Color.Transparent; card.OnAnswered += ExCard_OnAnswered; card.OnClosed += ExCard_OnClosed; panelExQuestionAlign.Controls.Add(card); }
public void StartPlayFlow() { if (this.optionButtonList.Count > 0) { for (int index = 0; index < this.optionButtonList.Count; index++) { gameObjectButtonList[index].onButtonPressed -= AfterOptionIsPressed; OnAnimationEnded -= gameObjectButtonList[index].InteractableAtEndofAnimation; Destroy(this.optionButtonList[index].gameObject); } this.optionButtonList.Clear(); this.gameObjectButtonList.Clear(); } QuestionManager.Categories targetCategory = QuestionManager.instance.GetRandomCategory(); targetQuestionCardScript = carouselBehaviour.StartSwipeToCategory(targetCategory).GetComponent <QuestionCard>(); QuestionAndAnswers targetQuestionData = QuestionManager.instance.GetRandomQuestionByCategory(targetCategory); targetQuestionCardScript.SetQuestionText(targetQuestionData.question); int RandomButton = Random.Range(0, 4); int wrongAnswerIndex = 0; for (int index = 0; index < 4; index++) { if (index == RandomButton) { OptionCard correctOptionButton = Instantiate(PrefabManager.instance.GetPrefabByName("OptionCard"), this.optionContainer).GetComponent <OptionCard>(); correctOptionButton.SetOptionCardQuestion(targetQuestionData.rightAnswer, true); this.optionButtonList.Add(correctOptionButton.GetComponent <RectTransform>()); this.gameObjectButtonList.Add(correctOptionButton); correctOptionButton.onButtonPressed += this.AfterOptionIsPressed; } else { OptionCard wrongOptionButton = Instantiate(PrefabManager.instance.GetPrefabByName("OptionCard"), this.optionContainer).GetComponent <OptionCard>(); wrongOptionButton.SetOptionCardQuestion(targetQuestionData.wrongAnswers[wrongAnswerIndex], false); this.optionButtonList.Add(wrongOptionButton.GetComponent <RectTransform>()); this.gameObjectButtonList.Add(wrongOptionButton); wrongOptionButton.onButtonPressed += this.AfterOptionIsPressed; wrongAnswerIndex++; } } }
private QuestionCardModel MapToModel(QuestionCard card) { if (card == null) { return(null); } return(new QuestionCardModel { QuestionCardId = card.QuestionCardId, LanguageId = card.LanguageId, Text = card.Text, NumberOfAnswers = card.NumberOfAnswers, IsAdultContent = card.IsAdultContent }); }
private void ExCard_OnAnswered(QuestionCard sender, bool isCorrect) { if (isCorrect) { exScore += 1; exQuestionCount += 1; lblExScore.Text = exScore.ToString() + " / " + exQuestionCount.ToString(); lblExMark.Text = Math.Round(exScore / (float)exQuestionCount * 100, 1).ToString() + "%"; } else { exQuestionCount += 1; lblExScore.Text = exScore.ToString() + " / " + exQuestionCount.ToString(); lblExMark.Text = Math.Round(exScore / (float)exQuestionCount * 100, 1).ToString() + "%"; } }
public void LoadQuestion() { if (this.master.GetPlayerInfo()[2] == 0) { SceneManager.LoadScene("GameOver"); return; } QuestionCard question = this.master.GetQuestion(); this.questionMessage.text = question.GiveQuestion(); string[] answers = (string[])question.GiveAnswers(); for (int i = 0; i <= 3; i++) { answerMessages[i].text = answers[i]; } }
protected override IEnumerator Execute() { KinectDeviceManager.Instance.BeginBodyTracking(true); while (questions.Count > 0) { QuestionCard q = questions[Random.Range(0, questions.Count)]; yield return(StartCoroutine(AskQuestion(q))); questions.Remove(q); } yield return(new WaitForSeconds(3)); ClearQuestionUI(); }
public void PlayAGameInProgress() { Trivia trivia = new Trivia(new Random()); trivia.StartTriviaGame(3, 5); QuestionCard currentQuestion = trivia.AskQuestion(); trivia.AnswerQuestion("THIS IS THE WRONG ANSWER YOU BLOODY IDIOTS!"); Assert.AreEqual(trivia.DidTheyWin(), TriviaState.InProgress); currentQuestion = trivia.AskQuestion(); trivia.AnswerQuestion(currentQuestion.GiveCorrectAnswer()); Assert.AreEqual(trivia.DidTheyWin(), TriviaState.InProgress); }
public static void OnWinnerSubmitted(int _cardCzarId, List <string> _winnerCards) { Console.WriteLine("On Winner Submitted\n"); foreach (int key in PlayerHands.Keys) { Console.WriteLine($"\nPlayer {key}'s Hand"); foreach (string card in PlayerHands[key]) { Console.WriteLine(card); } } Console.WriteLine($"\nWinners Hand"); foreach (string card in _winnerCards) { Console.WriteLine(card); } foreach (int key in PlayerHands.Keys) { bool match = true; foreach (string card in _winnerCards) { if (PlayerHands[key].Contains(card) == false) { match = false; } } if (match) { Console.WriteLine($"We have a winner => {key} {Server.Clients[key].Username}\n"); Server.Clients[key].Points++; int cardsNeeded = currentQuestion.cardsNeeded; QuestionCard card = UpdateCurrentQuestion(); StartNewRound(key, cardsNeeded); return; } } }
protected override IEnumerator Execute() { room = RoomManager.Instance.LoadRoom(); if (room == null) { yield break; } //get Questionary from json List <QuestionCard> questions = QuestionManager.Instance.GetQuestions(questionAmount); Debug.Log("before trim: " + questions[0].ToString()); QuestionManager.Instance.TrimQuestions(questions, answerAmount, true); Debug.Log("after trim: " + questions[0].ToString()); panels = new AnswerPanel[answerAmount]; for (int i = 0; i < panels.Length; i++) { GameObject p = Instantiate(panel); p.transform.SetParent(panelHolder.transform, false); AnswerPanel a = p.GetComponent <AnswerPanel>(); a.Bulb.GetComponent <MeshRenderer>().material = GetMaterial(colorsDimm[i]); panels[i] = a; } //List<QuestionCard> questions = QuestionManager.Instance.TrimQuestions(questionSet, 4, true); while (questions.Count > 0) { QuestionCard q = questions[Random.Range(0, questions.Count)]; yield return(StartCoroutine(AskQuestion(q))); questions.Remove(q); } yield return(new WaitForSeconds(3)); ClearQuestionUI(); }
public void PlayAGameWin() { Trivia trivia = new Trivia(new Random()); trivia.StartTriviaGame(3, 3); //Single question mechanics QuestionCard currentQuestion = trivia.AskQuestion(); trivia.AnswerQuestion(currentQuestion.GiveCorrectAnswer()); Assert.AreEqual(trivia.DidTheyWin(), TriviaState.InProgress); currentQuestion = trivia.AskQuestion(); trivia.AnswerQuestion(currentQuestion.GiveCorrectAnswer()); Assert.AreEqual(trivia.DidTheyWin(), TriviaState.InProgress); currentQuestion = trivia.AskQuestion(); trivia.AnswerQuestion(currentQuestion.GiveCorrectAnswer()); Assert.AreEqual(trivia.DidTheyWin(), TriviaState.Won); }
public void CardQuestion() { var b = false; do { var question = new System.Random().Next(musicalInstruments.Count()); Question = musicalInstruments[question]; if (Cikanlar.Any(a => a == Question)) { b = false; } else { b = true; } } while (b == false); if (b == true) { Cikanlar.Add(Question); } var questionCard = new QuestionCard() { Card = soruCard, Instrument = Question }; question = questionCard; foreach (var image in Images) { if (image.name == Question) { soruCardImage.GetComponent <Image>().sprite = image; } } }
/// <summary> Packet Format: [ Round Number, CardCzarID, LastRoundWinner, Array Size => [Card Texts], Server Message ] </summary> public static void BroadcastNewRound(int round, int newCardCzar, int lastCardCzar, int lastRoundWinner, int cardsNeeded, QuestionCard questionCard, string message) { Console.WriteLine("--------------------"); Console.WriteLine($"[Server] Broadcasting New Round | Round {round}, CardCzar {lastCardCzar} => {newCardCzar}, Last Round winner {lastRoundWinner}\n" + $"[Server] Sending {cardsNeeded} cards..\n" + $"[Server] New Question Card: {questionCard}. Cards Needed: {questionCard.cardsNeeded}\n"); foreach (ServerClient player in Server.Clients.Values) { if (player.Username == null) { continue; } using (Packet packet = new Packet((int)ServerPackets.broadcastNewRound)) { // Round count packet.Write(round); // new card czar ID packet.Write(newCardCzar); // Who won last round packet.Write(lastRoundWinner); // If its the first round of the game if (round == 1) { Console.WriteLine($"[Server] Sending {player.Username} {cardsNeeded} cards!"); // How many cards we are sending to the client packet.Write(cardsNeeded); for (int i = 0; i < cardsNeeded; i++) { // The cards we are sending packet.Write(GameManager.DrawFromDeck(player.ID, false)); } } else { if (player.ID == lastCardCzar) { // How many cards we are sending to the client packet.Write(0); } else { Console.WriteLine($"[Server] Sending {player.Username} {cardsNeeded} cards!"); // How many cards we are sending to the client packet.Write(cardsNeeded); for (int i = 0; i < cardsNeeded; i++) { // The cards we are sending packet.Write(GameManager.DrawFromDeck(player.ID, false)); } } } // New question packet.Write(questionCard.text); // Server message packet.Write(message); // The cards we need from the new question packet.Write(questionCard.cardsNeeded); SendTCPData(player.ID, packet); } } }
/// <summary> /// The Lamps glow for the set "glowTime" while reading the available Answers. /// The mesh filter changes from glowing to normal after the glowTime is finished. /// The User has the set time "answerTime" to think what the right answer is. /// The Lamp corresponding to the right answer glows up and the other Lamps and answers disappear (are disabled). /// </summary> /// <param name="q"></param> /// <returns></returns> IEnumerator AskQuestion(QuestionCard q) { q.Reshuffle(); InitQuestionUI(q); yield return(new WaitForSeconds(conf.questionTime)); bool correct = false; switch (conf.answeringMode) { case AnsweringMode.MOVE_X_AXIS: { Vector3 playerPosition = Vector3.zero; ToggleSlider(true); float remainingTime = conf.answerTime; countDownBar.enabled = true; countDownMask.gameObject.SetActive(true); while (remainingTime > 0f) { playerPosition = BodyDisplay.Instance.GetBodyPosition(); float adjustedX = Mathf.Clamp(playerPosition.x, -1, 1f); if (conf.flipX) { adjustedX *= -1; } adjustedX *= 0.5f; adjustedX += 0.5f; slider.value = adjustedX; remainingTime -= Time.deltaTime; countDownMask.fillAmount = 1 - remainingTime / conf.answerTime; countDownText.text = Mathf.RoundToInt(remainingTime).ToString(); yield return(null); } //yield return timer.UITimer(answerTime, countDownMask, countDownText); countDownText.text = ""; countDownBar.enabled = false; countDownMask.gameObject.SetActive(false); ToggleSlider(false); correct = (q.TrueAnswer == 0) ? playerPosition.x <= 0f : playerPosition.x > 0f; break; } case AnsweringMode.RAISE_HANDS: { float remainingTime = conf.answerTime / 2f; countDownBar.enabled = true; countDownMask.gameObject.SetActive(true); while (remainingTime > 0f) { remainingTime -= Time.deltaTime; countDownMask.fillAmount = 1 - remainingTime / conf.answerTime; countDownText.text = Mathf.RoundToInt(remainingTime).ToString(); yield return(null); } //yield return timer.UITimer(answerTime, countDownMask, countDownText); countDownText.text = ""; countDownBar.enabled = false; countDownMask.gameObject.SetActive(false); bool leftHandRaised = BodyDisplay.Instance.JointCompare(JointId.Head, JointId.HandLeft, hRC); bool rightHandRaised = BodyDisplay.Instance.JointCompare(JointId.Head, JointId.HandRight, hRC); //Debug.Log("Left" + leftHandRaised); //Debug.Log("Right" + rightHandRaised); correct = (q.TrueAnswer == 0) ? leftHandRaised && !rightHandRaised : rightHandRaised && !leftHandRaised; break; } } answerFeedback.gameObject.SetActive(true); countDownBar.gameObject.SetActive(false); countDownText.gameObject.SetActive(false); if (correct) { answerFeedback.text = StringRes.Get("_RightAnswer"); ConfettiBurst(); } else { answerFeedback.text = StringRes.Get("_WrongAnswer"); } for (int i = 0; i < q.Answers.Count; i++) { AnswerPanel p = panels[i]; if (i != q.TrueAnswer) { p.gameObject.SetActive(false); } } centerImg.gameObject.SetActive(false); yield return(new WaitForSeconds(conf.showCorrectAnswerTime)); answerFeedback.gameObject.SetActive(false); countDownBar.gameObject.SetActive(true); countDownText.gameObject.SetActive(true); }
public void ReturnCard(QuestionCard card) { card.gameObject.transform.SetParent(_qCardObjectPool.gameObject.transform); }