Exemple #1
0
        private void SetDrawingAreas()
        {
            double rect_w = DrawAreaWidth / columns;
            double rect_h = DrawAreaHeight / rows;

            Container container = new Container (DrawAreaX, DrawAreaY, 0.8, 0.8);
            AddWidget (container);

            for (int column = 0; column < columns; column++)
            {
                for (int row = 0; row < rows; row++)
                {
                    DrawableArea drawable_area = new DrawableArea (rect_w, rect_h);
                    drawable_area.X = DrawAreaX + column * rect_w;
                    drawable_area.Y = DrawAreaY + row * rect_h;
                    container.AddChild (drawable_area);

                    string num = grid[row * columns + column].ToString ();
                    drawable_area.Data = num;
                    drawable_area.DataEx = num;

                    drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
                    {
                        string number = (string) e.Data;

                        e.Context.Rectangle (0, 0, e.Width, e.Height);
                        e.Context.Stroke ();

                        e.Context.SetPangoLargeFontSize ();
                        e.Context.DrawTextCentered (e.Width / 2, e.Height / 2, number);
                        e.Context.Stroke ();
                    };
                }
            }
        }
Exemple #2
0
        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()
        {
            Current = GetNext ();

            if (Current == null || Current.answers == null)
                return;

            Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption;
            Answer.SetMultiOptionAnswer (Current.right, Current.answers[Current.right]);

            Container container = new Container (DrawAreaX, DrawAreaY + 0.2, 0.8, Current.answers.Length * 0.15);
            AddWidget (container);

            for (int i = 0; i <  Current.answers.Length; i++)
            {
                DrawableArea drawable_area = new DrawableArea (0.8, 0.1);
                drawable_area.X = DrawAreaX;
                drawable_area.Y = DrawAreaY + 0.2 + 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;

                    e.Context.MoveTo (0.05, 0.02);
                    e.Context.ShowPangoText (String.Format (Translations.GetString ("{0}) {1}"), Answer.GetMultiOption (n), Current.answers[n].ToString ()));
                };
            }
            SetAnswerCorrectShow ();
        }
        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()
        {
            int pair = random.Next (pairs);
            question = (char) (48 + question_answer[pair * 2]);

            char num = (char) (48 + question_answer[(pair * 2) + 1]);
            Answer.Correct = num.ToString ();

            Container container;
            DrawableArea drawable_area;
            double x = DrawAreaX + 0.1;
            double y = DrawAreaY + 0.2;

            container = new Container ();
            AddWidget (container);

            drawable_area = new DrawableArea (x + 0.1, y, figure_size, figure_size);
            drawable_area.DataEx = "1";
            container.AddChild (drawable_area);
            drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
            {
                e.Context.Rectangle (0, 0, figure_size, figure_size);
                e.Context.Stroke ();
                e.Context.MoveTo (txtoff_x, txtoff_y);
                e.Context.ShowPangoText ("1");
            };

            drawable_area = new DrawableArea (x + 0.2, y, figure_size, figure_size);
            drawable_area.DataEx = "2";
            container.AddChild (drawable_area);
            drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
            {
                e.Context.Rectangle (0, 0, figure_size, figure_size);
                e.Context.Stroke ();
                e.Context.MoveTo (txtoff_x, txtoff_y);
                e.Context.ShowPangoText ("2");
            };

            drawable_area = new DrawableArea (x + 0.2, y + 0.1, figure_size, figure_size);
            drawable_area.DataEx = "3";
            container.AddChild (drawable_area);
            drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
            {
                e.Context.Rectangle (0, 0, figure_size, figure_size);
                e.Context.Stroke ();
                e.Context.MoveTo (txtoff_x, txtoff_y);
                e.Context.ShowPangoText ("3");
            };

            drawable_area = new DrawableArea (x + 0.3, y + 0.1, figure_size, figure_size);
            drawable_area.DataEx = "4";
            container.AddChild (drawable_area);
            drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
            {
                e.Context.Rectangle (0, 0, figure_size, figure_size);
                e.Context.Stroke ();
                e.Context.MoveTo (txtoff_x, txtoff_y);
                e.Context.ShowPangoText ("4");
            };

            drawable_area = new DrawableArea (x + 0.4, y + 0.1, figure_size, figure_size);
            drawable_area.DataEx = "5";
            container.AddChild (drawable_area);
            drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
            {
                e.Context.Rectangle (0, 0, figure_size, figure_size);
                e.Context.Stroke ();
                e.Context.MoveTo (txtoff_x, txtoff_y);
                e.Context.ShowPangoText ("5");
            };

            drawable_area = new DrawableArea (x + 0.4, y + 0.2, figure_size, figure_size);
            drawable_area.DataEx = "6";
            container.AddChild (drawable_area);
            drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
            {
                e.Context.Rectangle (0, 0, figure_size, figure_size);
                e.Context.Stroke ();
                e.Context.MoveTo (txtoff_x, txtoff_y);
                e.Context.ShowPangoText ("6");
            };
        }
        protected override void Initialize()
        {
            Current = GetNext ();

            if (Current == null || Current.answers == null)
                return;

            string [] items;

            items = Current.question.Split (AnalogiesFactory.Separator);

            if (items.Length == 2)
                sample = items [1].Trim ();
            else
                sample = string.Empty;

            samples = items [0].Trim ();

            Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption;
            Answer.Correct = Answer.GetMultiOption (Current.right);

            Container container = new Container (DrawAreaX + 0.1, 0.50, 0.5, Current.answers.Length * 0.15);
            AddWidget (container);

            for (int i = 0; i <  Current.answers.Length; i++)
            {
                DrawableArea drawable_area = new DrawableArea (0.8, 0.1);
                drawable_area.X = DrawAreaX;
                drawable_area.Y = DrawAreaY + 0.25 + 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;

                    e.Context.MoveTo (0.05, 0.02);
                    e.Context.ShowPangoText (String.Format (ServiceLocator.Instance.GetService <ITranslations> ().GetString ("{0}) {1}"), Answer.GetMultiOption (n), Current.answers[n].ToString ()));
                };
            }
            SetAnswerCorrectShow ();
        }
        protected override void Initialize()
        {
            bool found;
            int n, m;
            int []mult = new int [3];

            Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption;
            switch (CurrentDifficulty) {
            case GameDifficulty.Easy:
                max_num = 999;
                num_answ_ques = 3;
                break;
            case GameDifficulty.Medium:
                max_num = 999;
                num_answ_ques = 4;
                break;
            case GameDifficulty.Master:
                max_num = 9999;
                num_answ_ques = 4;
                break;
            }

            numbers = new int [num_answ_ques];
            answers = new int [num_answ_ques];

            // Common multipliers for all numbers
            for (m = 0; m < mult.Length; m++) {
                mult[m] = GetMultiplier (mult);
            }

            n = 0;
            while (n < numbers.Length) {
                numbers [n] = 4 + random.Next (5);
                for (int i = 1; i < 5; i++) {
                    numbers [n] =  numbers [n]  * (1 + random.Next (10));
                }

                for (m = 0; m < mult.Length; m++) {
                    numbers[n] = numbers [n] * mult[m];
                }

                if (numbers[n] > max_num || numbers[n] < 50)
                    continue;

                found = false;
                for (int i = 0; i < n; i++) {
                    if (numbers[i]  == numbers [n]) {
                        found = true;
                        break;
                    }
                }
                if (found == false) {
                    n++;
                }
            }

            int answer = 0;
            // Avoid generating a set of answers in which none matches the condition
            while (answer == 0)
            {
                // Build a list of answers
                for (n = 0; n < answers.Length; n++) {
                    answers[n] = GetUniqueAnswer (mult, answers);
                }

                n = 0;
                for (int a = 0; a < answers.Length; a++)
                {
                    for (n = 0; n < answers.Length; n++)
                    {
                        if ((double)numbers[n] / (double)answers[a] !=  Math.Abs (numbers[n] / answers[a]))
                            break;
                    }

                    if (n == answers.Length && answers[a] > answer)
                    {
                        answer = answers[a];
                        answer_idx = a;
                    }
                }
            }

            Answer.SetMultiOptionAnswer (answer_idx, answer.ToString ());

            // Drawing objects
            Container container = new Container (DrawAreaX + 0.2, DrawAreaY + 0.25, 0.4, answers.Length * 0.15);
            AddWidget (container);

            for (int i = 0; i < answers.Length; i++)
            {
                DrawableArea drawable_area = new DrawableArea (0.3, 0.1);
                drawable_area.X = DrawAreaX + 0.23;
                drawable_area.Y = DrawAreaY + 0.27 + 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 d = (int) e.Data;
                    e.Context.SetPangoLargeFontSize ();
                    e.Context.MoveTo (0.07, 0.02);
                    e.Context.ShowPangoText (String.Format (Translations.GetString ("{0}) {1}"), Answer.GetMultiOption (d),
                        answers[d].ToString ()));
                };
            }
        }
        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]));
                };
            }
        }
        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 ();
                };
            }
        }
        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]));
                };
            }
        }
