Changes from email - glow, timers, floor texture
This commit is contained in:
@@ -25,21 +25,23 @@ public class Quiz4Controller : MonoBehaviour {
|
||||
|
||||
public GameObject[] answerModels;
|
||||
|
||||
private int scoreValue = 0;
|
||||
private int scoreValue;
|
||||
|
||||
private int questionIdx = 0;
|
||||
|
||||
private const int initialScore = 0;
|
||||
|
||||
private const int numberOfAnswers = 4;
|
||||
|
||||
private const int scoreCorrectAnswer = 10;
|
||||
|
||||
private const int scoreIncorrectAnswer = -15;
|
||||
private const int scoreIncorrectAnswer = -10;
|
||||
|
||||
private const int scoreTimedOut = 0;
|
||||
private const int scoreForProfessorAtom = 10;
|
||||
|
||||
private const int counterInitialValue = 10;
|
||||
private const float counterInitialValue = 90;
|
||||
|
||||
private const int counterDisplayAnswersInitialValue = 3;
|
||||
private const float counterDisplayAnswersInitialValue = 1.5f;
|
||||
|
||||
private float counterValue;
|
||||
|
||||
@@ -129,15 +131,22 @@ public class Quiz4Controller : MonoBehaviour {
|
||||
/// Use this for initialization
|
||||
/// </summary>
|
||||
void Start () {
|
||||
scoreValue = initialScore;
|
||||
UpdateScore(true);
|
||||
questionIdx = 0;
|
||||
// Set counter to 90s
|
||||
counterValue = counterInitialValue;
|
||||
UpdateCounter();
|
||||
|
||||
selectedAnswers = new List<int>();
|
||||
answersHaloEffects = new List<GameObject>();
|
||||
answers = new List<GameObject>();
|
||||
counterValue = counterInitialValue;
|
||||
|
||||
// Instantiate answers and halo effects
|
||||
InstantiateAnswers();
|
||||
InstantiateHaloPrefabs();
|
||||
|
||||
UpdateScene();
|
||||
UpdateCounter();
|
||||
UpdateScore();
|
||||
btnNextQuestion.GetComponent<Button>().onClick.AddListener(LoadNextQuestion);
|
||||
}
|
||||
|
||||
@@ -149,16 +158,24 @@ public class Quiz4Controller : MonoBehaviour {
|
||||
{
|
||||
if (counterValue > 0)
|
||||
{
|
||||
// We pause timer to show correct answers
|
||||
/*
|
||||
if (!counterDisplayAnswersStarted)
|
||||
{
|
||||
counterValue -= Time.deltaTime;
|
||||
UpdateCounter();
|
||||
}
|
||||
}*/
|
||||
|
||||
counterValue -= Time.deltaTime;
|
||||
UpdateCounter();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (questionIdx == questions.Count)
|
||||
{
|
||||
SceneManager.LoadScene("EntryScene");
|
||||
return;
|
||||
}
|
||||
else
|
||||
LoadNextQuestion();
|
||||
}
|
||||
@@ -167,7 +184,10 @@ public class Quiz4Controller : MonoBehaviour {
|
||||
else
|
||||
{
|
||||
if (questionIdx == questions.Count)
|
||||
{
|
||||
SceneManager.LoadScene("EntryScene");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateScene();
|
||||
@@ -261,25 +281,28 @@ public class Quiz4Controller : MonoBehaviour {
|
||||
{
|
||||
if (counterDisplayAnswersStarted)
|
||||
return;
|
||||
scoreValue += GetScore();
|
||||
if (scoreValue < 0)
|
||||
scoreValue = 0;
|
||||
|
||||
UpdateScore();
|
||||
selectedAnswers.Clear();
|
||||
ClearCurrentSceneGlowEffect();
|
||||
// Start display answers counter
|
||||
counterDisplayAnswersValue = counterDisplayAnswersInitialValue;
|
||||
counterDisplayAnswersStarted = true;
|
||||
counterValue = counterInitialValue;
|
||||
ShowAnswers();
|
||||
questionIdx = questionIdx + 1;
|
||||
Debug.Log(questionIdx);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates score value - called from Update() method
|
||||
/// Updates score value
|
||||
/// </summary>
|
||||
private void UpdateScore()
|
||||
private void UpdateScore(bool initialization = false)
|
||||
{
|
||||
if (!initialization)
|
||||
{
|
||||
scoreValue += GetScore();
|
||||
if (scoreValue < 0)
|
||||
scoreValue = 0;
|
||||
}
|
||||
scoreText.text = scoreValue.ToString();
|
||||
}
|
||||
|
||||
@@ -382,15 +405,29 @@ public class Quiz4Controller : MonoBehaviour {
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private int GetScore() {
|
||||
// Didn't try
|
||||
if (selectedAnswers.Count == 0)
|
||||
return scoreTimedOut;
|
||||
// Correct answer
|
||||
if(IsAnswerCorrect(selectedAnswers, questions[questionIdx].getCorrectAnswers()))
|
||||
return scoreCorrectAnswer;
|
||||
else
|
||||
return scoreIncorrectAnswer;
|
||||
|
||||
int score = 0;
|
||||
// Correct answers
|
||||
int[] correctAnswers = questions[questionIdx].getCorrectAnswers();
|
||||
// Selected answers: selectedAnswers
|
||||
for (int ansIdx = 1; ansIdx <= numberOfAnswers; ++ansIdx)
|
||||
{
|
||||
// Correct and selected
|
||||
if (correctAnswers.Contains(ansIdx) && selectedAnswers.Contains(ansIdx))
|
||||
score += scoreCorrectAnswer;
|
||||
// Correct and not selected
|
||||
else if (correctAnswers.Contains(ansIdx) && !selectedAnswers.Contains(ansIdx))
|
||||
score += scoreIncorrectAnswer;
|
||||
// Incorrect and selected
|
||||
else if (!correctAnswers.Contains(ansIdx) && selectedAnswers.Contains(ansIdx))
|
||||
score += scoreIncorrectAnswer;
|
||||
// Incorrect and not selected
|
||||
else
|
||||
score += scoreCorrectAnswer;
|
||||
}
|
||||
int profAtomIdx = questions[questionIdx].getProfessorAtomIdx();
|
||||
if (profAtomIdx != -1 && selectedAnswers.Contains(profAtomIdx))
|
||||
score += scoreForProfessorAtom;
|
||||
return score;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user