Funkcionalna igrica sa svim modelima dodatim

This commit is contained in:
Mediha Zukic
2017-05-19 19:46:08 +03:00
parent 115885da90
commit cdb36e6c52
217 changed files with 862453 additions and 640 deletions

View File

@@ -44,21 +44,16 @@ public class QuizController : MonoBehaviour {
List<Question> questions = new List<Question>() {
new Question("1. Neki od ovih prozora imaju 2-3 puta manje toplotnih gubitaka za razliku od drugih, koji su to?", new int[] {1, 4}),
new Question("2. Na jedan od načina možete uštedjeti i do 10 litara vode po osobi dnevno, uz koji predmet?", new int[] {3, 4}),
new Question("3. Korištenjem jednog od sljedećih predmeta, u svjetlost se pretvara svega 5% uložene energije, dok se ostatak pretvara u toplotu, koji je to?", new int[] {1}),
new Question("4. Neki od navedenih predmeta uključeni u utičnicu, iako nisu u u funkciji, i dalje se znatno griju i troše električnu energiju.", new int[] {3}),
new Question("5. Šta možemo ugraditi na radijatore da nam pomogne smanjiti troškove grijanja za 7-15%?", new int[] {1, 3}),
new Question("6. Ako je vani temperatura 33oC, koja je optimalna temperatura u kući? ", new int[] {4}),
new Question("7. Kakvim načinom pranja posuđa, i uz koji uređaj od navedenih, trošimo 60% manje električne energije i do 85% manje vode?", new int[] {2, 3}),
new Question("8. Koji uređaj u «stand by» načinu rada troši i do 24% energije u odnosu na potrošnju energije kada je upaljen?", new int[] {4}),
new Question("9. Jednom godišnje stručna osoba treba provjeriti prohodnost čega? Loša prohodnost doprinosi većoj potrošnji energije za grijanje.", new int[] {1}),
new Question("10. Uvijek odaberite program s najnižom temperaturom vode koji još uvijek obezbjeđuje dobar kvalitet pranja, za šta od navedenog? ", new int[] {1, 4}),
};
List<Question> q = new List<Question>()
{
new Question("3. Korištenjem jednog od sljedećih predmeta, u svjetlost se pretvara svega 5% uložene energije, dok se ostatak pretvara u toplotu, koji je to?", new int[] {1}),
new Question("4. Neki od navedenih predmeta uključeni u utičnicu, iako nisu u u funkciji, i dalje se znatno griju i troše električnu energiju.", new int[] {3}),
new Question("5. Šta možemo ugraditi na radijatore da nam pomogne smanjiti troškove grijanja za 7-15%?", new int[] {1, 3}),
new Question("6. Ako je vani temperatura 33oC, koja je optimalna temperatura u kući? ", new int[] {4}),
new Question("7. Kakvim načinom pranja posuđa, i uz koji uređaj od navedenih, trošimo 60% manje električne energije i do 85% manje vode?", new int[] {2, 3}),
new Question("8. Koji uređaj u «stand by» načinu rada troši i do 24% energije u odnosu na potrošnju energije kada je upaljen?", new int[] {4}),
new Question("9. Jednom godišnje stručna osoba treba provjeriti prohodnost čega? Loša prohodnost doprinosi većoj potrošnji energije za grijanje.", new int[] {1}),
new Question("10. Uvijek odaberite program s najnižom temperaturom vode koji još uvijek obezbjeđuje dobar kvalitet pranja, za šta od navedenog? ", new int[] {1, 4}),
};
public GameObject objController;
// Use this for initialization
@@ -69,25 +64,6 @@ public class QuizController : MonoBehaviour {
UpdateCounter();
UpdateScore();
btnNextQuestion.GetComponent<Button>().onClick.AddListener(LoadNextQuestion);
/*
// Instantiate the wreck game object at the same position we are at
GameObject wreckClone = (GameObject)Instantiate(objController, new Vector3(0, 2, -7), Quaternion.identity);
// Sometimes we need to carry over some variables from this object
// to the wreck
wreckClone.GetComponent<ObjectController>().imageCorrect.enabled = true;
wreckClone.GetComponent<ObjectController>().imageIncorrect.enabled = false;
// Instantiate the wreck game object at the same position we are at
GameObject wreckClone1 = (GameObject)Instantiate(objController, new Vector3(-5, 2, -7), Quaternion.identity);
// Sometimes we need to carry over some variables from this object
// to the wreck
wreckClone1.GetComponent<ObjectController>().imageCorrect.enabled = false;
wreckClone1.GetComponent<ObjectController>().imageIncorrect.enabled = true;
//Instantiate(Resources.Load("Prefabs/AnswerGameObject") as GameObject, new Vector3(0, 2, -7), Quaternion.identity);*/
}
@@ -96,16 +72,16 @@ public class QuizController : MonoBehaviour {
{
if (counterValue > 0)
{
counterValue -= Time.deltaTime;
UpdateCounter();
if (!counterDisplayAnswersStarted)
{
counterValue -= Time.deltaTime;
UpdateCounter();
}
}
else
{
LoadNextQuestion();
counterValue = counterInitialValue;
}
if (counterDisplayAnswersValue > 0 && counterDisplayAnswersStarted)
counterDisplayAnswersValue -= Time.deltaTime;
else
@@ -122,6 +98,8 @@ public class QuizController : MonoBehaviour {
if (Physics.Raycast(ray, out hit, 100))
{
if (counterDisplayAnswersStarted)
return;
Debug.Log(hit.transform.gameObject.name);
int answerIdx = GetAnswerIdx(hit.transform.gameObject.name) - numberOfAnswers * questionIdx;
if (!selectedAnswers.Contains(answerIdx))
@@ -139,8 +117,9 @@ public class QuizController : MonoBehaviour {
selectedAnswers.Clear();
counterDisplayAnswersValue = counterDisplayAnswersInitialValue;
counterDisplayAnswersStarted = true;
counterValue = counterInitialValue;
ShowAnswers();
questionIdx = (questionIdx + 1) % 2;
questionIdx = (questionIdx + 1) % questions.Count;
}
private void UpdateScore()
@@ -194,21 +173,43 @@ public class QuizController : MonoBehaviour {
}
}
/// <summary>
/// Returns answer index (X) from answer's name (AnswerX)
/// </summary>
/// <param name="gameObjName"></param>
/// <returns></returns>
private int GetAnswerIdx(string gameObjName)
{
string resultString = Regex.Match(gameObjName, @"\d+").Value;
return System.Int32.Parse(resultString);
}
/// <summary>
/// Returns score for a particular question
/// </summary>
/// <returns></returns>
private int GetScore() {
// Didn't try
if (selectedAnswers.Count == 0)
return scoreTimedOut;
// Correct answer
if (selectedAnswers.SequenceEqual(new List<int>(questions[questionIdx].getCorrectAnswers())))
if(IsAnswerCorrect(selectedAnswers, questions[questionIdx].getCorrectAnswers()))
return scoreCorrectAnswer;
else
return scoreIncorrectAnswer;
}
/// <summary>
/// Compares selected answers with correct answers
/// </summary>
/// <param name="selectedAnswers">List of selected answers</param>
/// <param name="correctAnswers">Array of correct answers</param>
/// <returns></returns>
private bool IsAnswerCorrect(List<int> selectedAnswers, int[] correctAnswers)
{
HashSet<int> correctAnswersSet = new HashSet<int>(new List<int>(correctAnswers));
return correctAnswersSet.SetEquals(selectedAnswers);
}
}