Skip to content
Snippets Groups Projects
Commit 2fdbab13 authored by EICHHORN LEO's avatar EICHHORN LEO
Browse files

Added change question onFail

parent 6ca82c50
Branches
No related merge requests found
......@@ -19,6 +19,7 @@ namespace Game.MinigameScript
{
_keypadController = gameObject.GetComponent<keypadController>();
_keypadController.OnCorrect(OnWin);
_keypadController.OnFail(OnLose);
_quiz = new Dictionary<string, int>
{
{ "Début de la première guerre mondial", 1914 },
......@@ -39,9 +40,13 @@ namespace Game.MinigameScript
//Function called to "init" the game
public override void StartScript()
{
_keypadController.enabled = true;
ChooseRandomQuestion();
}
private void ChooseRandomQuestion() {
KeyValuePair<String, int> question = _quiz.ElementAt(Random.Range(0, _quiz.Count));
_keypadController.password = question.Value.ToString();
_keypadController.enabled = true;
_tmpText.text = question.Key;
}
......@@ -56,6 +61,7 @@ namespace Game.MinigameScript
//Function called when the game is lost
public override void OnLose()
{
ChooseRandomQuestion();
NotifyLose();
}
}
......
......@@ -16,6 +16,7 @@ public class keypadController : MonoBehaviour
[FormerlySerializedAs("_password")] [SerializeField]
private Action onCorrect;
private Action onFail;
public string password;
// Start is called before the first frame update
......@@ -42,6 +43,10 @@ public class keypadController : MonoBehaviour
this.onCorrect = onCorrect;
}
public void OnFail(Action onFail){
this.onFail = onFail;
}
//Check if the code is correct, used coroutine for display
void OnButtonPressed(string buttonName)
{
......@@ -77,6 +82,7 @@ public class keypadController : MonoBehaviour
yield return new WaitForSeconds(1);
_textMeshProText.text = "";
_textMeshProText.color = Color.white;
onFail();
}
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment