Checkbox
This commit is contained in:
@@ -17,11 +17,19 @@ public class QuizController : MonoBehaviour {
|
||||
|
||||
public Button btnNextQuestion;
|
||||
|
||||
private float counterValue = 90;
|
||||
private float counterValue;
|
||||
|
||||
private const int scoreIncreaseValue = 10;
|
||||
private const int numberOfAnswers = 4;
|
||||
|
||||
private const int scoreDecreaseValue = 15;
|
||||
private const int scoreCorrectAnswer = 10;
|
||||
|
||||
private const int scoreIncorrectAnswer = -15;
|
||||
|
||||
private const int scoreTimedOut = 0;
|
||||
|
||||
private const int counterInitialValue = 10;
|
||||
|
||||
private const int displayAnswersCounterValue = 3;
|
||||
|
||||
private int scoreValue = 0;
|
||||
|
||||
@@ -37,6 +45,7 @@ public class QuizController : MonoBehaviour {
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
selectedAnswers = new List<int>();
|
||||
counterValue = counterInitialValue;
|
||||
UpdateScene();
|
||||
UpdateCounter();
|
||||
UpdateScore();
|
||||
@@ -51,6 +60,11 @@ public class QuizController : MonoBehaviour {
|
||||
counterValue -= Time.deltaTime;
|
||||
UpdateCounter();
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadNextQuestion();
|
||||
counterValue = counterInitialValue;
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
@@ -60,37 +74,21 @@ public class QuizController : MonoBehaviour {
|
||||
if (Physics.Raycast(ray, out hit, 100))
|
||||
{
|
||||
Debug.Log(hit.transform.gameObject.name);
|
||||
int answerIdx = GetAnswerIdx(hit.transform.gameObject.name) - 4 * questionIdx;
|
||||
int answerIdx = GetAnswerIdx(hit.transform.gameObject.name) - numberOfAnswers * questionIdx;
|
||||
if (!selectedAnswers.Contains(answerIdx))
|
||||
selectedAnswers.Add(answerIdx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void IncreaseScore()
|
||||
{
|
||||
Debug.Log("Clicked on cube!");
|
||||
scoreValue += scoreIncreaseValue;
|
||||
UpdateScore();
|
||||
}
|
||||
|
||||
void LoadNextQuestion()
|
||||
{
|
||||
if (IsAnswerCorrect())
|
||||
IncreaseScore();
|
||||
else
|
||||
DecreaseScore();
|
||||
scoreValue += GetScore();
|
||||
UpdateScore();
|
||||
questionIdx = (questionIdx + 1) % 2;
|
||||
selectedAnswers.Clear();
|
||||
Debug.Log("" + questionIdx);
|
||||
UpdateScene();
|
||||
}
|
||||
|
||||
public void DecreaseScore()
|
||||
{
|
||||
Debug.Log("Clicked on sphere!");
|
||||
scoreValue -= scoreDecreaseValue;
|
||||
UpdateScore();
|
||||
counterValue = counterInitialValue;
|
||||
}
|
||||
|
||||
private void UpdateScore()
|
||||
@@ -110,7 +108,7 @@ public class QuizController : MonoBehaviour {
|
||||
// Set right answers
|
||||
for(int i = 0; i < answers.Length; i++)
|
||||
{
|
||||
if (i >= 4 * questionIdx && i < 4 * (questionIdx + 1))
|
||||
if (i >= numberOfAnswers * questionIdx && i < numberOfAnswers * (questionIdx + 1))
|
||||
{
|
||||
Debug.Log("Set active: " + i);
|
||||
answers[i].SetActive(true);
|
||||
@@ -126,7 +124,15 @@ public class QuizController : MonoBehaviour {
|
||||
return System.Int32.Parse(resultString);
|
||||
}
|
||||
|
||||
private bool IsAnswerCorrect() {
|
||||
return selectedAnswers.SequenceEqual(new List<int>(questions[questionIdx].getCorrectAnswers()));
|
||||
private int GetScore() {
|
||||
// Didn't try
|
||||
if (selectedAnswers.Count == 0)
|
||||
return scoreTimedOut;
|
||||
// Correct answer
|
||||
if (selectedAnswers.SequenceEqual(new List<int>(questions[questionIdx].getCorrectAnswers())))
|
||||
return scoreCorrectAnswer;
|
||||
else
|
||||
return scoreIncorrectAnswer;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user