Changes from email - glow, timers, floor texture

This commit is contained in:
Mediha Zukic
2017-05-23 19:39:06 +03:00
parent dd09c6f72f
commit 40cedaf5bf
58 changed files with 4679 additions and 1465 deletions

View File

@@ -45,10 +45,6 @@
PROZOR_BEZ_ROLETNE
};
public class Answer
{
public Answer(AnswerObjectModel model, string caption)
@@ -87,9 +83,6 @@ public class Question
possibleAnswers = possibleAns;
}
// All questions have the same number of possible answers
// private static int numberOfAnswers = 4;
private int[] correctAnswers;
private string questionText;
@@ -111,9 +104,13 @@ public class Question
return possibleAnswers;
}
/*
public static int getNumberOfAnswers()
public int getProfessorAtomIdx()
{
return numberOfAnswers;
}*/
for(int i = 0; i < possibleAnswers.Length; ++i)
{
if (possibleAnswers[i].getAnswerModel() == AnswerObjectModel.PROFESOR_ATOM_10)
return i + 1;
}
return -1;
}
}

View File

@@ -13,37 +13,35 @@ public class Quiz2Controller : MonoBehaviour {
public GameObject[] answerModels;
public GameObject haloEffect;
public GameObject haloEffectRed;
public GameObject haloEffectGreen;
// References to answers
private List<GameObject> answers;
// References to answers halo prefabs
private List<GameObject> answersHaloEffects;
private List<GameObject> answersRedHaloEffects;
private List<GameObject> answersGreenHaloEffects;
private const int numberOfAnswers = 2;
private const int scoreCorrectAnswer = 10;
private const int scoreIncorrectAnswer = -15;
private const int scoreIncorrectAnswer = -10;
private const int scoreTimedOut = 0;
private const float counterInitialValue = 90;
private const int totalGameTime = 90;
private float totalTimePerQuestion;
private float counterValue;
private int scoreValue;
private int questionIdx;
private float counterValue;
private float counterPerQuestionValue;
private int selectedAnswerIdx;
private const int counterDisplayAnswersTotalValue = 3;
private const float counterDisplayAnswersTotalValue = 1.5f;
private float counterDisplayAnswersValue;
@@ -128,17 +126,17 @@ public class Quiz2Controller : MonoBehaviour {
// Init counters and score
questionIdx = 0;
scoreValue = 0;
counterValue = 0;
counterPerQuestionValue = 0;
counterValue = counterInitialValue;
counterDisplayAnswersValue = 0;
counterDisplayAnswersStarted = false;
totalTimePerQuestion = totalGameTime / questions.Count;
answers = new List<GameObject>();
answersHaloEffects = new List<GameObject>();
answersRedHaloEffects = new List<GameObject>();
answersGreenHaloEffects = new List<GameObject>();
UpdateCounter();
UpdateScore(true);
InstantiateAnswers();
InstantiateHaloPrefabs();
InstantiateRedHaloPrefabs();
InstantiateGreenHaloPrefabs();
UpdateScene();
}
@@ -148,13 +146,17 @@ public class Quiz2Controller : MonoBehaviour {
Debug.Log(counterDisplayAnswersValue.ToString());
// Main counter
// Game over
if (counterValue > totalGameTime)
if (counterValue < 0)
{
SceneManager.LoadScene("EntryScene");
counterValue += Time.deltaTime;
return;
}
counterValue -= Time.deltaTime;
UpdateCounter();
// Load next pair
if((counterDisplayAnswersValue > counterDisplayAnswersTotalValue) && counterDisplayAnswersStarted || (counterPerQuestionValue > totalTimePerQuestion && !counterDisplayAnswersStarted))
if((counterDisplayAnswersValue > counterDisplayAnswersTotalValue) && counterDisplayAnswersStarted)
{
// Load next pair
LoadNextPair();
@@ -163,9 +165,6 @@ public class Quiz2Controller : MonoBehaviour {
if (counterDisplayAnswersValue < counterDisplayAnswersTotalValue && counterDisplayAnswersStarted)
counterDisplayAnswersValue += Time.deltaTime;
if (counterPerQuestionValue < totalTimePerQuestion)
counterPerQuestionValue += Time.deltaTime;
// Select answers event handler
if (Input.GetMouseButtonDown(0))
@@ -181,7 +180,7 @@ public class Quiz2Controller : MonoBehaviour {
counterDisplayAnswersStarted = true;
// Set glow
selectedAnswerIdx = GetAnswerIdx(hit.transform.gameObject.name);
SetGlowEffect(selectedAnswerIdx, true);
SetGlowEffect(selectedAnswerIdx, true, IsAnswerCorrect(selectedAnswerIdx, questions[questionIdx].getCorrectAnswers()));
// Update score
UpdateScore();
}
@@ -196,7 +195,8 @@ public class Quiz2Controller : MonoBehaviour {
for (int i = 0; i < numberOfAnswers; i++)
{
int prefabIdx = questionIdx * numberOfAnswers + i;
answersHaloEffects[prefabIdx].SetActive(false);
answersRedHaloEffects[prefabIdx].SetActive(false);
answersGreenHaloEffects[prefabIdx].SetActive(false);
}
}
@@ -204,9 +204,12 @@ public class Quiz2Controller : MonoBehaviour {
/// Clears/Adds glow from a specific answer GameObject
/// </summary>
/// <param name="prefabIdx"></param>
private void SetGlowEffect(int prefabIdx, bool showGlowEffect)
{
answersHaloEffects[prefabIdx - 1].SetActive(showGlowEffect);
private void SetGlowEffect(int prefabIdx, bool showGlowEffect, bool isCorrectAnswer)
{
if(isCorrectAnswer)
answersGreenHaloEffects[prefabIdx - 1].SetActive(showGlowEffect);
else
answersRedHaloEffects[prefabIdx - 1].SetActive(showGlowEffect);
}
/// <summary>
@@ -244,22 +247,35 @@ public class Quiz2Controller : MonoBehaviour {
}
/// <summary>
/// Adds Halo prefabs to all answers
/// Adds red Halo prefabs to all answers
/// </summary>
private void InstantiateHaloPrefabs()
private void InstantiateRedHaloPrefabs()
{
for (int i = 0; i < answers.Count; i++)
{
GameObject answerPrefab = Instantiate(haloEffect) as GameObject;
GameObject answerPrefab = Instantiate(haloEffectRed) as GameObject;
answerPrefab.SetActive(false);
answerPrefab.transform.SetParent(answers[i].transform, false);
answersHaloEffects.Add(answerPrefab);
answersRedHaloEffects.Add(answerPrefab);
}
}
/// <summary>
/// Adds red Halo prefabs to all answers
/// </summary>
private void InstantiateGreenHaloPrefabs()
{
for (int i = 0; i < answers.Count; i++)
{
GameObject answerPrefab = Instantiate(haloEffectGreen) as GameObject;
answerPrefab.SetActive(false);
answerPrefab.transform.SetParent(answers[i].transform, false);
answersGreenHaloEffects.Add(answerPrefab);
}
}
void LoadNextPair()
{
counterPerQuestionValue = 0;
counterDisplayAnswersValue = 0;
counterDisplayAnswersStarted = false;
ClearCurrentSceneGlowEffect();

View File

@@ -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>