Exemple #11
0
        void DrawingAnswerObjects()
        {
            Container container = new Container (DrawAreaX + 0.2, DrawAreaY + 0.4, 0.5, answers.Length * 0.10);
            AddWidget (container);

            for (int i = 0; i < answers.Length; i++)
            {
                DrawableArea drawable_area = new DrawableArea (0.4, 0.1);
                drawable_area.X = DrawAreaX + 0.23;
                drawable_area.Y = DrawAreaY + 0.4 + 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 d = (int) e.Data;
                    e.Context.SetPangoLargeFontSize ();
                    e.Context.MoveTo (0.07, 0.02);
                    e.Context.ShowPangoText (String.Format (Translations.GetString ("{0}) {1}"), Answer.GetMultiOption (d),
                        converter.ToString (answers[d])));
                };
            }
        }
        protected override void Initialize()
        {
            Answer.CheckAttributes |= GameAnswerCheckAttributes.MultiOption;
            switch (CurrentDifficulty) {
            case GameDifficulty.Easy:
                div3 = true;
                max_primeidx = 55; // 263
                break;
            case GameDifficulty.Master:
                div3 = false;
                max_primeidx = total_primes;
                break;
            case GameDifficulty.Medium:
            default:
                div3 = true;
                max_primeidx = 95; // 503
                break;
            }

            numbers = new int [total_nums];

            for (int i = 0; i < numbers.Length; i++)
             	numbers [i] = GenerateNonPrime ();

            answer_idx = random.Next (numbers.Length);
            answer = primes [random.Next (max_primeidx + 1)];
            numbers [answer_idx] = answer;
            Answer.SetMultiOptionAnswer (answer_idx, answer.ToString ());

            // Drawing objects
            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 < numbers.Length; 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;

                    e.Context.SetPangoLargeFontSize ();
                    e.Context.MoveTo (0.02, 0.02);
                    e.Context.ShowPangoText (String.Format ("{0}) {1:##0.###}", Answer.GetMultiOption (n) , numbers [n]));
                };
            }
        }
