// Use Update to check if player is attempting to chomp void Update() { if (Input.GetKeyDown(KeyCode.Space)) { int currentCorrectChomps = GameManager.Instance.currentNumberOfCorrectChomps; string currentTrigger = ColliderScript.currentTrigger; for (int i = 0; i < GridContent.GRID_SIZE; i++) { int chompedNumber = int.Parse(GridManager.Instance.texts[i].text); string spaceName = GridManager.Instance.texts[i].name; if (currentTrigger == spaceName && Primes.Is(chompedNumber) && GridManager.Instance.texts[i].enabled) { GridManager.Instance.texts[i].enabled = false; GameManager.Instance.currentNumberOfCorrectChomps++; GameManager.Instance.CorrectChomp(); break; } else if (currentTrigger == spaceName && !Primes.Is(chompedNumber)) { GridManager.Instance.texts[i].enabled = false; GameManager.Instance.IncorrectChomp(); break; } } } }
// Generates number set based on rule set public static int[] Generate(int numberOfAnswers, int numberOfCorrectAnswers, int[] numberRange, string rule) { int[] set = new int[numberOfAnswers]; // If mode is challenge, a random ruleset will be chosen if (rule == "challenge") { rule = ruleSets[Random.Range(0, ruleSets.Length - 1)]; } // Generate correct/incorrect answers per rule set int possibleAnswer; switch (rule) { case "primes": int tempmax = 0; for (int i = 0; i < numberOfCorrectAnswers; i++) { do { possibleAnswer = Random.Range(numberRange[0], numberRange[1]); }while (!Primes.Is(possibleAnswer)); set[i] = possibleAnswer; tempmax = i; } Debug.Log("Number of correct answers: " + numberOfCorrectAnswers + "\nIndex: " + tempmax); for (int i = numberOfCorrectAnswers; i < numberOfAnswers; i++) { do { possibleAnswer = Random.Range(numberRange[0], numberRange[1]); }while (Primes.Is(possibleAnswer)); set[i] = possibleAnswer; } break; case "multiples": int factor = Random.Range(0, 10); for (int i = 0; i < numberOfCorrectAnswers; i++) { do { possibleAnswer = Random.Range(numberRange[0], numberRange[1]); }while (!Multiples.Is(possibleAnswer, factor)); set[i] = possibleAnswer; } for (int i = numberOfCorrectAnswers; i < numberOfAnswers; i++) { do { possibleAnswer = Random.Range(numberRange[0], numberRange[1]); }while (Multiples.Is(possibleAnswer, factor)); set[i] = possibleAnswer; } break; case "factors": int multiple = Random.Range(0, 10); for (int i = 0; i < numberOfCorrectAnswers; i++) { do { possibleAnswer = Random.Range(numberRange[0], numberRange[1]); }while (!Multiples.Is(possibleAnswer, multiple)); set[i] = possibleAnswer; } for (int i = numberOfCorrectAnswers; i < numberOfAnswers; i++) { do { possibleAnswer = Random.Range(numberRange[0], numberRange[1]); }while (Multiples.Is(possibleAnswer, multiple)); set[i] = possibleAnswer; } break; } set = Shuffle(set); return(set); }