Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class TriviaGame : MonoBehaviour {
- public struct Question
- {
- public string questionText;
- public string[] answers;
- public int correctAnswerIndex;
- public Question(string questionText, string[] answers, int correctAnswer)
- {
- this.questionText = questionText;
- this.answers = answers;
- this.correctAnswerIndex = correctAnswer;
- }
- }
- Question currentQuestion = new Question("Hi?", new string[] { "y", "p", "z", "g", "e"}, 2);
- public Button[] answerButtons;
- public Text questionText;
- private Question[] questions = new Question[10];
- private int currentQuestionIndex;
- private int[] questionNumbersChoosen = new int[5];
- // private int questionsFinished;
- void Start () {
- questions[0] = new Question("What is the capital of Spain?", new string[] { "Topeka", "Amsterdam", "Madrid", "London", "Toledo" }, 2);
- questions[1] = new Question("Who was the second US president?", new string[] { "Thomas Jefferson", "John Adams", "Bill Clinton", "George Washington", "Abraham Lincon" }, 1);
- questions[2] = new Question("What is the second planet in our solor system?", new string[] { "Mercury", "Earth", "Saturn", "Venus", "Pluto" }, 3);
- questions[3] = new Question("What is the largest continent?", new string[] { "Africa", "North America", "Asia", "Europe", "Austalia" }, 2);
- questions[4] = new Question("What US state has the hightest population?", new string[] { "California", "Florida", "Texas", "New York", "North Carolina" }, 0);
- questions[5] = new Question("A Platypus is a _____", new string[] { "Bird", "Reptile", "Insect", "Amphibian", "Mammal" }, 4);
- questions[6] = new Question("What is the boiling tempurature in fahrenheit?", new string[] { "100 degrees", "190 degrees", "300 degrees", "312 degreesn", "212 degrees" }, 4);
- questions[7] = new Question("How many degrees are in a circle?", new string[] { "360", "180", "640", "16", "270" }, 0);
- questions[8] = new Question("What is a name for a group of crows?", new string[] { "A bloat", "A herd", "A pack", "A murder", "A team" }, 3);
- questions[9] = new Question("Who created the painting starry night?", new string[] { "Pablo Picasso", "Vincent van Gogh", "Andy Warhol", "Leonardo da Vinci", "Frida Kahlo" }, 1);
- chooseQuestion();
- assignQuestion(questionNumbersChoosen[0]);
- }
- void Update () {
- }
- void assignQuestion(int questionNum)
- {
- currentQuestion = questions[questionNum];
- questionText.text = currentQuestion.questionText;
- for (int i = 0; i < answerButtons.Length; i++)
- {
- answerButtons[i].GetComponentInChildren<Text>().text = currentQuestion.answers[i];
- }
- }
- public void checkAnswer(int buttonNumber)
- {
- if(buttonNumber == currentQuestion.correctAnswerIndex)
- {
- print("you are correct!");
- }
- else
- {
- print("nope ;(");
- }
- // if(questionsFinished < questionNumbersChoosen.Length - 1)
- {
- moveToNextQuestion();
- // questionsFinished++;
- }
- }
- void chooseQuestion()
- {
- for(int i = 0; i < questionNumbersChoosen.Length; i++)
- {
- int questionNum = Random.Range(0, questions.Length);
- if(numberNotContained(questionNumbersChoosen, questionNum))
- {
- questionNumbersChoosen[i] = questionNum;
- }
- else
- {
- i--;
- }
- }
- currentQuestionIndex = Random.Range(0, questions.Length);
- }
- bool numberNotContained(int[] numbers, int number)
- {
- for(int i = 0; i < numbers.Length; i++) // zakres 0-4
- {
- if(number == numbers[i])
- {
- return false;
- }
- }
- return true;
- }
- public void moveToNextQuestion()
- {
- // assignQuestion(questionNumbersChoosen[questionNumbersChoosen.Length - 1 - questionsFinished]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement