Beispiel #1
0
        Fact GetFact(int index)
        {
            Fact fact = new Fact();

            switch (index)
            {
            case 0:
                fact.Initialize(2);
                fact.answers [0] = 2 + random.Next(14);
                fact.answers [1] = 1914 + random.Next(50);
                fact.fact        = String.Format(
                    // Translators: {0} is replaced by a number, {1} by a year (like 1940)
                    // Day in English does not need to be plural
                    Translations.GetPluralString("Shiny Cars had already announced a {0} day production halt next month, but before then it had not halted production since {1}.",
                                                 "Shiny Cars had already announced a {0} day production halt next month, but before then it had not halted production since {1}.",
                                                 fact.answers [0]),
                    fact.answers [0], fact.answers [1]);
                fact.questions [0] = Translations.GetString("How many days did Shiny Cars halt its production for?");
                fact.questions [1] = Translations.GetString("In what year did Shiny Cars last halt its production?");
                break;

            case 1:
                fact.Initialize(2);
                fact.answers [0] = 10 + random.Next(30);
                fact.answers [1] = 1914 + random.Next(50);
                fact.fact        = String.Format(
                    // Translators: {0} is replaced by a number, {1} by a year (like 1940)
                    Translations.GetString("Shiny Cars sales fell {0}% this past December, the worst decline since {1}."),
                    fact.answers [0], fact.answers [1]);
                fact.questions [0] = Translations.GetString("By how much did company sales fall last December?");
                fact.questions [1] = String.Format(
                    Translations.GetString("Shiny Cars sales fell {0}% this past December. This is the worst decline since which year?"),
                    fact.answers [0]);
                break;

            case 2:
                fact.Initialize(1);
                fact.answers [0] = 10 + random.Next(30);
                fact.fact        = String.Format(Translations.GetString("About {0}% of Shiny Cars produced worldwide are sold in Europe."),
                                                 fact.answers [0]);
                fact.questions [0] = Translations.GetString("What percentage of all Shiny Cars produced worldwide are sold in Europe?");
                break;

            case 3:
                fact.Initialize(2);
                fact.answers [0] = 10 + random.Next(30);
                fact.answers [1] = 100 - (1 + random.Next(10)) - fact.answers [0];
                fact.fact        = String.Format(Translations.GetString("About {0}% of Shiny Cars use diesel, {1}% use gasoline and the remainder use electricity."),
                                                 fact.answers [0], fact.answers [1]);
                fact.questions [0] = Translations.GetString("What percentage of Shiny Cars use diesel?");
                fact.questions [1] = Translations.GetString("What percentage of Shiny Cars use gasoline?");
                break;

            default:
                throw new Exception("Invalid index value");
            }

            return(fact);
        }
Beispiel #2
0
        // Protect from calling with null + resolve plurals
        internal string CatalogGetString(LocalizableString localizable)
        {
            if (localizable == null)
            {
                return(string.Empty);
            }

            if (localizable.IsPlural() == false)
            {
                return(CatalogGetString(localizable.String));
            }

            return(Translations.GetPluralString(localizable.String, localizable.PluralString, localizable.ValueComputed));
        }
Beispiel #3
0
        protected override void Initialize()
        {
            int ans, var, total;

            gametype = (GameType)random.Next((int)GameType.Total);

            switch (gametype)
            {
            case GameType.Machine:
                var      = 2 + random.Next(5);
                total    = 50 + random.Next(100);
                question = String.Format(
                    Translations.GetPluralString("We have a {0} meter piece of fabric.", "We have a {0} meters piece of fabric.", total),
                    total);
                question += " ";
                question += String.Format(
                    Translations.GetPluralString("A machine takes {0} second to cut 1 meter of this fabric. How many seconds does the machine take to cut the entire piece of fabric into 1 meter pieces?",
                                                 "A machine takes {0} seconds to cut 1 meter of this fabric. How many seconds does the machine take to cut the entire piece of fabric into 1 meter pieces?"
                                                 , var), var);
                answer = String.Format(
                    Translations.GetPluralString("With the cut number {0}, the machine creates two 1 meter pieces.",
                                                 "With the cut number {0}, the machine creates two 1 meter pieces.", total - 1),
                    total - 1);

                ans = (total - 1) * var;
                break;

            case GameType.Fence:
                total    = 20 + random.Next(20);
                ans      = 4 * total - 4;
                question = String.Format(
                    // Translators: {0} is a number
                    Translations.GetPluralString(
                        "A fence is built to enclose a square shaped region. {0} fence pole is used in each side of the square. How many fence poles are used in total?",
                        "A fence is built to enclose a square shaped region. {0} fence poles are used in each side of the square. How many fence poles are used in total?",
                        total),
                    total);
                // Translators: {0} is a number
                answer = String.Format(
                    Translations.GetPluralString(
                        "There is {0} fence pole since the poles on the corners of the square are shared.",
                        "There are {0} fence poles since the poles on the corners of the square are shared.",
                        ans)
                    , ans);
                break;

            case GameType.Present:
                int present = 5 + random.Next(20);
                total    = present + 2;
                ans      = total;
                question = String.Format(
                    // Translators: {0} is a number
                    Translations.GetPluralString(
                        "Wrapping an anniversary present costs one monetary unit. The anniversary present costs {0} monetary unit more than the cost to wrap it. How much does it cost to both purchase and wrap the present?",
                        "Wrapping an anniversary present costs one monetary unit. The anniversary present costs {0} monetary units more than the cost to wrap it. How much does it cost to both purchase and wrap the present?",
                        present),
                    present);

                answer = String.Format(
                    Translations.GetPluralString(
                        "It is the cost of the present, {0} monetary unit, plus one monetary unit of the wrapping.",
                        "It is the cost of the present, {0} monetary units, plus one monetary unit of the wrapping.",
                        present + 1), present + 1);
                break;

            default:
                throw new Exception("Unexpected value");
            }

            Answer.Correct = (ans).ToString();
        }
 string HasNRegionString(int regions)
 {
     return(String.Format(Translations.GetPluralString("Has {0} region",
                                                       "Has {0} regions", regions), regions));
 }
Beispiel #5
0
        protected override void Initialize()
        {
            int ans;

            gametype = (GameType)random.Next((int)GameType.Total);

            switch (gametype)
            {
            case GameType.Discount:
                double price, discount, paid;

                do
                {
                    discount = 10 + random.Next(30);
                    price    = 100 + random.Next(100);
                    paid     = price - (price * discount / 100);
                }  while (paid != Math.Truncate(paid));

                question = String.Format(
                    Translations.GetPluralString(
                        "After getting {0}% discount you have paid {1} monetary unit for a TV set. What was the original price of the TV set?",
                        "After getting {0}% discount you have paid {1} monetary units for a TV set. What was the original price of the TV set?",
                        (int)paid),
                    discount, paid);
                ans       = (int)price;
                svg_image = "tv_set.svg";
                break;

            case GameType.Sales:
                double sales, increase, previous;

                do
                {
                    previous = 10 + random.Next(90);
                    increase = 10 + random.Next(20);
                    sales    = previous + (previous * increase / 100);
                }  while (sales != Math.Truncate(sales));


                question = String.Format(
                    Translations.GetPluralString(
                        "John's shop had sales of {0} monetary unit. This was an increase of {1}% over last month. What were last month sales?",
                        "John's shop had sales of {0} monetary units. This was an increase of {1}% over last month. What were last month sales?",
                        (int)sales),
                    sales, increase);
                ans       = (int)previous;
                svg_image = "shop.svg";
                break;

            case GameType.Water:
                double decrease, percentage;

                do
                {
                    decrease   = (1 + random.Next(70));
                    percentage = decrease / (100 - decrease) * 100;
                } while (percentage != Math.Truncate(percentage));

                question = String.Format(
                    Translations.GetString("The amount of water in a bucket decreases by {0}%. By what percentage must the amount of water increase to reach its original value?"),
                    decrease);

                answer    = Translations.GetString("The objective is to obtain the same total amount.");
                ans       = (int)percentage;
                svg_image = "bucket.svg";
                break;

            default:
                throw new Exception("Unexpected value");
            }

            Answer.Correct         = (ans).ToString();
            Answer.CheckExpression = "[0-9]+";
        }
Beispiel #6
0
        protected override void Initialize()
        {
            int    ans;
            double speed_a, speed_b, rslt;

            gametype = (GameType)random.Next((int)GameType.Total);

            switch (gametype)
            {
            case GameType.Overtake:
            {
                double hours;

                do
                {
                    speed_a = 20 + (5 * random.Next(5));
                    speed_b = 50 + (5 * random.Next(5));
                    hours   = 2 * (1 + random.Next(3));
                    rslt    = speed_a * hours / (speed_b - speed_a);
                }  while (rslt != Math.Truncate(rslt));

                question = String.Format(
                    // Translators:
                    //  - mph (miles per hour). You must localize this using the right unit of speed for your locale
                    // - The translated string should not use more characters than the original sentence
                    Translations.GetPluralString("A train leaves the station traveling at {0} mph. {1} hour later a second train leaves the station traveling in the same direction at {2} mph. How many hours does it take the second train, since it starts moving, to overtake the first train?",
                                                 "A train leaves the station traveling at {0} mph. {1} hours later a second train leaves the station traveling in the same direction at {2} mph. How many hours does it take the second train, since it starts moving, to overtake the first train?", (int)hours),
                    speed_a, hours, speed_b);

                answer = Translations.GetString("You can calculate the answer by multiplying the speed of the first train by the time and dividing it by the difference of speeds.");
                break;
            }

            case GameType.Meet:
            {
                double distance, hours;

                speed_a  = 20 + (5 * random.Next(5));
                speed_b  = 50 + (5 * random.Next(5));
                hours    = 2 + random.Next(5);
                distance = hours * (speed_b + speed_a);
                rslt     = hours;

                question = String.Format(
                    // Translators:
                    //  - mph (miles per hour) and miles must be localized this using the right unit of speed for your locale
                    Translations.GetPluralString("Two trains separated by {0} mile are heading towards each other on straight parallel tracks. One travels at {1} mph and the other at {2} mph. In how many hours will they meet?",
                                                 "Two trains separated by {0} miles are heading towards each other on straight parallel tracks. One travels at {1} mph and the other at {2} mph. In how many hours will they meet?",
                                                 (int)distance),
                    distance, speed_a, speed_b);

                answer = Translations.GetString("You can calculate the answer by dividing the distance by the sum of both speeds.");
                break;
            }

            case GameType.Apart:
            {
                double distance;

                speed_a  = 10 + (2 * random.Next(5));
                speed_b  = 20 + (2 * random.Next(5));
                distance = (speed_a + speed_b) * (2 + random.Next(5));

                // Time in hours
                rslt = distance / (speed_a + speed_b);

                question = String.Format(
                    // Translators:
                    //  - mph (miles per hour) and miles must be localized this using the right unit of speed for your locale
                    Translations.GetPluralString("Two trains on straight parallel tracks leave from the same point and time traveling in opposite directions at {0} and {1} mph respectively. In how many hours will they be {2} mile apart?",
                                                 "Two trains on straight parallel tracks leave from the same point and time traveling in opposite directions at {0} and {1} mph respectively. In how many hours will they be {2} miles apart?",
                                                 (int)distance),
                    speed_a, speed_b, distance);

                answer = Translations.GetString("You can calculate the answer by dividing the distance by the sum of both speeds.");
                break;
            }

            default:
                throw new Exception("Unexpected value");
            }

            ans            = (int)rslt;
            Answer.Correct = (ans).ToString();
        }