protected override void Initialize() { switch (CurrentDifficulty) { case GameDifficulty.Easy: maxdotscolor = 2; break; case GameDifficulty.Medium: maxdotscolor = 5; break; case GameDifficulty.Master: maxdotscolor = 8; break; } location_order = new ArrayListIndicesRandom(NUMCOLUMNS * NUMCOLUMNS); location_order.Initialize(); palette = new ColorPalette(); // dotsPerColor is compared with iterator of dots. (this iterator is 0 based, so I // have to substract 1 to make dotsPerColor contents 0 based. dotsPerColor = new int [palette.Count]; for (int i = 0, before = -1; i < palette.Count; i++) { dotsPerColor[i] = before + MINDOTS + random.Next(maxdotscolor - MINDOTS + 1); before = dotsPerColor[i]; } Answer.Correct = (dotsPerColor[0] + 1).ToString(); base.Initialize(); }
protected override void Initialize() { random_indices = new ArrayListIndicesRandom((int)Figures.Last); random_indices.Initialize(); Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; for (int i = 0; i < (int)Figures.Last; i++) { if (random_indices[i] == (int)Figures.Third) { Answer.SetMultiOptionAnswer(i, Answer.GetFigureName(i)); break; } } HorizontalContainer container = new HorizontalContainer(DrawAreaX, DrawAreaY + figure_size + 0.16, 0.8, 0.3); DrawableArea drawable_area; AddWidget(container); for (int i = 0; i < (int)Figures.Last; i++) { drawable_area = new DrawableArea(space_figures, 0.2); drawable_area.SelectedArea = new Rectangle(0, 0, figure_size, figure_size); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption(i); container.AddChild(drawable_area); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { int n = (int)e.Data; switch ((Figures)random_indices[n]) { case Figures.First: DrawDiamon(e.Context, 0, 0, CerclePosition.Right | CerclePosition.Left); break; case Figures.Second: DrawDiamon(e.Context, 0, 0, CerclePosition.Top | CerclePosition.Right); break; case Figures.Third: DrawDiamon(e.Context, 0, 0, CerclePosition.Bottom | CerclePosition.Top); break; default: throw new InvalidOperationException(); } e.Context.MoveTo(0.02, 0.25); e.Context.ShowPangoText(Answer.GetFigureName(n)); e.Context.Stroke(); }; } }
protected override void Initialize() { sum_offset = random.Next(3); random_indices = new ArrayListIndicesRandom(slices.Length / items_per_slice); random_indices.Initialize(); ans_pos = random.Next(possible_answers); Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; Answer.SetMultiOptionAnswer(ans_pos, Answer.GetFigureName(ans_pos)); bad_answers = new int [possible_answers * items_per_slice]; for (int i = 0; i < bad_answers.Length; i++) { bad_answers[i] = 1 + random.Next(9); } HorizontalContainer container = new HorizontalContainer(DrawAreaX, 0.62, 0.8, 0.3); DrawableArea drawable_area; AddWidget(container); for (int i = 0; i < possible_answers; i++) { drawable_area = new DrawableArea(0.8 / 3, 0.3); drawable_area.SelectedArea = new Rectangle(0, 0, radius, 0.2); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption(i); container.AddChild(drawable_area); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { int n = (int)e.Data; DrawSlice(e.Context, 0, 0); if (n == ans_pos) { int pos = random_indices [0]; DrawSliceText(e.Context, 0, 0, 0, (sum_offset + slices [pos * items_per_slice]).ToString(), (sum_offset + slices [1 + (pos * items_per_slice)]).ToString(), (sum_offset + slices [2 + (pos * items_per_slice)]).ToString()); } else { DrawSliceText(e.Context, 0, 0, 0, bad_answers [n * items_per_slice].ToString(), bad_answers [1 + (n * items_per_slice)].ToString(), bad_answers [2 + (n * items_per_slice)].ToString()); } e.Context.MoveTo(0.0, 0.25); e.Context.DrawTextCentered(radius / 2, 0.25, Answer.GetFigureName(n)); e.Context.Stroke(); }; } }
// Generates a new figure that was not generated before private FigureElement [] BuildFigure(ArrayList array, ArrayList figures) { bool done = false; FigureElement [] element = null; ArrayListIndicesRandom elements = new ArrayListIndicesRandom(array.Count); bool element_exists = false; while (done == false) { elements = RandomizeFromArray(array); element = new FigureElement [] { new FigureElement(pos1_x, pos1_y, (Element)elements[0]), new FigureElement(pos2_x, pos2_y, (Element)elements[1]), new FigureElement(pos3_x, pos3_y, (Element)elements[2]), new FigureElement(pos4_x, pos4_y, (Element)elements[3]), new FigureElement(pos5_x, pos5_y, (Element)elements[4]), new FigureElement(pos6_x, pos6_y, (Element)elements[5]), new FigureElement(pos7_x, pos7_y, (Element)elements[6]), }; for (int i = 0; i < figures.Count; i++) { FigureElement [] element2 = (FigureElement [])figures[i]; if (element.Length != element2.Length) { continue; } element_exists = true; for (int n = 0; n < element.Length; n++) { if (element[n].element != element2[n].element) { element_exists = false; break; } } if (element_exists == true) { break; } } if (element_exists == false) { done = true; } } return(element); }
protected override void Initialize() { int answers; int correct_answer; if (predicates == null) { LoadPredicates(); } question = random.Next(predicates.Length); correct_answer = predicates [question].answer_index; answers = predicates [question].options.Length; random_indices = new ArrayListIndicesRandom(answers - 1); random_indices.Initialize(); random_indices.Add(answers - 1); for (int i = 0; i < answers; i++) { if (random_indices[i] == correct_answer) { Answer.Correct = Answer.GetMultiOption(i); break; } } Container container = new Container(DrawAreaX, DrawAreaY + 0.15, 0.8, 0.6); AddWidget(container); for (int i = 0; i < predicates[question].options.Length; i++) { DrawableArea drawable_area = new DrawableArea(0.8, 0.12); drawable_area.X = DrawAreaX; drawable_area.Y = DrawAreaY + 0.15 + i * 0.18; container.AddChild(drawable_area); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption(i); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { int data = (int)e.Data; int option = random_indices [data]; e.Context.SetPangoNormalFontSize(); e.Context.DrawStringWithWrapping(0.05, 0.02, String.Format(Translations.GetString("{0}) {1}"), Answer.GetMultiOption(data), predicates[question].options[option].ToString()), 0.8 - DrawAreaX); e.Context.Stroke(); }; } }
private void RandomizeArcsOrder() { arcs_indices = new ArrayListIndicesRandom(num_arcs); arcs_indices.Initialize(); for (int i = 0; i < arcs_indices.Count; i++) { if (arcs_indices[i] == right_answer) { right_answer_pos = i; break; } } }
Figure[] StoreRandomOrder(List <Figure> prevfigures) { List <Figure> randomfigures = new List <Figure> (); ArrayListIndicesRandom random_indices = new ArrayListIndicesRandom(prevfigures.Count); random_indices.Initialize(); foreach (int idx in random_indices) { randomfigures.Add(prevfigures[idx]); } return(randomfigures.ToArray()); }
protected override void Initialize() { Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; random_indices = new ArrayListIndicesRandom((int)Figures.Last); random_indices.Initialize(); for (int i = 0; i < (int)Figures.Last; i++) { if ((Figures)random_indices[i] == Figures.FigureA) { Answer.SetMultiOptionAnswer(i, Answer.GetFigureName(i)); break; } } }
protected override void Initialize() { int answers; int correct_answer; if (predicates == null) LoadPredicates (); question = random.Next (predicates.Length); correct_answer = predicates [question].answer_index; answers = predicates [question].options.Length; random_indices = new ArrayListIndicesRandom (answers - 1); random_indices.Initialize (); random_indices.Add (answers - 1); for (int i = 0; i < answers; i++) { if (random_indices[i] == correct_answer) { Answer.Correct = Answer.GetMultiOption (i); break; } } Container container = new Container (DrawAreaX, DrawAreaY + 0.15, 0.8, 0.6); AddWidget (container); for (int i = 0; i < predicates[question].options.Length; i++) { DrawableArea drawable_area = new DrawableArea (0.8, 0.12); drawable_area.X = DrawAreaX; drawable_area.Y = DrawAreaY + 0.15 + i * 0.18; container.AddChild (drawable_area); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption (i); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { int data = (int) e.Data; int option = random_indices [data]; e.Context.SetPangoNormalFontSize (); e.Context.DrawStringWithWrapping (0.05, 0.02, String.Format (Translations.GetString ("{0}) {1}"), Answer.GetMultiOption (data), predicates[question].options[option].ToString ()), 0.8 - DrawAreaX); e.Context.Stroke (); }; } }
void RandomizeOptions(DrawingObject [] drawing_objects, int randomized_options) { OptionDrawingObject option; // Randomize the order of the options if (randomized_options > 0) { OptionDrawingObject [] originals; ArrayListIndicesRandom random_indices; int index = 0; random_indices = new ArrayListIndicesRandom(randomized_options); originals = new OptionDrawingObject [randomized_options]; random_indices.Initialize(); // Backup originals for (int i = 0; i < drawing_objects.Length; i++) { option = drawing_objects[i] as OptionDrawingObject; if (option == null) { continue; } originals[index] = option.Copy(); index++; } // Swap index = 0; for (int i = 0; i < drawing_objects.Length; i++) { option = drawing_objects[i] as OptionDrawingObject; if (option == null) { continue; } option.CopyRandomizedProperties(originals [random_indices [index]]); index++; } } }
void RandomizePossibleAnswers() { ArrayListIndicesRandom answers_random; answers_random = new ArrayListIndicesRandom(4); answers_random.Initialize(); answers = new FigureType [answers_random.Count]; for (int i = 0; i < answers.Length; i++) { answers [i] = (FigureType)answers_random [i]; if (figures[question_pos] == answers [i]) { answer_idx = i; } } }
protected override void Initialize() { ArrayListIndicesRandom figures_random; int pos = 0; switch (CurrentDifficulty) { case GameDifficulty.Easy: case GameDifficulty.Medium: figures_active = 6; rows = 2; columns = 3; break; case GameDifficulty.Master: figures_active = 9; columns = rows = 3; break; default: throw new InvalidOperationException(); } rect_w = 0.65 / columns; rect_h = 0.65 / rows; figures = new int [figures_active]; figures_random = new ArrayListIndicesRandom(FigureType.Total); figures_random.Initialize(); for (int n = 0; n < figures_active; n++) { figures[n] = figures_random [pos++]; if (pos >= figures_random.Count) { pos = 0; figures_random.Initialize(); } } question_pos = random.Next(figures_active); Answer.Correct = FigureType.ToString(figures[question_pos]); base.Initialize(); }
protected override void Initialize() { Answer.CheckAttributes |= GameAnswerCheckAttributes.MatchAll | GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; switch (CurrentDifficulty) { case GameDifficulty.Easy: total_figures = 6; space_figures = 0.26; break; case GameDifficulty.Medium: case GameDifficulty.Master: total_figures = 8; space_figures = 0.2; break; } random_indices_answers = new ArrayListIndicesRandom(total_figures); random_indices_answers.Initialize(); answers = new string[answer_num]; for (int i = 0; i < random_indices_answers.Count; i++) { switch ((Figures)random_indices_answers[i]) { case Figures.TriangleB: answers[0] = Answer.GetMultiOption(i); break; case Figures.TriangleC: answers[1] = Answer.GetMultiOption(i); break; case Figures.Square: answers[2] = Answer.GetMultiOption(i); break; } } Answer.Correct = answers[0] + " | " + answers[1] + " | " + answers[2]; Answer.CheckExpression = Answer.GetMultiOptionsExpression(); Answer.CorrectShow = answers[0] + answers[1] + answers[2]; }
protected override void Initialize() { bool done = false; switch (CurrentDifficulty) { case GameDifficulty.Easy: colors_shown = 3; break; case GameDifficulty.Medium: colors_shown = 4; break; case GameDifficulty.Master: colors_shown = 6; break; } palette = new ColorPalette(); // It is not acceptable that all the random colors names match the right colors while (done == false) { color_order = new ArrayListIndicesRandom(colors_shown); color_order.Initialize(); for (int i = 0; i < colors_shown; i++) { if (palette.Name(color_order [i]) != palette.Name(i)) { done = true; break; } } } question = random.Next(colors_shown); Answer.Correct = palette.Name(color_order [question]); question_colorname = palette.Name(question); base.Initialize(); }
protected override void Initialize() { int fact_idx, quest_idx, questions; ArrayListIndicesRandom indices; switch (CurrentDifficulty) { case GameDifficulty.Easy: questions = 1; break; default: case GameDifficulty.Medium: questions = 2; break; case GameDifficulty.Master: questions = 3; break; } indices = new ArrayListIndicesRandom(total_questions); indices.Initialize(); facts = new Fact [questions]; base.Initialize(); for (int i = 0; i < facts.Length; i++) { facts[i] = GetFact(indices[i]); } fact_idx = random.Next(questions); quest_idx = random.Next(facts [fact_idx].Length); question = facts [fact_idx].questions [quest_idx]; Answer.Correct = (facts [fact_idx].answers [quest_idx]).ToString(); Answer.CheckExpression = "[0-9]+"; // Since this particular test requires to read and understand text // lets give the user twice time to be able to understand the text properly TotalTime = TotalTime * 2; }
protected override void Initialize() { question_indices = new ArrayListIndicesRandom(question_columns); question_indices.Initialize(); answer_indices = new ArrayListIndicesRandom(possible_answers); answer_indices.Initialize(); Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; BuildPossibleAnswers(); const double total_width = 0.8, total_height = 0.42; HorizontalContainer container = new HorizontalContainer(DrawAreaX, 0.52, total_width, total_height); AddWidget(container); // Possible answers columns for (int ans = 0; ans < possible_answers; ans++) { DrawableArea drawable_area = new DrawableArea(total_width / possible_answers, total_height); drawable_area.Data = ans; drawable_area.DataEx = Answer.GetMultiOption(ans); container.AddChild(drawable_area); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { double width = total_width / possible_answers; double x = (width - figure_size) / 2, y = 0; int column = (int)e.Data; for (int figure = 0; figure < figures_column; figure++) { DrawFigure(e.Context, x, y, figure_answers [(column * figures_column) + figure]); y += figure_size + space_height; } e.Context.DrawTextCentered(width / 2, total_height - 0.02, Answer.GetFigureName(column)); e.Context.Stroke(); }; } Answer.SetMultiOptionAnswer(answer_indices[good_answer], Answer.GetFigureName(answer_indices[good_answer])); }
protected override void Initialize() { int first_letter; ArrayListIndicesRandom first_letters; first_letters = new ArrayListIndicesRandom (figures); // Make sure that the first letter is never the same first_letters.Initialize (); step = random.Next (3) + 3; characters = new char [(1 + figures) * 4]; for (int figure = 0; figure < figures; figure++) { first_letter = first_letters [figure]; for (int letter = 0; letter < 4; letter++) { characters[(figure * 4) + letter] = (char) (65 + first_letter + (step * letter)); } } Answer.Correct = ToStr (characters[((figures - 1) * 4) + 3]); characters[((figures - 1) * 4) + 3] = '?'; }
void RandomizeFigures() { ArrayListIndicesRandom figures_random; int pos = 0; figures = new FigureType [figures_active]; figures_random = new ArrayListIndicesRandom((int)FigureType.Total); figures_random.Initialize(); for (int n = 0; n < figures_active; n++) { figures[n] = (FigureType)figures_random [pos++]; if (pos >= figures_random.Count) { pos = 0; figures_random.Initialize(); } } }
private ArrayListIndicesRandom RandomizeFromArray(ArrayList ar) { int index; object [] array = (object [])ar.ToArray(typeof(object)); ArrayListIndicesRandom elements = new ArrayListIndicesRandom(ar.Count); int left = ar.Count; elements.Clear(); // Generate a random number that can be as big as the maximum -1 // Add the random element picked up element in the list // The element just randomized gets out of pending list and replaced by the maximum -1 element for (int i = 0; i < ar.Count; i++, left--) { index = random.Next(left); elements.Add((int)array[index]); array[index] = array[left - 1]; } return(elements); }
protected override void Initialize() { Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; random_indices_questions = new ArrayListIndicesRandom(4); random_indices_questions.Initialize(); random_indices_answers = new ArrayListIndicesRandom(3); random_indices_answers.Initialize(); for (int i = 0; i < random_indices_answers.Count; i++) { if (random_indices_answers [i] == 0) { Answer.SetMultiOptionAnswer(i, Answer.GetFigureName(i)); break; } } HorizontalContainer container = new HorizontalContainer(0.1, 0.5, 0.8, 0.4); DrawableArea drawable_area; AddWidget(container); for (int i = 0; i < 3; i++) { drawable_area = new DrawableArea(0.8 / 3, 0.4); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption(i); container.AddChild(drawable_area); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { int n = (int)e.Data; DrawAnswerFigures(e.Context, 0.05, 0.2, random_indices_answers [n]); e.Context.MoveTo(0.05, 0.33); e.Context.ShowPangoText(Answer.GetFigureName(n)); }; } }
protected override void Initialize() { Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; possible_answers = new ArrayListIndicesRandom(3); possible_answers.Initialize(); puzzle_index = random.Next(puzzles.Length); puzzle = puzzles [puzzle_index]; DrawableArea drawable_area; HorizontalContainer container = new HorizontalContainer(0.05, 0.5, 0.9, figure_size + 0.1); AddWidget(container); for (int i = 0; i < possible_answers.Count; i++) { drawable_area = new DrawableArea(figure_size + space_figures, figure_size + 0.1); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption(i); drawable_area.SelectedArea = new Rectangle(space_figures / 2, space_figures / 2, figure_size, figure_size); container.AddChild(drawable_area); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { DrawPossibleAnswer(e.Context, space_figures / 2, space_figures / 2, possible_answers [(int)e.Data]); e.Context.DrawTextCentered(space_figures / 2 + figure_size / 2, space_figures + figure_size + 0.02, Answer.GetFigureName((int)e.Data)); }; } for (int i = 0; i < possible_answers.Count; i++) { if (possible_answers[i] == 0) { Answer.SetMultiOptionAnswer(i, Answer.GetFigureName(i)); break; } } }
protected override void Initialize() { int first_letter; ArrayListIndicesRandom first_letters; first_letters = new ArrayListIndicesRandom(figures); // Make sure that the first letter is never the same first_letters.Initialize(); step = random.Next(3) + 3; characters = new char [(1 + figures) * 4]; for (int figure = 0; figure < figures; figure++) { first_letter = first_letters [figure]; for (int letter = 0; letter < 4; letter++) { characters[(figure * 4) + letter] = (char)(65 + first_letter + (step * letter)); } } Answer.Correct = ToStr(characters[((figures - 1) * 4) + 3]); characters[((figures - 1) * 4) + 3] = '?'; }
protected override void Initialize() { int tmp; animals = new List <string> (); animals.Add("dog"); animals.Add("cat"); animals.Add("rat"); animals.Add("bird"); animals.Add("sardine"); animals.Add("trout"); animals.Add("monkfish"); animals.Add("cod"); animals.Add("salmon"); switch (CurrentDifficulty) { case GameDifficulty.Easy: showed = 4; break; case GameDifficulty.Medium: showed = 6; break; case GameDifficulty.Master: showed = 8; break; } animals_order = new ArrayListIndicesRandom(animals.Count); animals_order.Initialize(); answer = random.Next(showed); tmp = animals_order [answer]; Answer.Correct = animals [tmp]; base.Initialize(); }
protected override void Initialize() { Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; random_indices_questions = new ArrayListIndicesRandom (4); random_indices_questions.Initialize (); random_indices_answers = new ArrayListIndicesRandom (3); random_indices_answers.Initialize (); for (int i = 0; i < random_indices_answers.Count; i++) { if (random_indices_answers [i] == 0) { Answer.SetMultiOptionAnswer (i, Answer.GetFigureName (i)); break; } } HorizontalContainer container = new HorizontalContainer (0.1, 0.5, 0.8, 0.4); DrawableArea drawable_area; AddWidget (container); for (int i = 0; i < 3; i++) { drawable_area = new DrawableArea (0.8 / 3, 0.4); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption (i); container.AddChild (drawable_area); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { int n = (int) e.Data; DrawAnswerFigures (e.Context, 0.05, 0.2, random_indices_answers [n]); e.Context.MoveTo (0.05, 0.33); e.Context.ShowPangoText (Answer.GetFigureName (n)); }; } }
protected override void Initialize() { ArrayListIndicesRandom random_indices = new ArrayListIndicesRandom(total_slices); Color clr; cp = new ColorPalette(Translations); Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; cercle_colors = new Color [total_slices]; badcercle_colors = new Color [total_slices]; for (int i = 0; i < total_slices; i++) { cercle_colors [i] = cp.Cairo(i); badcercle_colors [i] = cp.Cairo(i); } // Correct answer random_indices.Initialize(); clr = badcercle_colors [random_indices[0]]; badcercle_colors [random_indices[0]] = badcercle_colors [random_indices[1]]; badcercle_colors [random_indices[1]] = clr; // Create random color order for the session start_indices = new int [circles]; for (int i = 0; i < circles; i++) { start_indices[i] = (random_indices[i]); } ans_pos = random.Next(circles); Answer.SetMultiOptionAnswer(ans_pos, Answer.GetFigureName(ans_pos)); const double text_offset = 0.04; const double witdh_used = 0.9; // Total width used for drawing all the figures const double margin = 0.1 / circles / 2; const double box_size = witdh_used / circles; double y; HorizontalContainer container; DrawableArea drawable_area; Color [] colors; y = DrawAreaY + 0.1 + (radius / 2); container = new HorizontalContainer(0.05, y, witdh_used, box_size); AddWidget(container); circle_parameters = new CircleParameters [circles]; for (int i = 0; i < circles; i++) { if (ans_pos == i) { colors = badcercle_colors; } else { colors = cercle_colors; } circle_parameters [i] = new CircleParameters(colors); drawable_area = new DrawableArea(box_size, box_size); drawable_area.SelectedArea = new Rectangle((box_size - box_size) / 2, 0, box_size, box_size); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption(i); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { int idx = (int)e.Data; CircleParameters circle = circle_parameters [idx]; double x1, y1; x1 = y1 = radius + margin; DrawCircle(e.Context, x1, y1, circle.Colors, start_indices [idx]); e.Context.DrawTextCentered(e.Width / 2, box_size + text_offset, Answer.GetFigureName(idx)); e.Context.Stroke(); }; container.AddChild(drawable_area); } }
protected override void Initialize() { Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; palette = new ColorPalette(); switch (random.Next(2)) { case 0: quest1 = g1question_A; quest2 = g1question_B; answer = g1answer; ranswer = g1rightanswer; break; case 1: quest1 = g2question_A; quest2 = g2question_B; answer = g2answer; ranswer = g2rightanswer; break; } random_indices = new ArrayListIndicesRandom(answers); random_indices.Initialize(); for (int i = 0; i < answers; i++) { if (random_indices[i] == ranswer) { Answer.SetMultiOptionAnswer(i, Answer.GetFigureName(i)); break; } } double x = DrawAreaX, y = DrawAreaY; // Question DrawableArea drawable_area; HorizontalContainer container = new HorizontalContainer(x, y, 0.8, 0.3); AddWidget(container); drawable_area = new DrawableArea(container.Width / 2, 0.25); drawable_area.Sensitive = false; container.AddChild(drawable_area); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { DrawSquare(e.Context, 0.15, 0); }; drawable_area = new DrawableArea(container.Width / 2, 0.25); drawable_area.Sensitive = false; container.AddChild(drawable_area); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { DrawLShape(e.Context, 0.15, 0); }; // Answers y += 0.28; container = new HorizontalContainer(x, y, 0.8, 0.3); AddWidget(container); for (int i = 0; i < 2; i++) { drawable_area = new DrawableArea(container.Width / 2, 0.25); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption(i); container.AddChild(drawable_area); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { int n = (int)e.Data; DrawPossibleAnswer(e.Context, 0.12, 0.03, answer, random_indices [n], n); e.Context.DrawTextCentered(drawable_area.Width / 2, 0.22, Answer.GetFigureName(n)); e.Context.Stroke(); }; } container = new HorizontalContainer(x, y + 0.3, 0.8, 0.3); AddWidget(container); for (int i = 2; i < 4; i++) { drawable_area = new DrawableArea(container.Width / 2, 0.25); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption(i); container.AddChild(drawable_area); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { int n = (int)e.Data; DrawPossibleAnswer(e.Context, 0.12, 0.03, answer, random_indices [n], n); e.Context.DrawTextCentered(drawable_area.Width / 2, 0.22, Answer.GetFigureName(n)); e.Context.Stroke(); }; } }
protected override void Initialize() { Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; palette = new ColorPalette (); switch (random.Next (2)) { case 0: quest1 = g1question_A; quest2 = g1question_B; answer = g1answer; ranswer = g1rightanswer; break; case 1: quest1 = g2question_A; quest2 = g2question_B; answer = g2answer; ranswer = g2rightanswer; break; } random_indices = new ArrayListIndicesRandom (answers); random_indices.Initialize (); for (int i = 0; i < answers; i++) { if (random_indices[i] == ranswer) { Answer.SetMultiOptionAnswer (i, Answer.GetFigureName (i)); break; } } double x = DrawAreaX, y = DrawAreaY; // Question DrawableArea drawable_area; HorizontalContainer container = new HorizontalContainer (x, y, 0.8, 0.3); AddWidget (container); drawable_area = new DrawableArea (container.Width / 2, 0.25); drawable_area.Sensitive = false; container.AddChild (drawable_area); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { DrawSquare (e.Context, 0.15, 0); }; drawable_area = new DrawableArea (container.Width / 2, 0.25); drawable_area.Sensitive = false; container.AddChild (drawable_area); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { DrawLShape (e.Context, 0.15, 0); }; // Answers y += 0.28; container = new HorizontalContainer (x, y, 0.8, 0.3); AddWidget (container); for (int i = 0; i < 2; i++) { drawable_area = new DrawableArea (container.Width / 2, 0.25); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption (i); container.AddChild (drawable_area); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { int n = (int) e.Data; DrawPossibleAnswer (e.Context, 0.12, 0.03, answer, random_indices [n], n); e.Context.DrawTextCentered (drawable_area.Width / 2, 0.22, Answer.GetFigureName (n)); e.Context.Stroke (); }; } container = new HorizontalContainer (x, y + 0.3, 0.8, 0.3); AddWidget (container); for (int i = 2; i < 4; i++) { drawable_area = new DrawableArea (container.Width / 2, 0.25); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption (i); container.AddChild (drawable_area); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { int n = (int) e.Data; DrawPossibleAnswer (e.Context, 0.12, 0.03, answer, random_indices [n], n); e.Context.DrawTextCentered (drawable_area.Width / 2, 0.22, Answer.GetFigureName (n)); e.Context.Stroke (); }; } }
protected override void Initialize() { Answer.CheckAttributes |= GameAnswerCheckAttributes.MatchAll | GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; switch (CurrentDifficulty) { case GameDifficulty.Easy: total_figures = 6; space_figures = 0.26; break; case GameDifficulty.Medium: case GameDifficulty.Master: total_figures = 8; space_figures = 0.2; break; } random_indices_answers = new ArrayListIndicesRandom (total_figures); random_indices_answers.Initialize (); answers = new string[answer_num]; for (int i = 0; i < random_indices_answers.Count; i++) { switch ((Figures) random_indices_answers[i]) { case Figures.TriangleB: answers[0] = Answer.GetMultiOption (i); break; case Figures.TriangleC: answers[1] = Answer.GetMultiOption (i); break; case Figures.Square: answers[2] = Answer.GetMultiOption (i); break; } } Answer.Correct = answers[0] + " | " + answers[1] + " | " + answers[2]; Answer.CheckExpression = Answer.GetMultiOptionsExpression (); Answer.CorrectShow = answers[0] + answers[1] + answers[2]; }
void RandomizePossibleAnswers() { ArrayListIndicesRandom answers_random; answers_random = new ArrayListIndicesRandom (4); answers_random.Initialize (); answers = new FigureType [answers_random.Count]; for (int i = 0; i < answers.Length; i++) { answers [i] = (FigureType) answers_random [i]; if (figures[question_pos] == answers [i]) { answer_idx = i; } } }
protected override void Initialize() { indications = new Indication [CurrentDifficulty == GameDifficulty.Easy ? 5 : 7]; Indication.TurnDirection second_turn = (Indication.TurnDirection) 2 + random.Next (2); indications[0] = new Indication (Translations, Indication.Type.Start, 0); indications[1] = new Indication (Translations, Indication.Type.Turn, random.Next (2)); // right or left indications[2] = new Indication (Translations, Indication.Type.Turn, second_turn); // up or down indications[3] = new Indication (Translations, Indication.Type.Turn, random.Next (2)); // right or left Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; if (CurrentDifficulty==GameDifficulty.Easy) { indications[4] = new Indication (Translations, Indication.Type.End, 1); } else { if (second_turn == Indication.TurnDirection.Up) indications[4] = new Indication (Translations, Indication.Type.Turn, Indication.TurnDirection.Up); else indications[4] = new Indication (Translations, Indication.Type.Turn, Indication.TurnDirection.Down); indications[5] = new Indication (Translations, Indication.Type.Turn, random.Next (2)); // right or left indications[6] = new Indication (Translations, Indication.Type.End, 1); } indications_wrongA = CopyAnswer (); indications_wrongB = CopyAnswer (); indications_wrongC = CopyAnswer (); if ((Indication.TurnDirection) indications[3].obj == Indication.TurnDirection.Right) { indications_wrongA[3] = new Indication (Translations, Indication.Type.Turn, Indication.TurnDirection.Left); } else { indications_wrongA[3] = new Indication (Translations, Indication.Type.Turn, Indication.TurnDirection.Right); } if (CurrentDifficulty == GameDifficulty.Easy) { if ((Indication.TurnDirection) indications[2].obj == Indication.TurnDirection.Up) { indications_wrongB[2] = new Indication (Translations, Indication.Type.Turn, Indication.TurnDirection.Down); } else { indications_wrongB[2] = new Indication (Translations, Indication.Type.Turn, Indication.TurnDirection.Up); } } else { if ((Indication.TurnDirection) indications[5].obj == Indication.TurnDirection.Right) { indications_wrongB[5] = new Indication (Translations, Indication.Type.Turn, Indication.TurnDirection.Left); } else { indications_wrongB[5] = new Indication (Translations, Indication.Type.Turn, Indication.TurnDirection.Right); } } if ((Indication.TurnDirection) indications[1].obj == Indication.TurnDirection.Right) { indications_wrongC[1] = new Indication (Translations, Indication.Type.Turn, Indication.TurnDirection.Left); } else { indications_wrongC[1] = new Indication (Translations, Indication.Type.Turn, Indication.TurnDirection.Right); } base.Initialize (); answers = new ArrayListIndicesRandom (4); answers.Initialize (); for (int i = 0; i < answers.Count; i++) { if (answers [i] == 0) { Answer.SetMultiOptionAnswer (i, Answer.GetFigureName (i)); ans = i; break; } } // Draw row 1 HorizontalContainer container = new HorizontalContainer (0.05, 0.1, 0.9, 0.4); AddWidget (container); for (int i = 0; i < 2; i++) { DrawableArea drawable_area = new DrawableArea (0.45, 0.4); container.AddChild (drawable_area); drawable_area.SelectedArea = new Rectangle (0, 0, 0.45, 0.3); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption (i); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { int n = (int) e.Data; DrawPossibleAnswers (e.Context, 0.2, 0.1, WhichAnswer (answers[n])); e.Context.MoveTo (0.2, 0.12 + 0.2); e.Context.ShowPangoText (Answer.GetFigureName (n)); }; } // Draw row 2 container = new HorizontalContainer (0.05, 0.5, 0.9, 0.4); AddWidget (container); for (int i = 2; i < 4; i++) { DrawableArea drawable_area = new DrawableArea (0.45, 0.4); container.AddChild (drawable_area); drawable_area.SelectedArea = new Rectangle (0, 0, 0.45, 0.3); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption (i); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { int n = (int) e.Data; DrawPossibleAnswers (e.Context, 0.2, 0.1, WhichAnswer (answers[n])); e.Context.MoveTo (0.2, 0.12 + 0.2); e.Context.ShowPangoText (Answer.GetFigureName (n)); }; } }
protected override void Initialize() { random_indices = new ArrayListIndicesRandom(figures); random_indices.Initialize(); Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; for (int i = 0; i < random_indices.Count; i++) { if (random_indices[i] != answer_index) { continue; } Answer.SetMultiOptionAnswer(i, Answer.GetFigureName(i)); break; } const double text_offset = 0.04; double x = DrawAreaX, y = DrawAreaY + 0.1, box_size = (1 - (DrawAreaX * 2)) / 3; HorizontalContainer container1, container2, container = null; DrawableArea drawable_area; for (int figure = 0; figure < figures; figure++) { switch (figure) { case 0: x = DrawAreaX; container1 = new HorizontalContainer(x, y, 0.8, figure_size); container = container1; AddWidget(container); break; case 3: x = DrawAreaX; y += 0.4; container2 = new HorizontalContainer(x, y, 0.8, figure_size); container = container2; AddWidget(container); break; default: break; } drawable_area = new DrawableArea(box_size, figure_size); drawable_area.SelectedArea = new Rectangle((box_size - figure_size) / 2, 0, figure_size, figure_size); drawable_area.Data = figure; drawable_area.DataEx = Answer.GetMultiOption(figure); switch (random_indices[figure]) { case 0: drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { DrawTriangle(e.Context, (e.Width - figure_size) / 2, 0); e.Context.DrawTextCentered(e.Width / 2, figure_size + text_offset, Answer.GetFigureName((int)e.Data)); }; break; case 1: drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { DrawDiamon(e.Context, (e.Width - figure_size) / 2, 0); e.Context.DrawTextCentered(e.Width / 2, figure_size + text_offset, Answer.GetFigureName((int)e.Data)); }; break; case 2: drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { DrawRectangleWithTriangles(e.Context, (e.Width - figure_size) / 2, 0); e.Context.DrawTextCentered(e.Width / 2, figure_size + text_offset, Answer.GetFigureName((int)e.Data)); }; break; case 3: drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { DrawThreeTriangles(e.Context, (e.Width - figure_size) / 2, 0); e.Context.DrawTextCentered(e.Width / 2, figure_size + text_offset, Answer.GetFigureName((int)e.Data)); }; break; case answer_index: drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { DrawRectangleWithCross(e.Context, (e.Width - figure_size) / 2, 0); e.Context.DrawTextCentered(e.Width / 2, figure_size + text_offset, Answer.GetFigureName((int)e.Data)); }; break; } container.AddChild(drawable_area); x += box_size; } }
protected override void Initialize() { int options_next, random_max, which = 0; Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption; switch (CurrentDifficulty) { case GameDifficulty.Easy: random_max = 30; break; default: case GameDifficulty.Medium: random_max = 50; break; case GameDifficulty.Master: random_max = 80; break; } do { // Fraction num = 10 + random.Next(random_max); den = 2 + random.Next(random_max / 5); percentage = 10 + random.Next(random_max); correct = percentage / 100d * num / den; } while (correct < 1); options = new double [options_cnt]; options_next = 0; options [options_next++] = correct; options [options_next++] = percentage / 70d * num / den; options [options_next++] = percentage / 120d * num / den; options [options_next] = percentage / 150d * num / den; random_indices = new ArrayListIndicesRandom(options_cnt); random_indices.Initialize(); for (int i = 0; i < options_cnt; i++) { if (random_indices [i] == correct_pos) { which = i; break; } } Answer.SetMultiOptionAnswer(which, String.Format("{0:##0.##}", options[which])); // Options double x = DrawAreaX + 0.25, y = DrawAreaY + 0.16; Container container = new Container(x, y, 1 - (x * 2), 0.6); AddWidget(container); for (int i = 0; i < options_cnt; i++) { DrawableArea drawable_area = new DrawableArea(0.3, 0.1); drawable_area.X = x; drawable_area.Y = y + i * 0.15; container.AddChild(drawable_area); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption(i); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { int n = (int)e.Data; int indx = random_indices[n]; e.Context.SetPangoLargeFontSize(); e.Context.MoveTo(0.02, 0.02); e.Context.ShowPangoText(String.Format("{0}) {1:##0.##}", Answer.GetMultiOption(n), options [indx])); }; } }
Figure[] StoreRandomOrder(List <Figure> prevfigures) { List <Figure> randomfigures = new List <Figure> (); ArrayListIndicesRandom random_indices = new ArrayListIndicesRandom (prevfigures.Count); random_indices.Initialize (); foreach (int idx in random_indices) { randomfigures.Add(prevfigures[idx]); } return randomfigures.ToArray (); }
// Taking a GameLocator list builds the play_list void BuildPlayList(List <GameLocator> all_games) { if ((game_type & GameSession.Types.Custom) == GameSession.Types.Custom) throw new InvalidOperationException (); play_list.Clear (); ArrayListIndicesRandom indices = new ArrayListIndicesRandom (all_games.Count); indices.Initialize (); List <int> logic_indices = new List <int> (cnt_logic); List <int> calculation_indices = new List <int> (cnt_calculation); List <int> memory_indices = new List <int> (cnt_memory); List <int> verbal_indices = new List <int> (cnt_verbal); bool logic, memory, calculation, verbal; // Decide which game_types are part of the game if ((game_type & GameSession.Types.AllGames) == GameSession.Types.AllGames) { logic = memory = calculation = verbal = true; } else { logic = (game_type & GameSession.Types.LogicPuzzles) == GameSession.Types.LogicPuzzles; calculation = (game_type & GameSession.Types.Calculation) == GameSession.Types.Calculation; memory = (game_type & GameSession.Types.Memory) == GameSession.Types.Memory; verbal = (game_type & GameSession.Types.VerbalAnalogies) == GameSession.Types.VerbalAnalogies; } // Create arrays by game type for (int n = 0; n < all_games.Count; n++) { switch (all_games [indices [n]].GameType) { case GameTypes.LogicPuzzle: if (logic) logic_indices.Add (indices [n]); break; case GameTypes.Memory: if (memory) memory_indices.Add (indices [n]); break; case GameTypes.Calculation: if (calculation) calculation_indices.Add (indices [n]); break; case GameTypes.VerbalAnalogy: if (verbal) verbal_indices.Add (indices [n]); break; default: throw new InvalidOperationException ("Unknown value"); } } int total = logic_indices.Count + memory_indices.Count + calculation_indices.Count + verbal_indices.Count; int pos_logic, pos_memory, pos_calculation, pos_verbal; Random random = new Random (); pos_logic = pos_memory = pos_calculation = pos_verbal = 0; while (play_list.Count < total) { switch (random.Next (3)) { case 0: if (pos_calculation < calculation_indices.Count) play_list.Add (calculation_indices[pos_calculation++]); if (pos_logic < logic_indices.Count) play_list.Add (logic_indices[pos_logic++]); if (pos_memory < memory_indices.Count) play_list.Add (memory_indices[pos_memory++]); if (pos_verbal < verbal_indices.Count) play_list.Add (verbal_indices[pos_verbal++]); break; case 1: if (pos_memory < memory_indices.Count) play_list.Add (memory_indices[pos_memory++]); if (pos_calculation < calculation_indices.Count) play_list.Add (calculation_indices[pos_calculation++]); if (pos_verbal < verbal_indices.Count) play_list.Add (verbal_indices[pos_verbal++]); if (pos_logic < logic_indices.Count) play_list.Add (logic_indices[pos_logic++]); break; case 2: if (pos_calculation < calculation_indices.Count) play_list.Add (calculation_indices[pos_calculation++]); if (pos_verbal < verbal_indices.Count) play_list.Add (verbal_indices[pos_verbal++]); if (pos_memory < memory_indices.Count) play_list.Add (memory_indices[pos_memory++]); if (pos_logic < logic_indices.Count) play_list.Add (logic_indices[pos_logic++]); break; } } enumerator = play_list.GetEnumerator (); }
protected override void Initialize() { random_indices = new ArrayListIndicesRandom (figures); random_indices.Initialize (); Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; for (int i = 0; i < random_indices.Count; i++) { if (random_indices[i] != answer_index) continue; Answer.SetMultiOptionAnswer (i, Answer.GetFigureName (i)); break; } const double text_offset = 0.04; double x = DrawAreaX, y = DrawAreaY + 0.1, box_size = (1 - (DrawAreaX * 2)) / 3; HorizontalContainer container1, container2, container = null; DrawableArea drawable_area; for (int figure = 0; figure < figures; figure++) { switch (figure) { case 0: x = DrawAreaX; container1 = new HorizontalContainer (x, y, 0.8, figure_size); container = container1; AddWidget (container); break; case 3: x = DrawAreaX; y += 0.4; container2 = new HorizontalContainer (x, y, 0.8, figure_size); container = container2; AddWidget (container); break; default: break; } drawable_area = new DrawableArea (box_size, figure_size); drawable_area.SelectedArea = new Rectangle ((box_size - figure_size) / 2, 0, figure_size, figure_size); drawable_area.Data = figure; drawable_area.DataEx = Answer.GetMultiOption (figure); switch (random_indices[figure]) { case 0: drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { DrawTriangle (e.Context, (e.Width - figure_size) / 2, 0); e.Context.DrawTextCentered (e.Width / 2, figure_size + text_offset, Answer.GetFigureName ((int) e.Data)); }; break; case 1: drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { DrawDiamon (e.Context, (e.Width - figure_size) / 2, 0); e.Context.DrawTextCentered (e.Width / 2, figure_size + text_offset, Answer.GetFigureName ((int) e.Data)); }; break; case 2: drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { DrawRectangleWithTriangles (e.Context, (e.Width - figure_size) / 2, 0); e.Context.DrawTextCentered (e.Width / 2, figure_size + text_offset, Answer.GetFigureName ((int) e.Data)); }; break; case 3: drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { DrawThreeTriangles (e.Context, (e.Width - figure_size) / 2, 0); e.Context.DrawTextCentered (e.Width / 2, figure_size + text_offset, Answer.GetFigureName ((int) e.Data)); }; break; case answer_index: drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { DrawRectangleWithCross (e.Context, (e.Width - figure_size) / 2, 0); e.Context.DrawTextCentered (e.Width / 2, figure_size + text_offset, Answer.GetFigureName ((int) e.Data)); }; break; } container.AddChild (drawable_area); x += box_size; } }
protected override void Initialize() { Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; switch (CurrentDifficulty) { case GameDifficulty.Easy: columns = rows = 2; break; case GameDifficulty.Medium: columns = rows = 3; break; case GameDifficulty.Master: columns = rows = 4; break; } rect_w = 0.3 / rows; rect_h = 0.3 / columns; squares = rows * columns; numbers = new int [squares * 4]; for (int n = 0; n < rows; n++) for (int i = 0; i < columns; i++) numbers[(n*columns) + i] = random.Next (10) + random.Next (5); Randomize (numbers, 0, squares); Randomize (numbers, 0, squares * 2); Randomize (numbers, 0, squares * 3); answers_order = new ArrayListIndicesRandom (answers); answers_order.Initialize (); for (int i = 0; i < answers_order.Count; i++) { if ((int) answers_order[i] == 0) { Answer.SetMultiOptionAnswer (i, Answer.GetFigureName (i)); break; } } base.Initialize (); HorizontalContainer container = new HorizontalContainer (DrawAreaX, DrawAreaY, 0.8, 0.4); AddWidget (container); for (int i = 0; i < answers_order.Count; i++) { if (i == 2) { container = new HorizontalContainer (DrawAreaX, DrawAreaY + 0.45, 0.8, 0.4); AddWidget (container); } DrawableArea drawable_area = new DrawableArea (0.4, 0.4); container.AddChild (drawable_area); drawable_area.SelectedArea = new Rectangle (0.05, 0, 0.3, 0.3); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption (i); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { int n = (int) e.Data; DrawSquare (e.Context, 0.05, 0, numbers, squares * answers_order[n]); e.Context.MoveTo (0.05, block_space - 0.02); e.Context.ShowPangoText (Answer.GetFigureName (n)); e.Context.Stroke (); }; } }
protected override void Initialize() { ArrayListIndicesRandom random_indices = new ArrayListIndicesRandom (total_slices); Color clr; cp = new ColorPalette (); Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; cercle_colors = new Color [total_slices]; badcercle_colors = new Color [total_slices]; for (int i = 0; i < total_slices; i++) { cercle_colors [i] = cp.Cairo (i); badcercle_colors [i] = cp.Cairo (i); } // Correct answer random_indices.Initialize (); clr = badcercle_colors [random_indices[0]]; badcercle_colors [random_indices[0]] = badcercle_colors [random_indices[1]]; badcercle_colors [random_indices[1]] = clr; // Create random color order for the session start_indices = new int [circles]; for (int i = 0; i < circles; i++) start_indices[i] = (random_indices[i]); ans_pos = random.Next (circles); Answer.SetMultiOptionAnswer (ans_pos, Answer.GetFigureName (ans_pos)); const double text_offset = 0.04; const double witdh_used = 0.9; // Total width used for drawing all the figures const double margin = 0.1 / circles / 2; const double box_size = witdh_used / circles; double y; HorizontalContainer container; DrawableArea drawable_area; Color [] colors; y = DrawAreaY + 0.1 + (radius / 2); container = new HorizontalContainer (0.05, y, witdh_used, box_size); AddWidget (container); circle_parameters = new CircleParameters [circles]; for (int i = 0; i < circles; i++) { if (ans_pos == i) colors = badcercle_colors; else colors = cercle_colors; circle_parameters [i] = new CircleParameters (colors); drawable_area = new DrawableArea (box_size, box_size); drawable_area.SelectedArea = new Rectangle ((box_size - box_size) / 2, 0, box_size, box_size); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption (i); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { int idx = (int) e.Data; CircleParameters circle = circle_parameters [idx]; double x1, y1; x1 = y1 = radius + margin; DrawCircle (e.Context, x1, y1, circle.Colors, start_indices [idx]); e.Context.DrawTextCentered (e.Width / 2, box_size + text_offset, Answer.GetFigureName (idx)); e.Context.Stroke (); }; container.AddChild (drawable_area); } }
protected override void Initialize() { double pos_x = 0, sel_width; Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption; gametype = (GameType) random.Next ((int) GameType.Last + 1); switch (gametype) { case GameType.Equations: pos_x = 0.1; sel_width = 0.5; equations = equations_a; break; case GameType.Numbers: { int num, evens; int [] seeds = {25, 26, 28, 30, 18, 21, 22}; ArrayListIndicesRandom random_seeds = new ArrayListIndicesRandom (seeds.Length); pos_x = 0.2; sel_width = 0.32; // Make sure that one of the numbers only is not even or odd to avoid // this rationale as valid answer too do { evens = 0; random_seeds.Initialize (); equations = new string [max_equations]; for (int i = 0; i < max_equations - 1; i++) { num = seeds [random_seeds [i]]; equations [i] = num.ToString () + (num * num).ToString (); if (num % 2 == 0) evens++; } num = seeds [random_seeds [max_equations - 1]]; equations [max_equations - 1] = num.ToString () + ((num * num) - 20).ToString (); if (num % 2 == 0) evens++; } while (evens <= 1 || max_equations - evens <= 1 /* odds */); break; } default: throw new InvalidOperationException (); } random_indices = new ArrayListIndicesRandom (equations.Length); random_indices.Initialize (); for (int i = 0; i < random_indices.Count; i++) { if (random_indices[i] == wrong_answer) { Answer.SetMultiOptionAnswer (i, Answer.GetFigureName (i)); break; } } Container container = new Container (DrawAreaX + pos_x, DrawAreaY + 0.2, 0.5, random_indices.Count * 0.1); AddWidget (container); for (int i = 0; i < random_indices.Count; i++) { DrawableArea drawable_area = new DrawableArea (sel_width, 0.1); drawable_area.X = DrawAreaX + pos_x; drawable_area.Y = DrawAreaY + 0.2 + i * 0.1; container.AddChild (drawable_area); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption (i); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { int n = (int) e.Data; e.Context.SetPangoLargeFontSize (); e.Context.MoveTo (0.05, 0.02); // Translators: this "option) answer" for example "a) "21 x 60 = 1260". This should not be changed for most of the languages e.Context.ShowPangoText (String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("{0}) {1}"), Answer.GetMultiOption (n), equations [random_indices[n]])); }; } }
protected override void Initialize() { double pos_x = 0, sel_width; Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption; gametype = (GameType)random.Next((int)GameType.Last + 1); switch (gametype) { case GameType.Equations: pos_x = 0.1; sel_width = 0.5; equations = equations_a; break; case GameType.Numbers: { int num, evens; int [] seeds = { 25, 26, 28, 30, 18, 21, 22 }; ArrayListIndicesRandom random_seeds = new ArrayListIndicesRandom(seeds.Length); pos_x = 0.2; sel_width = 0.32; // Make sure that one of the numbers only is not even or odd to avoid // this rationale as valid answer too do { evens = 0; random_seeds.Initialize(); equations = new string [max_equations]; for (int i = 0; i < max_equations - 1; i++) { num = seeds [random_seeds [i]]; equations [i] = num.ToString() + (num * num).ToString(); if (num % 2 == 0) { evens++; } } num = seeds [random_seeds [max_equations - 1]]; equations [max_equations - 1] = num.ToString() + ((num * num) - 20).ToString(); if (num % 2 == 0) { evens++; } } while (evens <= 1 || max_equations - evens <= 1 /* odds */); break; } default: throw new InvalidOperationException(); } random_indices = new ArrayListIndicesRandom(equations.Length); random_indices.Initialize(); for (int i = 0; i < random_indices.Count; i++) { if (random_indices[i] == wrong_answer) { Answer.SetMultiOptionAnswer(i, Answer.GetFigureName(i)); break; } } Container container = new Container(DrawAreaX + pos_x, DrawAreaY + 0.2, 0.5, random_indices.Count * 0.1); AddWidget(container); for (int i = 0; i < random_indices.Count; i++) { DrawableArea drawable_area = new DrawableArea(sel_width, 0.1); drawable_area.X = DrawAreaX + pos_x; drawable_area.Y = DrawAreaY + 0.2 + i * 0.1; container.AddChild(drawable_area); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption(i); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { int n = (int)e.Data; e.Context.SetPangoLargeFontSize(); e.Context.MoveTo(0.05, 0.02); // Translators: this "option) answer" for example "a) "21 x 60 = 1260". This should not be changed for most of the languages e.Context.ShowPangoText(String.Format(Translations.GetString("{0}) {1}"), Answer.GetMultiOption(n), equations [random_indices[n]])); }; } }
protected override void Initialize() { int fact_idx, quest_idx, questions; ArrayListIndicesRandom indices; switch (CurrentDifficulty) { case GameDifficulty.Easy: questions = 1; break; default: case GameDifficulty.Medium: questions = 2; break; case GameDifficulty.Master: questions = 3; break; } indices = new ArrayListIndicesRandom (total_questions); indices.Initialize (); facts = new Fact [questions]; base.Initialize (); for (int i = 0; i < facts.Length; i++) facts[i] = GetFact (indices[i]); fact_idx = random.Next (questions); quest_idx = random.Next (facts [fact_idx].Length); question = facts [fact_idx].questions [quest_idx]; Answer.Correct = (facts [fact_idx].answers [quest_idx]).ToString (); Answer.CheckExpression = "[0-9]+"; // Since this particular test requires to read and understand text // lets give the user twice time to be able to understand the text properly TotalTime = TotalTime * 2; }
private void RandomizeArcsOrder() { arcs_indices = new ArrayListIndicesRandom (num_arcs); arcs_indices.Initialize (); for (int i = 0; i < arcs_indices.Count; i++) { if (arcs_indices[i] == right_answer) { right_answer_pos = i; break; } } }
protected override void Initialize() { bool duplicated; int nums, options_next, dist, num_size, which = 0; Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption; switch (CurrentDifficulty) { case GameDifficulty.Easy: nums = 3; dist = nums * 3; num_size = 50; break; default: case GameDifficulty.Medium: nums = 5; dist = nums * 3; num_size = 150; break; case GameDifficulty.Master: nums = 7; dist = nums * 3; num_size = 500; break; } numbers = new double [nums]; options = new double [options_cnt]; do { // Random set of numbers correct = 0; for (int i = 0; i < nums; i++) { numbers [i] = 10 + random.Next(num_size) + dist; correct += numbers [i]; } correct = correct / nums; } while (correct != Math.Truncate(correct)); options [correct_pos] = correct; options_next = correct_pos + 1; // Generate possible answers while (options_next < options_cnt) { double ans; ans = correct + random.Next(-dist, dist + 1); duplicated = false; // No repeated answers for (int num = 0; num < options_next; num++) { // Due to decimal precision if (options [num] == ans || options [num] == ans + 1 || options [num] == ans - 1) { duplicated = true; break; } } if (duplicated) { continue; } options [options_next] = ans; options_next++; } random_indices = new ArrayListIndicesRandom(options_cnt); random_indices.Initialize(); for (int i = 0; i < options_cnt; i++) { if (random_indices [i] == correct_pos) { which = i; break; } } Answer.SetMultiOptionAnswer(which, options [correct_pos].ToString()); // Options double x = DrawAreaX + 0.25, y = DrawAreaY + 0.16; Container container = new Container(x, y, 1 - (x * 2), 0.6); AddWidget(container); for (int i = 0; i < options_cnt; i++) { DrawableArea drawable_area = new DrawableArea(0.3, 0.1); drawable_area.X = x; drawable_area.Y = y + i * 0.15; container.AddChild(drawable_area); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption(i); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { int n = (int)e.Data; int indx = random_indices[n]; e.Context.SetPangoLargeFontSize(); e.Context.MoveTo(0.02, 0.02); e.Context.ShowPangoText(String.Format("{0}) {1}", Answer.GetMultiOption(n), options [indx])); }; } }
protected override void Initialize() { int fig1, fig2; switch (CurrentDifficulty) { case GameDifficulty.Easy: figures_active = 4; rows = columns = 3; break; case GameDifficulty.Medium: figures_active = 6; rows = 3; columns = 4; break; case GameDifficulty.Master: figures_active = 8; columns = rows = 4; break; } rect_w = 0.65 / columns; rect_h = 0.65 / rows; figures = new ArrayListIndicesRandom(figures_active * 2); figures.Initialize(); question_pos = random.Next(figures_active * 2); for (int figure = 0; figure < figures_active * 2; figure++) { if (figure == question_pos) { continue; } fig1 = figures[figure]; fig2 = figures[question_pos]; if (fig1 >= figures_active) { fig1 -= figures_active; } if (fig2 >= figures_active) { fig2 -= figures_active; } if (fig1 == fig2) { question_answer = figure + 1; break; } } Answer.Correct = question_answer.ToString(); base.Initialize(); // Answers controls int col = 0; double y = start_y; HorizontalContainer container = new HorizontalContainer(start_x_ans, y, columns * rect_w, rect_h); AddWidget(container); for (int figure = 0; figure < figures.Count; figure++, col++) { if (col >= columns) { col = 0; y += rect_h; container = new HorizontalContainer(start_x_ans, y, columns * rect_w, rect_h); AddWidget(container); } DrawableArea drawable_area = new DrawableArea(rect_w, rect_h); container.AddChild(drawable_area); drawable_area.DataEx = (figure + 1).ToString(); if (figure == question_pos) { int fig = figures[figure]; if (fig >= figures_active) { fig -= figures_active; } drawable_area.Data = fig; drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { DrawFigure(e.Context, 0, 0, (FigureType)e.Data); }; } else { drawable_area.Data = figure + 1; drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { int n = (int)e.Data; e.Context.SetPangoLargeFontSize(); e.Context.DrawTextCentered(rect_w / 2, rect_h / 2, (n).ToString()); e.Context.Stroke(); }; } } }
private ArrayListIndicesRandom RandomizeFromArray(ArrayList ar) { int index; object []array = (object []) ar.ToArray (typeof (object)); ArrayListIndicesRandom elements = new ArrayListIndicesRandom (ar.Count); int left = ar.Count; elements.Clear (); // Generate a random number that can be as big as the maximum -1 // Add the random element picked up element in the list // The element just randomized gets out of pending list and replaced by the maximum -1 element for (int i = 0; i < ar.Count; i++, left--) { index = random.Next (left); elements.Add ((int) array[index]); array[index] = array[left - 1]; } return elements; }
protected override void Initialize() { question_indices = new ArrayListIndicesRandom (question_columns); question_indices.Initialize (); answer_indices = new ArrayListIndicesRandom (possible_answers); answer_indices.Initialize (); Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; BuildPossibleAnswers (); const double total_width = 0.8, total_height = 0.42; HorizontalContainer container = new HorizontalContainer (DrawAreaX, 0.52, total_width, total_height); AddWidget (container); // Possible answers columns for (int ans = 0; ans < possible_answers; ans++) { DrawableArea drawable_area = new DrawableArea (total_width / possible_answers, total_height); drawable_area.Data = ans; drawable_area.DataEx = Answer.GetMultiOption (ans); container.AddChild (drawable_area); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { double width = total_width / possible_answers; double x = (width - figure_size) / 2, y = 0; int column = (int) e.Data; for (int figure = 0; figure < figures_column; figure++) { DrawFigure (e.Context, x, y, figure_answers [(column * figures_column) + figure]); y+= figure_size + space_height; } e.Context.DrawTextCentered (width / 2, total_height - 0.02, Answer.GetFigureName (column)); e.Context.Stroke (); }; } Answer.SetMultiOptionAnswer (answer_indices[good_answer], Answer.GetFigureName (answer_indices[good_answer])); }
// Generates a new figure that was not generated before private FigureElement[] BuildFigure(ArrayList array, ArrayList figures) { bool done = false; FigureElement [] element = null; ArrayListIndicesRandom elements = new ArrayListIndicesRandom (array.Count); bool element_exists = false; while (done == false) { elements = RandomizeFromArray (array); element = new FigureElement [] { new FigureElement (pos1_x, pos1_y, (Element) elements[0]), new FigureElement (pos2_x, pos2_y, (Element) elements[1]), new FigureElement (pos3_x, pos3_y, (Element) elements[2]), new FigureElement (pos4_x, pos4_y, (Element) elements[3]), new FigureElement (pos5_x, pos5_y, (Element) elements[4]), new FigureElement (pos6_x, pos6_y, (Element) elements[5]), new FigureElement (pos7_x, pos7_y, (Element) elements[6]), }; for (int i = 0; i < figures.Count; i++) { FigureElement [] element2 = (FigureElement []) figures[i]; if (element.Length != element2.Length) continue; element_exists = true; for (int n = 0; n < element.Length; n++) { if (element[n].element != element2[n].element) { element_exists = false; break; } } if (element_exists == true) break; } if (element_exists == false) done = true; } return element; }
protected override void Initialize() { bool duplicated; int nums, options_next, dist, num_size, which = 0; Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption; switch (CurrentDifficulty) { case GameDifficulty.Easy: nums = 3; dist = nums * 3; num_size = 50; break; default: case GameDifficulty.Medium: nums = 5; dist = nums * 3; num_size = 150; break; case GameDifficulty.Master: nums = 7; dist = nums * 3; num_size = 500; break; } numbers = new double [nums]; options = new double [options_cnt]; do { // Random set of numbers correct = 0; for (int i = 0; i < nums; i++) { numbers [i] = 10 + random.Next (num_size) + dist; correct += numbers [i]; } correct = correct / nums; } while (correct != Math.Truncate (correct)); options [correct_pos] = correct; options_next = correct_pos + 1; // Generate possible answers while (options_next < options_cnt) { double ans; ans = correct + random.Next (dist); duplicated = false; // No repeated answers for (int num = 0; num < options_next; num++) { // Due to decimal precision if (options [num] == ans || options [num] == ans + 1 || options [num] == ans - 1) { duplicated = true; break; } } if (duplicated) continue; options [options_next] = ans; options_next++; } random_indices = new ArrayListIndicesRandom (options_cnt); random_indices.Initialize (); for (int i = 0; i < options_cnt; i++) { if (random_indices [i] == correct_pos) { which = i; break; } } Answer.SetMultiOptionAnswer (which, options [correct_pos].ToString ()); // Options double x = DrawAreaX + 0.25, y = DrawAreaY + 0.16; Container container = new Container (x, y, 1 - (x * 2), 0.6); AddWidget (container); for (int i = 0; i < options_cnt; i++) { DrawableArea drawable_area = new DrawableArea (0.3, 0.1); drawable_area.X = x; drawable_area.Y = y + i * 0.15; container.AddChild (drawable_area); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption (i); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { int n = (int) e.Data; int indx = random_indices[n]; e.Context.SetPangoLargeFontSize (); e.Context.MoveTo (0.02, 0.02); e.Context.ShowPangoText (String.Format ("{0}) {1}", Answer.GetMultiOption (n) , options [indx])); }; } }
public Analogy GetNext() { Analogy analogy; // Holds a deep copy Analogy analogy_ref; // Holds reference to the object ArrayListIndicesRandom indices = null; int new_right = 0; bool localized = true; List.TryGetValue (Variant, out analogy_ref); analogy = analogy_ref.Copy (); if (analogy.answers != null) { // Randomize answers order string [] answers; indices = new ArrayListIndicesRandom (analogy.answers.Length); answers = new string [analogy.answers.Length]; indices.Initialize (); for (int i = 0; i < indices.Count; i++) { if (GetText.StringExists (analogy.answers [indices[i]]) == false) localized = false; answers [i] = ServiceLocator.Instance.GetService <ITranslations> ().GetString (analogy.answers [indices[i]]); if (indices[i] == analogy.right) new_right = i; } analogy.right = new_right; analogy.answers = answers; } if ((GetText.StringExists (analogy.question) == false) || (String.IsNullOrEmpty (analogy.tip) == false && GetText.StringExists (analogy.tip) == false) || (String.IsNullOrEmpty (analogy.rationale) == false && GetText.StringExists (analogy.rationale) == false)) localized = false; if (localized == true) { analogy.question = ServiceLocator.Instance.GetService <ITranslations> ().GetString (analogy.question); if (String.IsNullOrEmpty (analogy.tip) == false) analogy.tip = ServiceLocator.Instance.GetService <ITranslations> ().GetString (analogy.tip); if (String.IsNullOrEmpty (analogy.rationale) == false) analogy.rationale = ServiceLocator.Instance.GetService <ITranslations> ().GetString (analogy.rationale); } else { // Get analogy again List.TryGetValue (Variant, out analogy_ref); analogy = analogy_ref.Copy (); if (analogy.answers != null) { // Randomize answers order string [] answers; answers = new string [analogy.answers.Length]; for (int i = 0; i < indices.Count; i++) answers [i] = analogy.answers [indices[i]]; analogy.right = new_right; analogy.answers = answers; } } return analogy; }
void RandomizeFigures() { ArrayListIndicesRandom figures_random; int pos = 0; figures = new FigureType [figures_active]; figures_random = new ArrayListIndicesRandom ((int) FigureType.Total); figures_random.Initialize (); for (int n = 0; n < figures_active; n++) { figures[n] = (FigureType) figures_random [pos++]; if (pos >= figures_random.Count) { pos = 0; figures_random.Initialize (); } } }
protected override void Initialize() { int tmp; words = new List <string> (total_words); // Body parts words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("wrist")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("elbow")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("armpit")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("hand")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("chest")); //Fishes words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("sardine")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("trout")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("monkfish")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("cod")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("salmon")); // Vegetables words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("potato")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("ginger")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("pepper")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("garlic")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("pumpkin")); // Bicycle words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("brake")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("pedal")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("chain")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("wheel")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("handlebar")); // Music words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("drummer")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("speaker")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("lyrics")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("beat")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("song")); // Weather words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("cloud")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("rain")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("storm")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("fog")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("rainbow")); // Animals words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("rabbit")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("mouse")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("monkey")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("bear")); words.Add (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("wolf")); switch (CurrentDifficulty) { case GameDifficulty.Easy: showed = 6; break; case GameDifficulty.Medium: showed = 9; break; case GameDifficulty.Master: showed = 12; break; } words_order = new ArrayListIndicesRandom (total_words); words_order.Initialize (); answer = random.Next (showed); tmp = words_order [answer]; Answer.Correct = words [tmp]; base.Initialize (); }
protected override void Initialize() { Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; options = new double [options_cnt * 2]; bool duplicated; bool done = false; int i, ans_idx, basenum, randnum; switch (CurrentDifficulty) { case GameDifficulty.Easy: basenum = 5; randnum = 10; break; default: case GameDifficulty.Medium: basenum = 5; randnum = 30; break; case GameDifficulty.Master: basenum = 9; randnum = 60; break; } while (done == false) { duplicated = false; options[0 + 0] = basenum + random.Next (randnum); options[0 + 1] = basenum + random.Next (randnum); options[2 + 0] = options[0 + 0] + random.Next (2); options[2 + 1] = options[0 + 1] + random.Next (2); options[(2 * 2) + 0] = options[0 + 0] - random.Next (5); options[(2 * 2) + 1] = options[0 + 1] - random.Next (5); options[(3 * 2) + 0] = options[0 + 0] + random.Next (5); options[(3 * 2) + 1] = options[0 + 1] + random.Next (5); // No repeated answers for (int num = 0; num < options_cnt; num++) { for (int n = 0; n < options_cnt; n++) { if (n == num) continue; if (options [(num * 2) + 0] / options [(num * 2) + 1] == options [(n * 2) + 0] / options [(n * 2) + 1]) { duplicated = true; break; } } } if (duplicated) continue; // No numerator = denominator (1 value) if (options [0 + 0] == options [0 + 1]) continue; if (options [(1 * 2) + 0] == options [(1 * 2) + 1]) continue; if (options [(2 * 2) + 0] == options [(2 * 2) + 1]) continue; if (options [(3 * 2) + 0] == options [(3 * 2) + 1]) continue; // No < 2 for (i = 0; i < options_cnt * 2; i++) { if (options [i] < 2) break; } if (i < options_cnt * 2) continue; done = true; } random_indices = new ArrayListIndicesRandom (4); random_indices.Initialize (); which = random.Next (options_cnt); ans_idx = random_indices[which]; question_num = options[ans_idx * 2] / options[(ans_idx * 2) + 1]; Answer.SetMultiOptionAnswer (which, options [ans_idx * 2] + " / " + options [(ans_idx * 2) +1]); // Options double x = DrawAreaX + 0.25, y = DrawAreaY + 0.16; Container container = new Container (x, y, 1 - (x * 2), 0.6); AddWidget (container); for (i = 0; i < options_cnt; i++) { DrawableArea drawable_area = new DrawableArea (0.3, 0.1); drawable_area.X = x; drawable_area.Y = y + i * 0.15; container.AddChild (drawable_area); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption (i); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { int n = (int) e.Data; int indx = random_indices[n]; e.Context.SetPangoLargeFontSize (); e.Context.MoveTo (0.02, 0.02); e.Context.ShowPangoText (String.Format (Translations.GetString ("{0}) {1}"), Answer.GetMultiOption (n) , options [indx * 2] + " / " + options [(indx * 2) +1])); }; } }
public Analogy GetNext() { Analogy analogy; // Holds a deep copy Analogy analogy_ref; // Holds reference to the object ArrayListIndicesRandom indices = null; int new_right = 0; bool localized = true; List.TryGetValue(Variant, out analogy_ref); analogy = analogy_ref.Copy(); if (analogy.answers != null) // Randomize answers order { string [] answers; indices = new ArrayListIndicesRandom(analogy.answers.Length); answers = new string [analogy.answers.Length]; indices.Initialize(); for (int i = 0; i < indices.Count; i++) { if (GetText.StringExists(analogy.answers [indices[i]]) == false) { localized = false; } answers [i] = Translations.GetString(analogy.answers [indices[i]]); if (indices[i] == analogy.right) { new_right = i; } } analogy.right = new_right; analogy.answers = answers; } if ((GetText.StringExists(analogy.question) == false) || (String.IsNullOrEmpty(analogy.tip) == false && GetText.StringExists(analogy.tip) == false) || (String.IsNullOrEmpty(analogy.rationale) == false && GetText.StringExists(analogy.rationale) == false)) { localized = false; } if (localized == true) { analogy.question = Translations.GetString(analogy.question); if (String.IsNullOrEmpty(analogy.tip) == false) { analogy.tip = Translations.GetString(analogy.tip); } if (String.IsNullOrEmpty(analogy.rationale) == false) { analogy.rationale = Translations.GetString(analogy.rationale); } } else { // Get analogy again List.TryGetValue(Variant, out analogy_ref); analogy = analogy_ref.Copy(); if (analogy.answers != null) // Randomize answers order { string [] answers; answers = new string [analogy.answers.Length]; for (int i = 0; i < indices.Count; i++) { answers [i] = analogy.answers [indices[i]]; } analogy.right = new_right; analogy.answers = answers; } } return(analogy); }
protected override void Initialize() { sum_offset = random.Next (3); random_indices = new ArrayListIndicesRandom (slices.Length / items_per_slice); random_indices.Initialize (); ans_pos = random.Next (possible_answers); Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; Answer.SetMultiOptionAnswer (ans_pos, Answer.GetFigureName (ans_pos)); bad_answers = new int [possible_answers * items_per_slice]; for (int i = 0; i < bad_answers.Length; i++) { bad_answers[i] = 1 + random.Next (9); } HorizontalContainer container = new HorizontalContainer (DrawAreaX, 0.62, 0.8, 0.3); DrawableArea drawable_area; AddWidget (container); for (int i = 0; i < possible_answers; i++) { drawable_area = new DrawableArea (0.8 / 3, 0.3); drawable_area.SelectedArea = new Rectangle (0, 0, radius, 0.2); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption (i); container.AddChild (drawable_area); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { int n = (int) e.Data; DrawSlice (e.Context, 0, 0); if (n == ans_pos) { int pos = random_indices [0]; DrawSliceText (e.Context, 0, 0, 0, (sum_offset + slices [pos * items_per_slice]).ToString (), (sum_offset + slices [1 + (pos * items_per_slice)]).ToString (), (sum_offset + slices [2 + (pos * items_per_slice)]).ToString ()); } else { DrawSliceText (e.Context, 0, 0, 0, bad_answers [n * items_per_slice].ToString (), bad_answers [1 + (n * items_per_slice)].ToString (), bad_answers [2 + (n * items_per_slice)].ToString ()); } e.Context.MoveTo (0.0, 0.25); e.Context.DrawTextCentered (radius / 2, 0.25, Answer.GetFigureName (n)); e.Context.Stroke (); }; } }
protected override void Initialize() { // Question ArrayList array_good = new ArrayList (); array_good.AddRange (new Element [] {Element.SmallCircle, Element.SmallCircle, Element.SmallCircle, Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild}); Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; // Four random samples with equal elements questions = new ArrayList (); for (int i = 0; i < 4; i++) { questions.Add (BuildFigure (array_good, questions)); } ArrayList array = new ArrayList (); answers = new ArrayList (); random_indices_answers = new ArrayListIndicesRandom (4); random_indices_answers.Initialize (); for (int i = 0; i < random_indices_answers.Count; i++) { if ((int) random_indices_answers [i] == 0) { Answer.SetMultiOptionAnswer (i, Answer.GetFigureName (i)); break; } } if (CurrentDifficulty == GameDifficulty.Easy) { // Answer 1 (good) array.AddRange (new Element [] {Element.SmallCircle, Element.SmallCircle, Element.SmallCircle, Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild}); answers.Add (BuildFigure (array, answers)); // Answer 2 array.Clear (); array.AddRange (new Element [] {Element.SmallCircle, Element.SmallCircle, Element.MediumCircle, Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild}); answers.Add (BuildFigure (array, answers)); // Answer 3 array.Clear (); array.AddRange (new Element [] {Element.SmallCircle, Element.SmallCircle, Element.MediumCircle, Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild}); answers.Add (BuildFigure (array, answers)); // Answer 4 array.Clear (); array.AddRange (new Element [] {Element.SmallCircle, Element.SmallCircle, Element.MediumCircle, Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild}); answers.Add (BuildFigure (array, answers)); } else // Medium or Master { // Answer 1 (good) array.AddRange (new Element [] {Element.SmallCircle, Element.SmallCircle, Element.MediumCircleWithChild, Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild}); answers.Add (BuildFigure (array, answers)); // Answer 2 array.Clear (); array.AddRange (new Element [] {Element.SmallCircle, Element.MediumCircle, Element.MediumCircle, Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild}); answers.Add (BuildFigure (array, answers)); // Answer 3 array.Clear (); array.AddRange (new Element [] {Element.SmallCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild, Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild}); answers.Add (BuildFigure (array, answers)); // Answer 4 array.Clear (); array.AddRange (new Element [] {Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild, Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild}); answers.Add (BuildFigure (array, answers)); } double figure_size = 0.22; double x = DrawAreaX - 0.05, y = DrawAreaY + 0.45; HorizontalContainer container = new HorizontalContainer (x, y, random_indices_answers.Count * figure_size, 0.3); DrawableArea drawable_area; AddWidget (container); for (int i = 0; i < random_indices_answers.Count; i++) { drawable_area = new DrawableArea (figure_size, figure_size + 0.05); drawable_area.SelectedArea = new Rectangle (0.05, 0.05, 0.15, 0.15); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption (i); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { int n = (int) e.Data; DrawFigure (e.Context, 0.05, 0.05, (FigureElement []) answers[random_indices_answers[n]]); e.Context.MoveTo (0.05, 0.22); e.Context.ShowPangoText (Answer.GetFigureName (n)); }; container.AddChild (drawable_area); } }
protected override void Initialize() { Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; random_indices = new ArrayListIndicesRandom ((int) Figures.Last); random_indices.Initialize (); for (int i = 0; i < (int) Figures.Last; i++) { if ((Figures) random_indices[i] == Figures.FigureA) { Answer.SetMultiOptionAnswer (i, Answer.GetFigureName (i)); break; } } }
protected override void Initialize() { switch (CurrentDifficulty) { case GameDifficulty.Easy: maxdotscolor = 2; break; case GameDifficulty.Medium: maxdotscolor = 5; break; case GameDifficulty.Master: maxdotscolor = 8; break; } location_order = new ArrayListIndicesRandom (NUMCOLUMNS*NUMCOLUMNS); location_order.Initialize(); palette = new ColorPalette (); // dotsPerColor is compared with iterator of dots. (this iterator is 0 based, so I // have to substract 1 to make dotsPerColor contents 0 based. dotsPerColor = new int [palette.Count]; for (int i=0,before=-1; i< palette.Count; i++) { dotsPerColor[i] = before + MINDOTS + random.Next(maxdotscolor-MINDOTS+1); before = dotsPerColor[i]; } Answer.Correct = (dotsPerColor[0]+1).ToString (); base.Initialize (); }
protected override void Initialize() { bool duplicated; int options_next, which = 0; Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption; switch (CurrentDifficulty) { case GameDifficulty.Easy: total_size = 10; break; case GameDifficulty.Medium: case GameDifficulty.Master: total_size = 15; break; } GetPuzzleNumbersAndAnswer(); options = new int [options_cnt]; options [correct_pos] = correct; options_next = correct_pos + 1; // Generate possible answers while (options_next < options_cnt) { int ans; ans = correct + random.Next(-correct / 2, correct / 2); duplicated = false; // No repeated answers for (int num = 0; num < options_next; num++) { if (options [num] == ans) { duplicated = true; break; } } if (duplicated) { continue; } options [options_next] = ans; options_next++; } random_indices = new ArrayListIndicesRandom(options_cnt); random_indices.Initialize(); for (int i = 0; i < options_cnt; i++) { if (random_indices [i] == correct_pos) { which = i; break; } } Answer.SetMultiOptionAnswer(which, options [correct_pos].ToString()); // Options double x = DrawAreaX + 0.25, y = DrawAreaY + 0.26; Container container = new Container(x, y, 1 - (x * 2), 0.6); AddWidget(container); for (int i = 0; i < options_cnt; i++) { DrawableArea drawable_area = new DrawableArea(0.3, 0.1); drawable_area.X = x; drawable_area.Y = y + i * 0.15; container.AddChild(drawable_area); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption(i); drawable_area.DrawEventHandler += delegate(object sender, DrawEventArgs e) { int n = (int)e.Data; int indx = random_indices[n]; e.Context.SetPangoLargeFontSize(); e.Context.MoveTo(0.02, 0.02); e.Context.ShowPangoText(String.Format("{0}) {1}", Answer.GetMultiOption(n), options [indx])); }; } }
void CreateDrawingObjects(GameXmlDefinitionVariant game) { OptionDrawingObject option; double x = 0, y = 0, width = 0, height = 0; bool first = true; int randomized_options = 0; if (game.DrawingObjects == null) return; // Calculate the size of container from the options and count the number of random options foreach (DrawingObject draw_object in game.DrawingObjects) { option = draw_object as OptionDrawingObject; if (option == null) continue; if (option.RandomizedOrder) randomized_options++; if (first == true) { x = option.X; y = option.Y; width = option.Width; height = option.Height; first = false; continue; } if (option.X < x) x = option.X; if (option.Y < y) y = option.Y; if (option.X + option.Width > width) width = option.X + option.Width; if (option.Y + option.Height > height) height = option.Y + option.Height; } if (first == true) return; // Randomize the order of the options if (randomized_options > 0) { OptionDrawingObject [] originals; ArrayListIndicesRandom random_indices; int index = 0; random_indices = new ArrayListIndicesRandom (randomized_options); originals = new OptionDrawingObject [randomized_options]; random_indices.Initialize (); // Backup originals for (int i = 0; i < game.DrawingObjects.Length; i++) { option = game.DrawingObjects[i] as OptionDrawingObject; if (option == null) continue; originals[index] = option.Copy (); index++; } // Swap index = 0; for (int i = 0; i < game.DrawingObjects.Length; i++) { option = game.DrawingObjects[i] as OptionDrawingObject; if (option == null) continue; option.CopyRandomizedProperties (originals [random_indices [index]]); index++; } } Container container = new Container (x, y, width - x, height - y); AddWidget (container); if (options == null) options = new List <OptionDrawingObject> (); int idx = 0; // Create drawing widgets objects foreach (DrawingObject draw_object in game.DrawingObjects) { option = draw_object as OptionDrawingObject; if (option == null) continue; DrawableArea drawable_area = new DrawableArea (option.Width, option.Height); drawable_area.X = option.X; drawable_area.Y = option.Y; // + i * 0.15; container.AddChild (drawable_area); drawable_area.Data = idx; drawable_area.DataEx = Answer.GetMultiOption (idx); options.Add (option); idx++; drawable_area.DrawEventHandler += DrawOption; } }
protected override void Initialize() { Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces; possible_answers = new ArrayListIndicesRandom (3); possible_answers.Initialize (); puzzle_index = random.Next (puzzles.Length); puzzle = puzzles [puzzle_index]; DrawableArea drawable_area; HorizontalContainer container = new HorizontalContainer (0.05, 0.5, 0.9, figure_size + 0.1); AddWidget (container); for (int i = 0; i < possible_answers.Count; i++) { drawable_area = new DrawableArea (figure_size + space_figures, figure_size + 0.1); drawable_area.Data = i; drawable_area.DataEx = Answer.GetMultiOption (i); drawable_area.SelectedArea = new Rectangle (space_figures / 2, space_figures / 2, figure_size, figure_size); container.AddChild (drawable_area); drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e) { DrawPossibleAnswer (e.Context, space_figures / 2, space_figures / 2, possible_answers [(int)e.Data]); e.Context.DrawTextCentered (space_figures / 2 + figure_size / 2, space_figures + figure_size + 0.02, Answer.GetFigureName ((int)e.Data)); }; } for (int i = 0; i < possible_answers.Count; i++) { if (possible_answers[i] == 0) { Answer.SetMultiOptionAnswer (i, Answer.GetFigureName (i)); break; } } }
protected override void Initialize() { int tmp; animals = new List <string> (); animals.Add ("dog"); animals.Add ("cat"); animals.Add ("rat"); animals.Add ("bird"); animals.Add ("sardine"); animals.Add ("trout"); animals.Add ("monkfish"); animals.Add ("cod"); animals.Add ("salmon"); switch (CurrentDifficulty) { case GameDifficulty.Easy: showed = 4; break; case GameDifficulty.Medium: showed = 6; break; case GameDifficulty.Master: showed = 8; break; } animals_order = new ArrayListIndicesRandom (animals.Count); animals_order.Initialize (); answer = random.Next (showed); tmp = animals_order [answer]; Answer.Correct = animals [tmp]; base.Initialize (); }