private void NewInstructions() { timeRemain = StaticData.TIME_LIMIT; instructions = Randomize.RandomInstruction(noOfInstruction); noOfPressed = 0; int counting = 0; foreach (Transform child in instructionContainer.transform) { if (counting < instructions.Count) { child.gameObject.SetActive(true); child.GetChild(0).gameObject.GetComponent <Image>().sprite = instructionIcons[instructions[counting]]; child.gameObject.name = instructions[counting].ToString(); } else { child.gameObject.SetActive(false); } counting++; } operation = instructions[instructions.Count - 1]; }
public static List <StaticData.INSTRUCTION> RandomInstruction(int n) { Array values = Enum.GetValues(typeof(StaticData.INSTRUCTION)); List <StaticData.INSTRUCTION> instructions = new List <StaticData.INSTRUCTION>(); for (int i = 0; i < n - 1; i++) { StaticData.INSTRUCTION instruction = (StaticData.INSTRUCTION)values.GetValue(random.Next(values.Length)); if (instructions.Count >= 1) { while (instruction == instructions[instructions.Count - 1]) { instruction = (StaticData.INSTRUCTION)values.GetValue(random.Next(values.Length)); } } instructions.Add(instruction); } StaticData.INSTRUCTION lastOperation = (StaticData.INSTRUCTION)values.GetValue(random.Next(3)); instructions.Add(lastOperation); return(instructions); }