Exemple #13
0
        private void SetDrawingAreas()
        {
            double rect_w = DrawAreaWidth / rows;
            double rect_h = DrawAreaHeight / columns;

            Container container = new Container (DrawAreaX, DrawAreaY, 0.8, 0.8);
            AddWidget (container);

            for (int column = 0; column < columns; column++)
            {
                for (int row = 0; row < rows; row++)
                {
                    bool cercled;
                    DrawableArea drawable_area = new DrawableArea (rect_w, rect_h);
                    drawable_area.X = DrawAreaX + row * rect_w;
                    drawable_area.Y = DrawAreaY + column * rect_h;
                    container.AddChild (drawable_area);

                    cercled = numbers[column + (row * 4)] % divisor == 0 && good_pos != column + (row * 4);
                    Number number = new Number { NumberString = numbers[column + (row * 4)].ToString (), Cercled = cercled };
                    drawable_area.Data = number;
                    drawable_area.DataEx = number.NumberString;

                    drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
                    {
                        Number num = (Number) e.Data;

                        e.Context.Color = DefaultDrawingColor;
                        e.Context.Rectangle (0, 0, e.Width, e.Height);
                        e.Context.Stroke ();

                        e.Context.DrawTextCentered (e.Width / 2, e.Height / 2, num.NumberString);

                        if (num.Cercled)
                        {
                            e.Context.Arc (e.Width / 2, e.Height / 2, 0.05, 0, 2 * Math.PI);
                            e.Context.FillGradient (e.Width / 2, e.Height / 2, 0.05, 0.05);
                        }

                        e.Context.Stroke ();
                    };
                }
            }
        }
        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]));
                };
            }
        }
Exemple #15
0
        public void CreateDrawingObjects(DrawingObject [] drawing_objects)
        {
            OptionDrawingObject option;
            double x = 0, y = 0, width = 0, height = 0;
            bool first = true;
            int randomized_options = 0;

            if (drawing_objects == null)
                return;

            // Calculate the size of container from the options and count the number of random options
            foreach (DrawingObject draw_object in drawing_objects)
            {
                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;

            RandomizeOptions (drawing_objects, randomized_options);

            Container container = new Container (x, y, width - x, height - y);
            game_xml.AddWidget (container);

            if (Options == null)
                Options = new List <OptionDrawingObject> ();

            // Create drawing widgets objects
            int idx = 0;
            foreach (DrawingObject draw_object in drawing_objects)
            {
                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 = game_xml.Answer.GetMultiOption (idx);
                Options.Add (option);

                idx++;
                drawable_area.DrawEventHandler += DrawOption;
            }
        }
        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]));
                };
            }
        }